| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 | BemsWebApplication.ContractManagement = function (params, viewInfo) {    'use strict';    var partnerTypeDataSource = BemsWebApplication.db.createDataSource('CmPartnerType', false, true, true),         partnerDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, true, true),        contractClassDataSource = BemsWebApplication.db.createDataSource('FmsContractClass', true, true, true),        contractMethodDataSource = BemsWebApplication.db.createDataSource('FmsContractMethod', true, true, true),        contractTypeDataSource = BemsWebApplication.db.createDataSource('FmsContractType', true, true, true),        paymentTypeDataSource = BemsWebApplication.db.createDataSource('FmsPaymentType', true, true, true);    var partnerTypes = ko.observableArray(),        contractClasses = ko.observableArray(),        contractMethods = ko.observableArray(),        contractTypes = ko.observableArray(),        paymentTypes = ko.observableArray(),        allPartner = ko.observableArray(),        filteredPartner = ko.observableArray();    var partnerTypesForSearch = ko.observableArray(),        contractClassesForSearch = ko.observableArray(),        contractMethodsForSearch = ko.observableArray(),        contractTypesForSearch = ko.observableArray(),        paymentTypesForSearch = ko.observableArray();    var ConstractInfo = ko.observableArray();    var FmsConstractDataSource = BemsWebApplication.db.createDataSource('FmsContract');    var RowName;    var deferredForSearch = new $.Deferred();    var dataSourceOptions = {        select: [            'SiteId',            'ContractId',            'Name',            'PartnerTypeId',            'PartnerId',            'ContractDate',            'StartDate',            'EndDate',            'OwnerShipName',            'OwnerShipPhoneNo',            'CommitmentMan',            'Comment',            'ContractClassId',            'ContractTypeId',            'ContractMethodId',            'PaymentTypeId',            'CmPartner/Name',            'CmPartnerType/Name',            'FmsContractClass/Name',            'FmsContractType/Name',            'FmsContractMethod/Name',            'FmsPaymentType/Name'        ],        expand: [            'CmPartner', 'CmPartnerType', 'FmsContractClass', 'FmsContractType', 'FmsContractMethod', 'FmsPaymentType'        ],        extendOptions: {            forceOriginalField: true        },        filter: [            ['SiteId', '=', BWA.UserInfo.SiteId()],        ]    };    var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsContract', {        dataSourceOptions: dataSourceOptions,        columns: [            { dataField: 'ContractId', caption: $G('number'), width: '10%', alignment: 'center', allowFiltering: false, sortOrder: 'desc' },            { dataField: 'Name', caption: '계약명', width: '45%', alignment: 'center' },            { dataField: 'CmPartnerType/Name', caption: '업체유형', width: '35%', alignment: 'center' },            {                dataField: 'StartDate', caption: '시작일', width: '15%', alignment: 'center', dataType: 'string',                customizeText: function (cellInfo) {                    if (cellInfo.value != null) {                        if (cellInfo.value.getMonth() >= 9) {                            if (cellInfo.value.getDate() >= 10) {                                return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();                            }                            else {                                return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();                            }                        }                        else {                            if (cellInfo.value.getDate() >= 10) {                                return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();                            }                            else {                                return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();                            }                        }                    }                }            },            {                dataField: 'EndDate', caption: '종료일', width: '15%', alignment: 'center', dataType: 'string',                customizeText: function (cellInfo) {                    if (cellInfo.value != null) {                        if (cellInfo.value.getMonth() >= 9) {                            if (cellInfo.value.getDate() >= 10) {                                return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();                            }                            else {                                return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();                            }                        }                        else {                            if (cellInfo.value.getDate() >= 10) {                                return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();                            }                            else {                                return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();                            }                        }                    }                }            },            { dataField: 'CmPartner/Name', caption: '업체명', width: '25%', alignment: 'center' },            { dataField: 'OwnerShipName', caption: '담당자', width: '20%', alignment: 'center' },            { dataField: 'OwnerShipPhoneNo', caption: '전화번호', width: '25%', alignment: 'center' },        ],        paging: {            pageSize: 18,            enabled: true        },        pager: {},        "export": {            enabled: true,            fileName: '계약 목록',        },        onExporting: function (e) {            e.component.columnOption("ContractId", "visible", false);        },        onExported: function (e) {            e.component.columnOption("ContractId", "visible", true);        },        searchViewItems: [            { id: 'Name' },            { id: 'StartDate', type: 'dateRange', isOnlyDate: true },            { id: 'EndDate', type: 'dateRange', isOnlyDate: true },            { id: 'CmPartner/Name' },            { id: 'OwnerShipName' },            { id: 'PartnerTypeId', ignoreValue: 0, defaultValue: 0, dataSource: partnerTypesForSearch },            { id: 'ContractClassId', ignoreValue: 0, defaultValue: 0, dataSource: contractClassesForSearch },            { id: 'ContractMethodId', ignoreValue: 0, defaultValue: 0, dataSource: contractMethodsForSearch },            { id: 'ContractTypeId', ignoreValue: 0, defaultValue: 0, dataSource: contractTypesForSearch },            { id: 'PaymentTypeId', ignoreValue: 0, defaultValue: 0, dataSource: paymentTypesForSearch },        ],        handleViewShowing: function (dataModel) {            $.when(                partnerTypeDataSource.load(),                contractClassDataSource.load(),                contractMethodDataSource.load(),                contractTypeDataSource.load(),                paymentTypeDataSource.load(),                partnerDataSource.load()            ).done(function (partnerTypeDataResult, contractClassDataResult, contractMethodDataResult, contractTypeDataResult, paymentTypeDataResult, partnerDataResult) {                partnerTypes(partnerTypeDataResult[0]);                contractClasses(contractClassDataResult[0]);                contractMethods(contractMethodDataResult[0]);                contractTypes(contractTypeDataResult[0]);                paymentTypes(paymentTypeDataResult[0]);                allPartner(partnerDataResult[0]);                partnerTypesForSearch($SearchView.createArrayOfSelectBox('PartnerTypeId', partnerTypeDataResult[0]));                contractClassesForSearch($SearchView.createArrayOfSelectBox('ContractClassId', contractClassDataResult[0]));                contractMethodsForSearch($SearchView.createArrayOfSelectBox('ContractMethodId', contractMethodDataResult[0]));                contractTypesForSearch($SearchView.createArrayOfSelectBox('ContractTypeId', contractTypeDataResult[0]));                paymentTypesForSearch($SearchView.createArrayOfSelectBox('PaymentTypeId', paymentTypeDataResult[0]));                deferredForSearch.resolve();            });        },        handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {                        var data = clickRow.data;            RowName = data.Name;            popupVisible(true);        },        // 이름 중복 방지        handlePopupShowing: function () {            FmsConstractDataSource.filter([                ["SiteId", "=", BWA.UserInfo.SiteId()]            ]);            FmsConstractDataSource.load().done(function (result) {                ConstractInfo(result);            });        },        beforeInsertingDataViewModel: function (dataModel, dbModelId) {            var dfd = $.Deferred();            var isDuplicated = false;            if (dataModel.StartDate() > dataModel.EndDate())                dfd.resolve(false, '시작일은 종료일 이전으로 선택해야 합니다.', 'error');            for (var i = 0; i < ConstractInfo().length; i++) {                if (dataModel.Name() == ConstractInfo()[i].Name()) {                    isDuplicated = true;                    break;                }            }            if (!BWA.DataUtil.isValidInputValue(dataModel.Name()))                return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');            else {                if (isDuplicated)                    return dfd.resolve(false, '이미 동일 정보가 존재합니다.');                else                    return dfd.resolve(true);            }        },        beforeUpdateDataViewModel: function () {            if (viewModel.dataModel.StartDate() > viewModel.dataModel.EndDate()) {                utils.toast.show('시작일은 종료일 이전으로 선택해야 합니다.', 'error');                return 0;            }                        var isDuplicated = false;            for (var i = 0; i < ConstractInfo().length; i++) {                if (viewModel.dataModel.Name() == ConstractInfo()[i].Name() && RowName() != ConstractInfo()[i].Name()) {                    isDuplicated = true;                    break;                }            }            if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {                utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');                return 0;            }            else {                if (isDuplicated) {                    utils.toast.show('이미 동일 정보가 존재합니다.', 'error');                    return 0;                }                else                    return 2;            }        },    });    function processValueChange(e) {        filteredPartner([]);        _.each(allPartner(), function (partner) {            if (e.value === partner.PartnerTypeId()) {                filteredPartner.push(partner);            }        });        if (!_.isEmpty(filteredPartner())) {            viewModel.dataModel.PartnerId(filteredPartner()[0].PartnerId());        }    }    viewModel.processValueChange = processValueChange;    viewModel.partnerTypes = partnerTypes;    viewModel.contractClasses = contractClasses;    viewModel.contractMethods = contractMethods;    viewModel.contractTypes = contractTypes;    viewModel.paymentTypes = paymentTypes;    viewModel.allPartner = allPartner;    viewModel.filteredPartner = filteredPartner;    return viewModel;};
 |