123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569 |
-
- BemsWebApplication.BudgetPlan2 = function (params, viewInfo) {
- "use strict";
- var eq = BWA.DataUtil.constructEqualFilter,
- and = BWA.DataUtil.andFilter;
- var initialized = false;
- var isNewBudget = ko.observable(false);
- var currentYear = (new Date()).getFullYear();
- 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,
- store: BemsWebApplication.odata.FmsBudgetDetail,
- select: ['SiteId', 'Year', 'BudgetSeq', 'BudgetClassId',
- 'RootBudgetClassId', 'ParentBudgetClassId',
- 'RootBudgetName', 'ParentBudgetName',
- 'Depth', 'Name', 'Abbreviation', 'IsUse', 'YearlyBudget', 'MonthlyBudget'], //, 'MonthlyExecution'
- }
- });
- // }, 'FmsBudgetDetail');
- modifiableBudgetPlanDataGridOptions = utils.datagrid.defaultOptions({
- pager: {
- showPageSizeSelector: false,
- allowedPageSizes: []
- },
- //groupPanel: {
- // visible: true
- //},
- dataSource: budgetsInView,
- columns: [
- // { dataField: 'BudgetSeq', caption: 'Seq', width: '15%', alignment: 'left'}, , //sortOrder: 'asc'
- //{ dataField: 'BudgetClassId', caption: 'BudgetClassId', width: '10%', alignment: 'center' },
- // { dataField: 'RootBudgetClassId', caption: 'RootBudgetClassId', width: '10%', alignment: 'center' },
- { dataField: 'RootBudgetName', caption: '대분류', alignment: 'left', groupIndex: 0 },
- { dataField: 'ParentBudgetName', caption: '중분류', alignment: 'left', groupIndex: 1 },
-
- // { dataField: 'ParentBudgetClassId', caption: 'ParentBudgetClassId', width: '10%', alignment: 'center'},
-
- { dataField: 'Name', caption: '명칭', alignment: 'left' },
- {
- dataField: 'YearlyBudget',
- caption: '연간예산', alignment: 'center'
- , customizeText: function (cellInfo) {
- return 0;
- }
- , cellTemplate: utils.datagrid.getNumberBoxDataGridTemplateFunc({
- min: 0,
- max: Number.MAX_SAFE_INTEGER,
- dataField: 'YearlyBudget'
- , convertValueWhenValueChanged: function (data, value) {
- var monthlyValue = value / 12;
- data.MonthlyBudget(Number(monthlyValue.toFixed(1)));
- reCalculateSummaryValue();
- return Math.max(0, value);
- }
- })
- },
- {
- 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);
- }
- })
- },
- ],
- sortByGroupSummaryInfo: [{
- summaryItem: 'count'
- }],
- summary: {
- groupItems: [
- {
- column: 'YearlyBudget',
- summaryType: 'sum',
- valueFormat: "currency",
- showInGroupFooter: false,
- alignByColumn: true
- },
- {
- column: 'MonthlyBudget',
- summaryType: 'sum',
- valueFormat: "currency",
- showInGroupFooter: false,
- alignByColumn: true
- }
- ]
- },
- cellClick: function (e) {
- if (e.rowType == 'data' && e.data.Depth() === 2) {
- if (e.column.dataField === 'YearlyBudget' || e.column.dataField === 'MonthlyBudget') {
- utils.datagrid.cellClickEventForDataGridTemplate(e, e.column.dataField);
- }
- }
- },
- rowPrepared: function (rowElement, rowInfo) {
- if (rowInfo.rowType == 'data') {
- var data = rowInfo.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) {
- if (cellInfo.rowType == 'data') {
- switch (cellInfo.column.dataField) {
- case 'Name':
- //if (cellInfo.data.Depth() === 1) {
- // cellElement.css('padding-left', '30px');
- //}
- //else
- if (cellInfo.data.Depth() === 2) {
- cellElement.css('padding-left', '40px');
- }
- break;
- }
- }
- },
- contentReadyAction: function (e) {
- budgetGridView = e.component;
- },
- });
- var viewModel,
- popup = null,
- virtualFacilityPopup = null,
- selectedTreeData = ko.observable(null),
- selectedTreeItem = ko.observable(null);
- var commandButtonOptions = [{
- icon: 'add',
- id: 'create1',
- title: '신규',
- //disabled: disabledButtons[BID_INSERT_VIRTUAL_FACILITY],
- action: newBudget
- },
- {
- icon: 'add',
- id: 'create3',
- title: '불러오기',
- //disabled: disabledButtons[BID_GENERATE_POINT],
- //action: generatePoints
- action: getBudgetYear
- },
- {
- icon: 'edit',
- id: 'create2',
- title: '저장',
- //disabled: disabledButtons[BID_EDIT_VIRTUAL_FACILITY],
- action: saveBudget
- }, {
- id: 'create4',
- title: '초기화',
- //disabled: disabledButtons[BID_GENERATE_POINT],
- //action: generatePoints
- action: resetBudget
- },
- {
- icon: 'remove',
- id: 'delete',
- title: '삭제',
- //disabled: disabledButtons[BID_DELETE_POINT],
- //action: handleRemoveSelectedPoints
- action: deleteBudget
- }];
- 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',
- ['Depth', '=', 0]
- ];
- }
- else if (depth === 2) {
- // FirstCodeClass 에 해당하는 모든 항목
- filter = [
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- ['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();
- 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.BudgetPlan2.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('Depth', 2),
- ]);
- else
- existingBudgetCodeDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- eq('Year', selectedBudgets.Year()),
- and,
- eq('Depth', 2),
- ]);
- $.when(existingBudgetCodeDataSource.load()).done(function (budgetCodeResult) {
- budgetsInView(budgetCodeResult);
- });
- isNewBudget(false);
- if (selectedBudgets == null)
- currentYear = now.getFullYear();
- else
- currentYear = selectedBudgets.Year();
- selectedBudgetYearName(currentYear + ' 년도 대상 항목');
- }
- });
- function reCalculateSummaryValue() {
- _.each(budgetsInView(), function (x) {
- if (x.Depth() === 0) {
- var yearlySum = 0;
- var monthlySum = 0;
- _.each(budgetsInView(), function (y) {
- if (y.Depth() === 2 && y.BudgetSeq().indexOf(x.BudgetSeq()) == 0) {
- yearlySum += Number(y.YearlyBudget());
- monthlySum += Number(y.MonthlyBudget());
- }
- });
- x.YearlyBudget(yearlySum);
- x.MonthlyBudget(monthlySum);
- }
- 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.YearlyBudget());
- monthlySum += Number(y.MonthlyBudget());
- }
- });
- x.YearlyBudget(yearlySum);
- x.MonthlyBudget(monthlySum);
- }
- });
- budgetGridView.refresh();
- }
- function newBudget() {
- isNewBudget(true);
- newBudgetCodeDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- eq('Depth', 2),
- ]);
- $.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('FmsBudgetDetail/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 postData;
- var parameters = {
- SiteId: siteId,
- Year: year
- };
- postData = _.map(array, function (f) {
- return {
- SiteId: siteId,
- Year: year,
- BudgetClassId: f.BudgetClassId(),
- BudgetSeq: f.BudgetSeq(),
- RootBudgetClassId: f.RootBudgetClassId(),
- ParentBudgetClassId: f.ParentBudgetClassId(),
- Depth: f.Depth(),
- Name: f.Name(),
- Abbreviation: f.Abbreviation(),
- IsUse: f.IsUse(),
- YearlyBudget: f.YearlyBudget(),
- MonthlyBudget: f.MonthlyBudget(),
- //MonthlyExecution: 0,
- //YearlyExecution: 0,
- };
- });
- if (isNewBudget()) {
- BWA.api.post('FmsBudgetDetail/Save', postData, parameters).done(function () {
- utils.toast.show($G('successDatabaseProcessMsg'));
- isNewBudget(false);
- });
- }
- else {
- BWA.api.post('FmsBudgetDetail/Update', 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;
- };
- }
- return viewModel;
- };
|