| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 | 
							- 
 
- BemsWebApplication.BudgetExecute = function (params, viewInfo) {
 
-     "use strict";
 
-     
 
-     var initialized = false;
 
-     var eq = BWA.DataUtil.constructEqualFilter,
 
-         and = BWA.DataUtil.andFilter;
 
-     var isNewBudget = ko.observable(false);
 
-     var currentYear = (new Date()).getFullYear();
 
-     var currentMonth = (new Date()).getMonth();
 
-     var modifiableBudgetPlanDataGridOptions = undefined;
 
-     var budgetsInView = ko.observableArray(),
 
-         budgets = ko.observableArray()
 
-     ;
 
-     var selectedBudgetYearName = ko.observable();
 
-     var budgetGridView = undefined;
 
-     var disabledButtons = [ko.observable(), ko.observable(), ko.observable(), ko.observable()];
 
-     var budgetDataSource = BemsWebApplication.db.createDataSource('FmsBudget', true, false, true);
 
-     var budgetCodeDataSourceForTree = BWA.DataUtil.createDataSource({
 
-         dataSourceOptions: {
 
-             paginate: false,
 
-             store: BemsWebApplication.odata.FmsBudgetCodeClass,
 
-             select: ['SiteId', 'BudgetSeq', 'BudgetClassId',
 
-                 'RootBudgetClassId', 'ParentBudgetClassId',
 
-                 'RootBudgetName', 'ParentBudgetName',
 
-                 'Depth', 'Name', 'Abbreviation', 'IsUse', 'YearlyBudget', 'MonthlyBudget'],
 
-         }
 
-     });
 
-     var newBudgetCodeDataSource = BWA.DataUtil.createDataSource({
 
-         dataSourceOptions: {
 
-             paginate: false,
 
-             store: BemsWebApplication.odata.FmsBudgetCodeClass,
 
-             select: [
 
-                 'SiteId',
 
-                 'BudgetSeq',
 
-                 'BudgetClassId',
 
-                 'RootBudgetClassId',
 
-                 'ParentBudgetClassId',
 
-                 'RootBudgetName',
 
-                 'ParentBudgetName',
 
-                 'Depth',
 
-                 'Name', 'Abbreviation', 'IsUse', 'YearlyBudget', 'MonthlyBudget'],
 
-         }
 
-     });
 
-     //var existingBudgetCodeDataSource = BWA.DataUtil.createDataSource({
 
-     //    dataSourceOptions: {
 
-     //        paginate: false,
 
-     //        select: ['SiteId', 'Year', 'FmsBudgetDetail/BudgetSeq', 'BudgetClassId', 'ParentBudgetClassId', 'FmsBudgetDetail/Depth',
 
-     //            'FmsBudgetDetail/Name', 'FmsBudgetDetail/Abbreviation', 'FmsBudgetDetail/IsUse',
 
-     //            'YearlyBudget', 'MonthlyBudget', 'MonthlyExecution', 'Month', 'YearlyExecution'
 
-     //        ],
 
-     //        //, 'MonthlyExecution' , 'YearlyExecution'
 
-     //        expand: ['FmsBudgetDetail'],
 
-     //        extendOptions: {
 
-     //            forceOriginalField: true
 
-     //        },
 
-     //    }
 
-     //}, 'FmsBudgetDetailExecution');
 
-     var existingBudgetCodeDataSource = BWA.DataUtil.createDataSource({
 
-         dataSourceOptions: {
 
-             paginate: false,
 
-             store: BemsWebApplication.odata.FmsBudgetDetailExecution2,
 
-             select: [
 
-                 'SiteId',
 
-                 'Year', 'BudgetClassId', 'BudgetSeq',
 
-                 'RootBudgetClassId', 'ParentBudgetClassId',
 
-                 'RootBudgetName', 'ParentBudgetName', 'Month',
 
-                 'Depth', 'Name', 'YearlyBudget', 'MonthlyBudget',
 
-                 'YearlyExecution', 'MonthlyExecution'], 
 
-         }
 
-     });
 
-     modifiableBudgetPlanDataGridOptions = utils.datagrid.defaultOptions({
 
-         pager: {
 
-             showPageSizeSelector: false,
 
-             allowedPageSizes: []
 
-         },
 
-         //groupPanel: {
 
-         //    visible: true
 
-         //},
 
-         dataSource: budgetsInView,
 
-         columns: [
 
-                  
 
-                  { dataField: 'RootBudgetName', caption: '대분류', alignment: 'left', groupIndex: 0 },
 
-                  { dataField: 'ParentBudgetName', caption: '중분류', alignment: 'left', groupIndex: 1 },
 
-                  { dataField: 'Name', caption: '명칭', alignment: 'left' },
 
-                  {
 
-                      dataField: 'MonthlyBudget', caption: '월간예산', alignment: 'center'
 
-                   , cellTemplate: utils.datagrid.getNumberBoxDataGridTemplateFunc({
 
-                       min: 0,
 
-                       max: Number.MAX_SAFE_INTEGER,
 
-                       dataField: 'MonthlyBudget'
 
-                         , convertValueWhenValueChanged: function (data, value) {
 
-                             var yearlyValue = value * 12;
 
-                             data.YearlyBudget(Number(yearlyValue.toFixed(1)));
 
-                             reCalculateSummaryValue();
 
-                             return Math.max(0, value);
 
-                         }
 
-                     })
 
-                  },
 
-                  {
 
-                      dataField: 'MonthlyExecution', caption: '월간실적', alignment: 'center'
 
-                       , cellTemplate: utils.datagrid.getNumberBoxDataGridTemplateFunc({
 
-                           min: 0,
 
-                           max: Number.MAX_SAFE_INTEGER,
 
-                           dataField: 'MonthlyExecution'
 
-                           , convertValueWhenValueChanged: function (data, value) {
 
-                               var yearlyValue = value * 12;
 
-                               data.YearlyExecution(Number(yearlyValue.toFixed(1)));
 
-                               reCalculateSummaryValue();
 
-                               return Math.max(0, value);
 
-                           }
 
-                       })
 
-                  },
 
-         ],
 
-         sortByGroupSummaryInfo: [{
 
-             summaryItem: 'count'
 
-         }],
 
-         summary: {
 
-             groupItems: [
 
-             {
 
-                 column: 'MonthlyBudget',
 
-                 summaryType: 'sum',
 
-                 valueFormat: "currency",
 
-                 showInGroupFooter: false,
 
-                 alignByColumn: true
 
-             },
 
-             {
 
-                 column: 'MonthlyExecution',
 
-                 summaryType: 'sum',
 
-                 valueFormat: "currency",
 
-                 showInGroupFooter: false,
 
-                 alignByColumn: true
 
-             }
 
-             ]
 
-         },
 
-         cellClick: function (e) {
 
-             if (e.rowType == 'data' && e.data['Depth']() === 2) {
 
-                 if (e.column.dataField === 'MonthlyExecution' || e.column.dataField === 'MonthlyBudget') {
 
-                     utils.datagrid.cellClickEventForDataGridTemplate(e, e.column.dataField);
 
-                 }
 
-             }
 
-         },
 
-         rowPrepared: function (rowElement, rowInfo) {
 
-             var data = rowInfo.data;
 
-             if (rowInfo.rowType == 'data') {
 
-             if (data['Depth']() === 0) {
 
-                 var color = 'rgba(100,100,100,0.2)';
 
-                 rowElement.css('background-color', color);
 
-             }
 
-             else if (data['Depth']() === 1) {
 
-                 var color = 'rgba(150,150,150,0.2)';
 
-                 rowElement.css('background-color', color);
 
-             }
 
-             else if (data['Depth']() === 2) {
 
-             }
 
-             }
 
-             
 
-         },
 
-         cellPrepared: function (cellElement, cellInfo) {
 
-             switch (cellInfo.column.dataField) {
 
-                 case 'Name':
 
-                     if (cellInfo.rowType == 'data' && cellInfo.data['Depth']() === 1) {
 
-                         cellElement.css('padding-left', '30px');
 
-                     }
 
-                     else if (cellInfo.rowType == 'data' && cellInfo.data['Depth']() === 2) {
 
-                         cellElement.css('padding-left', '60px');
 
-                     }
 
-                     break;
 
-             }
 
-         },
 
-         contentReadyAction: function (e) {
 
-             budgetGridView = e.component;
 
-         },
 
-     });
 
-     var viewModel,
 
-         popup = null,
 
-         virtualFacilityPopup = null,
 
-         //popupVisible = ko.observable(false),
 
-         //rootTreeData = ko.observable(null),
 
-         selectedTreeData = ko.observable(null),
 
-         selectedTreeItem = ko.observable(null);
 
-     var commandButtonOptions = [
 
-     {
 
-         icon: 'add',
 
-         id: 'create3',
 
-         title: '불러오기',
 
-         action: getBudgetYear
 
-     },
 
-     {
 
-         icon: 'edit',
 
-         id: 'create2',
 
-         title: '저장',
 
-         action: saveBudget
 
-     }, {
 
-         id: 'create4',
 
-         title: '초기화',
 
-         action: resetBudget
 
-     },
 
-     ];
 
-     function handleClickTreeItem(element, data) {
 
-         selectedTreeItem(data);
 
-         var filter;
 
-         var depth = data.depth;
 
-         var parentData = data.parentData;
 
-         data = data.data;
 
-         selectedTreeData(data);
 
-         if (depth == 1) {
 
-             filter = [
 
-               ['SiteId', '=', BWA.UserInfo.SiteId()],
 
-               'and',
 
-               ['FmsBudgetDetail/Depth', '=', 0]
 
-             ];
 
-         }
 
-         else if (depth === 2) {
 
-             // FirstCodeClass 에 해당하는 모든 항목
 
-             filter = [
 
-                 ['SiteId', '=', BWA.UserInfo.SiteId()],
 
-                 'and',
 
-                 ['FmsBudgetDetail/BudgetSeq', 'startswith', data.BudgetSeq()]
 
-             ];
 
-         }
 
-         else if (depth === 3) {
 
-             // SecondCodeClass 에 해당하는 모든 항목
 
-             filter = [
 
-                 ['SiteId', '=', BWA.UserInfo.SiteId()],
 
-                 'and',
 
-                 [
 
-                     ['BudgetClassId', '=', data.ParentBudgetClassId()],
 
-                     'or',
 
-                     ['BudgetClassId', '=', data.BudgetClassId()],
 
-                     'or',
 
-                     ['ParentBudgetClassId', '=', data.BudgetClassId()]
 
-                 ]
 
-             ];
 
-         }
 
-         budgetGridView.filter(filter);
 
-     }
 
-     function handleViewShown() {
 
-         //setTreeview();
 
-         
 
-         //currentYear = selectedBudgets.Year();
 
-         //currentMonth = selectedBudgets.Month();
 
-         //var a = [BWA.UserInfo.SiteId(), 2015, 12];
 
-         if (initialized == false)
 
-         {
 
-             selectedBudgetYearName('대상 항목');
 
-             viewModel.popup.onSelectedBudgets(null);
 
-         }
 
-         initialized = true;
 
-     }
 
-     viewModel = BWA.CommonView.create(params, viewInfo, null, null, handleViewShown);
 
-     viewModel.modifiableBudgetPlanDataGridOptions = modifiableBudgetPlanDataGridOptions;
 
-     viewModel.commandButtonOptions = commandButtonOptions;
 
-     viewModel.budgets = budgets;
 
-     viewModel.selectedBudgetYearName = selectedBudgetYearName;
 
-     popup = viewModel.popup = BWA.Popup.BudgetExecute.create(viewModel, {
 
-         onSelectedBudgets: function (selectedBudgets) {
 
-             var now = new Date();
 
-             if (selectedBudgets == null)
 
-             existingBudgetCodeDataSource.filter([
 
-               eq('SiteId', BWA.UserInfo.SiteId()),
 
-               and,
 
-               eq('Year', now.getFullYear() ),
 
-               and,
 
-               eq('Month', now.getMonth() + 1),
 
-             ]);
 
-             else
 
-                 existingBudgetCodeDataSource.filter([
 
-                   eq('SiteId', BWA.UserInfo.SiteId()),
 
-                   and,
 
-                   eq('Year', selectedBudgets.Year()),
 
-                   and,
 
-                   eq('Month', selectedBudgets.Month()),
 
-                 ]);
 
-             $.when(existingBudgetCodeDataSource.load()).done(function (budgetCodeResult) {
 
-                 budgetsInView(budgetCodeResult);
 
-             });
 
-             isNewBudget(false);
 
-             if (selectedBudgets == null) {
 
-                 currentYear = now.getFullYear();
 
-                 currentMonth = now.getMonth() + 1;
 
-             }
 
-             else{
 
-                 currentYear = selectedBudgets.Year();
 
-                 currentMonth = selectedBudgets.Month();
 
-             }
 
-             selectedBudgetYearName(currentYear + ' 년도 ' + currentMonth + ' 월 대상 항목');
 
-         }
 
-     });
 
-     function reCalculateSummaryValue() {
 
-         _.each(budgetsInView(), function (x) {
 
-             if (x['Depth']() === 0) {
 
-                 var yearlySum = 0;
 
-                 var monthlySum = 0;
 
-                 var yearlySumBudget = 0;
 
-                 var monthlySumBudget = 0;
 
-                 _.each(budgetsInView(), function (y) {
 
-                     if (y['Depth']() === 2 && y['BudgetSeq']().indexOf(x['BudgetSeq']()) == 0) {
 
-                         yearlySum += Number(y.YearlyExecution());
 
-                         monthlySum += Number(y.MonthlyExecution());
 
-                         yearlySumBudget += Number(y.YearlyBudget());
 
-                         monthlySumBudget += Number(y.MonthlyBudget());
 
-                     }
 
-                 });
 
-                 x.YearlyExecution(yearlySum);
 
-                 x.MonthlyExecution(monthlySum);
 
-                 x.YearlyBudget(yearlySumBudget);
 
-                 x.MonthlyBudget(monthlySumBudget);
 
-             }
 
-             else if (x['Depth']() === 1) {
 
-                 var yearlySum = 0;
 
-                 var monthlySum = 0;
 
-                 _.each(budgetsInView(), function (y) {
 
-                     if (y['Depth']() === 2 && y['BudgetSeq']().indexOf(x['BudgetSeq']()) == 0) {
 
-                         yearlySum += Number(y.YearlyExecution());
 
-                         monthlySum += Number(y.MonthlyExecution());
 
-                         yearlySumBudget += Number(y.YearlyBudget());
 
-                         monthlySumBudget += Number(y.MonthlyBudget());
 
-                     }
 
-                 });
 
-                 x.YearlyExecution(yearlySum);
 
-                 x.MonthlyExecution(monthlySum);
 
-                 x.YearlyBudget(yearlySumBudget);
 
-                 x.MonthlyBudget(monthlySumBudget);
 
-             }
 
-         });
 
-         budgetGridView.refresh();
 
-     }
 
-     function newBudget() {
 
-         isNewBudget(true);
 
-         $.when(
 
-             newBudgetCodeDataSource.load(),
 
-             budgetDataSource.load()
 
-             ).done(function (budgetCodeResult, budgetResult) {
 
-                 budgetsInView(budgetCodeResult[0]);
 
-                 budgets(budgetResult[0]);
 
-                 // currentYear 설정 (최신년도 설정 으로...)
 
-                 if (_.isEmpty(budgets())) {
 
-                     currentYear = (new Date()).getFullYear();
 
-                 }
 
-                 else {
 
-                     var lastBudget = _.last(budgets());
 
-                     currentYear = lastBudget.Year() + 1;
 
-                 }
 
-                 selectedBudgetYearName(currentYear + ' 년도 대상 항목');
 
-             });
 
-     }
 
-     function deleteBudget() {
 
-         //DevExpress.ui.dialog.confirm($G('deleteConfirmMsg'), "삭제").then(function (result) {
 
-         //    if (result) {
 
-         //        var array = budgetsInView();
 
-         //        if (_.isEmpty(array)) {
 
-         //            utils.toast.show('저장할 예산편성이 없습니다.', 'error');
 
-         //            return;
 
-         //        }
 
-         //        var siteId = BWA.UserInfo.SiteId();
 
-         //        var year = currentYear;
 
-         //        var parameters = {
 
-         //            SiteId: siteId,
 
-         //            Year: year
 
-         //        };
 
-         //        BWA.api.post('FmsBudgetDetailExecution/Delete', null, parameters).done(function () {
 
-         //            utils.toast.show($G('successDatabaseDeleteMsg'));
 
-         //            resetBudget();
 
-         //        });
 
-         //    }
 
-         //});
 
-     }
 
-     function getBudgetYear() {
 
-         popup.show();
 
-     }
 
-     function saveBudget() {
 
-         var array = budgetsInView();
 
-         if (_.isEmpty(array)) {
 
-             utils.toast.show('저장할 예산편성이 없습니다.', 'error');
 
-             return;
 
-         }
 
-         var siteId = BWA.UserInfo.SiteId();
 
-         var year = currentYear;
 
-         var month = currentMonth;
 
-         var postData;
 
-         var parameters = {
 
-             SiteId: siteId,
 
-             Year: year,
 
-             Month: month
 
-         };
 
-         postData = _.map(array, function (f) {
 
-             return {
 
-                 SiteId: siteId,
 
-                 Year: year,
 
-                 BudgetClassId: f.BudgetClassId(),
 
-                 RootBudgetClassId: f.RootBudgetClassId(),
 
-                 ParentBudgetClassId: f.ParentBudgetClassId(),
 
-                 Month: month,
 
-                 YearlyBudget: f.YearlyBudget(),
 
-                 MonthlyBudget: f.MonthlyBudget(),
 
-                 YearlyExecution: f.YearlyExecution(),
 
-                 MonthlyExecution: f.MonthlyExecution(),
 
-             };
 
-         });
 
-         BWA.api.post('FmsBudgetDetailExecution/Save', postData, parameters).done(function () {
 
-             utils.toast.show($G('successDatabaseProcessMsg'));
 
-         });
 
-     }
 
-     function resetBudget() {
 
-         isNewBudget(false);
 
-         budgetsInView([]);
 
-         budgets([]);
 
-         budgetGridView.refresh();
 
-         selectedBudgetYearName('대상 항목');
 
-         //clearTreeview();
 
-     }
 
-     function clearTreeview() {
 
-         $('#facilityTreeView').cwTreeView({
 
-             width: '30%',
 
-             height: 'auto',
 
-             onClickTreeItem: handleClickTreeItem,
 
-             delegateDataSource: getDataSourceDelegateForTreeView(budgetCodeDataSourceForTree)
 
-         });
 
-     }
 
-     function setTreeview() {
 
-         $('#facilityTreeView').cwTreeView({
 
-             width: '30%',
 
-             height: 'auto',
 
-             onClickTreeItem: handleClickTreeItem,
 
-             delegateDataSource: getDataSourceDelegateForTreeView(budgetCodeDataSourceForTree)
 
-         });
 
-     }
 
-     function getDataSourceDelegateForTreeView(dataSource) {
 
-         return function (data, alterObj) {
 
-             var id = data.id;
 
-             var depth = data.depth;
 
-             var promise = null;
 
-             switch (depth) {
 
-                 case 0:
 
-                     var typeDeferred = new $.Deferred();
 
-                     promise = typeDeferred.promise();
 
-                     alterObj.IsFunction = false;
 
-                     typeDeferred.resolve([{
 
-                         Id: 0,
 
-                         Name: '관리항목'
 
-                     }]);
 
-                     //rootTreeData(data);
 
-                     break;
 
-                 case 1:
 
-                     dataSource.filter([
 
-                         eq('SiteId', BWA.UserInfo.SiteId()),
 
-                         'and',
 
-                         eq('Depth', 0)
 
-                     ]);
 
-                     promise = dataSource.load();
 
-                     break;
 
-                 case 2:
 
-                     dataSource.filter([
 
-                         eq('SiteId', BWA.UserInfo.SiteId()),
 
-                         'and',
 
-                         eq('ParentBudgetClassId', data.data.BudgetClassId()),
 
-                         'and',
 
-                         eq('Depth', 1)
 
-                     ]);
 
-                     promise = dataSource.load();
 
-                     break;
 
-             }
 
-             return promise;
 
-         };
 
-     }
 
-     //viewModel.popup.onSelectedBudgets(null);
 
-     return viewModel;
 
- };
 
 
  |