| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 | BemsWebApplication.MonthMoney = function(params, viewInfo) {    "use strict";    var initialized = false,        shouldReload = false,        dataSource;    var CODE = $Code,        FuelType = CODE.FuelType,        FacilityType = CODE.FacilityType,        FacilityCode = CODE.FacilityCode,        F = CODE.Formula,        TIT = CODE.TimeIntervalType;    var visiblePopup = ko.observable(false);    var factorToeDataSource = BemsWebApplication.db.createDataSource('BemsFactorToe'),        chartPieDay = BWA.Chart.Instance('chartPieDayMM', 'dxPieChart'),        chartBarDay = BWA.Chart.Instance('chartBarDayMM', 'dxChart'),        chartPieMonth = BWA.Chart.Instance('chartPieMonthMM', 'dxPieChart'),        chartBarMonth = BWA.Chart.Instance('chartBarMonthMM', 'dxChart');    var MonthMoneyGet = new BWA.Chart.PointHistory_MonthMoneyGet(BWA.UserInfo.SiteId());    var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForMonthOnly);    var factorToe = null;    var Toe = $Code.FuelType.WATER + 1;    var fuelTypesDataSource = BemsWebApplication.db.createDataSource('BemsFuelType'),        fuelTypesForSearch = ko.observableArray(),        timeTypesForSearch = ko.observableArray(),        timeTypeIdForSearch = ko.observable(0),        fuelTypeIdForSearch = ko.observable(),        deferredForSearch = new $.Deferred();    var dataArray = ko.observableArray(),        dataDayForPie = ko.observableArray(),        dataMonthForPie = ko.observableArray(),        dataDayForBar = ko.observableArray(),        dataMonthForBar = ko.observableArray()    ;    var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());    timeTypesForSearch($G.TimeTypes);    var m = moment();    /*dataDayForBar([        { DateTime: new Date(m.year(), m.month(), 1), PowerToe: 40, GasToe: 40, WaterToe: 40 },        { DateTime: new Date(m.year(), m.month(), 2), Value: 50, PowerToe: 40, GasToe: 40, WaterToe: 40 },        { DateTime: new Date(m.year(), m.month(), 3), Value: 60, PowerToe: 40, GasToe: 40, WaterToe: 40 },        { DateTime: new Date(m.year(), m.month(), 4), Value: 80, PowerToe: 40, GasToe: 40, WaterToe: 40 },        { DateTime: new Date(m.year(), m.month(), 5), Value: 100, PowerToe: 40, GasToe: 40, WaterToe: 40 },        { DateTime: new Date(m.year(), m.month(), 6), Value: 40, PowerToe: 40, GasToe: 40, WaterToe: 40 },        { DateTime: new Date(m.year(), m.month(), 7), Value: 120, PowerToe: 40, GasToe: 40, WaterToe: 40 },        { DateTime: new Date(m.year(), m.month(), 31), Value: 120, PowerToe: 40, GasToe: 40, WaterToe: 40 }    ]);    dataMonthForBar(dataDayForBar());    dataDayForPie([        { FuelTypeName: '전기', Value: 320 },        { FuelTypeName: '가스', Value: 350 },        { FuelTypeName: '수도', Value: 360 },    ]);    dataMonthForPie(dataDayForPie());    */    function handleMonthBarPointClick(clickedPoint) {        var month = clickedPoint.originalArgument;        //loadDailyEnergyUsage(month);        //console.log(month);    }    var searchViewOptions = {        searchViewItems: [            { id: 'TimeTypeId', defaultValue: 0, value: timeTypeIdForSearch, dataSource: timeTypesForSearch },            { id: 'FuelTypeId', ignoreValue: 0, defaultValue: 1, value: fuelTypeIdForSearch, dataSource: fuelTypesForSearch },            { id: 'DateForHour', type: 'dateRange', isOnlyDate: true },            { id: 'TimeForHour', type: 'dateRange', isOnlyDate: true },        ],        promiseDataInSearchView: deferredForSearch.promise()    };    function handleViewShown() {        if (initialized === false) {            var chartOption = BWA.ChartOptions.MonthMoney;            chartPieDay = chartPieDay(chartOption.getPieChartDayOptions());            chartBarDay = chartBarDay(chartOption.getBarChartDayOptions());            chartPieMonth = chartPieMonth(chartOption.getPieChartMonthOptions());            chartBarMonth = chartBarMonth(chartOption.getBarChartMonthOptions(handleMonthBarPointClick));            //$('#chartPieDay').dxPieChart(chartOption.getPieChartDayOptions(dataDayForPie));            //$('#chartBarDay').dxChart(chartOption.getBarChartDayOptions(dataDayForBar));            //$('#chartPieMonth').dxPieChart(chartOption.getPieChartMonthOptions(dataMonthForPie));            //$('#chartBarMonth').dxChart(chartOption.getBarChartMonthOptions(dataMonthForBar));            initialized = true;        }        factorToeDataSource.load().done(function(dbFactorToe) {            factorToe = BWA.Bems.refineFactorToeDataArray(dbFactorToe);            //loadMonthlyEnergyUsage();            //loadDailyEnergyUsage();            handleSearchInSearchView();        });    }    function handleSearchInSearchView() {        visiblePopup(true);        $("#large-indicator").dxLoadIndicator({            height: 60,            width: 60        });            //fuelTypeId = fuelTypeIdForSearch();        loadMonthlyEnergyUsage();        //loadDailyEnergyUsage();    }    function getChartDataFromDataSources(loadedDataSources, barDataArray, pieDataArray, timeFormat) {        var pieFields = [$G('electricity'), $G('water'), $G('gas'), ];        var toeFields = ['Elec', 'Water', 'Gas'];        //var pieFields = [$G('electricity'), $G('gas')];        //var toeFields = ['ElectricityToe', 'GasToe',];        _.each(loadedDataSources, function(array, i) {            var field = toeFields[i];            var sum = 0;            _.each(array[0], function(x) {                var data = {                    DateTime: moment(x.DateTime).format(timeFormat),                };                sum += data[field] = x.Value;                barDataArray.push(data);            });            pieDataArray.push({                FuelTypeName: pieFields[i],                Value: sum            });        });        //_.each(pieDataArray, function (x) {        //    if (x.Value == 0) x.Value = 1;        //});    }    var fuelTypes = [FuelType.ELECTRICITY, FuelType.GAS, FuelType.WATER];    function loadMonthlyEnergyUsage() {        visiblePopup(true);        $("#large-indicator").dxLoadIndicator({            height: 60,            width: 60        });        var date = timeBoxForSearch.getDate(),            timeType = timeBoxForSearch.type();        var promises = [];        var param = {            SiteId: BWA.UserInfo.SiteId(),            TimeIntervalType: timeType,            StartDate : date.startDate,            EndDate : date.endDate,        };        //promises.push(BWA.api.post('BemsMonitoringPointHistory/MonthMoney', null, param));        /*        _.each(fuelTypes, function(x) {            promises.push(energyUsageStatusGet.requestGetForUsgaeStatus(x, TIT.MONTH)                (moment().startOf('year'), moment()));        });*/        promises.push(MonthMoneyGet.apiGet(_.extend(param, {Type:10})));        promises.push(MonthMoneyGet.apiGet(_.extend(param, {Type: 11 })));        promises.push(MonthMoneyGet.apiGet(_.extend(param, {Type: 12 })));        $.when.apply(this, promises).done(function(e,w,g) {                        var Datas = [];            /*            _.each(e[0], function (x) {                Datas.push(e[0]);            });            _.each(w[0], function (x) {                Datas.push(x);            });            _.each(g[0], function (x) {                Datas.push(x);            });*/            Datas.push(e[0]);            Datas.push(w[0]);            Datas.push(g[0]);            var barDataArray = [];            var pieDataArray = [];            getChartDataFromDataSources(Datas, barDataArray, pieDataArray, 'M');            //var eData = data[0];            //var wData = data[1];            //var gData = data[2];            //console.log(barDataArray);            chartBarMonth().option('dataSource', barDataArray);            chartPieMonth().option('dataSource', pieDataArray);            visiblePopup(false);            $('#st4').text(new Date().getFullYear() + '년 에너지 비용 현황');            $('#st5').text(new Date().getFullYear() + '년 에너지 비용 비율');            $('#st6').text(new Date().getFullYear() + '년 에너지 비용');        }).fail(function (error) {            //alert(error);            visiblePopup(false);        });    }    function handleViewHidden() {        visiblePopup(false);        $SearchView.visibleObservable(false); // hcLee 2015 03 23        //hideOverlay();        //    var dataGrid = $('#gridContainer').dxDataGrid('instance');        //    dataGrid.clearSelection();    }    function handleViewShowing() {    }    function refreshList() {        //dataSource.pageIndex(0);        //dataSource.load();    }    var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView), {        refreshList: refreshList,        viewHidden: handleViewHidden, // hcLee 2015 03 23        viewShowing: handleViewShowing,    });    viewModel.timeBoxForSearch = timeBoxForSearch;    viewModel.popupOptions = {        width: 300,        height: 100,        contentTemplate: "info",        showTitle: false,        title: "메세지",        visible: visiblePopup,        dragEnabled: false,        shading: false,        closeOnOutsideClick: false    };    return viewModel;};
 |