6d59f13667d4c8c9fc9e356f3f5c31fba312bfe1.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. BemsWebApplication.ContractManagement = function (params, viewInfo) {
  2. 'use strict';
  3. var partnerTypeDataSource = BemsWebApplication.db.createDataSource('CmPartnerType', false, true, true),
  4. partnerDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, true, true),
  5. contractClassDataSource = BemsWebApplication.db.createDataSource('FmsContractClass', true, true, true),
  6. contractMethodDataSource = BemsWebApplication.db.createDataSource('FmsContractMethod', true, true, true),
  7. contractTypeDataSource = BemsWebApplication.db.createDataSource('FmsContractType', true, true, true),
  8. paymentTypeDataSource = BemsWebApplication.db.createDataSource('FmsPaymentType', true, true, true);
  9. var partnerTypes = ko.observableArray(),
  10. contractClasses = ko.observableArray(),
  11. contractMethods = ko.observableArray(),
  12. contractTypes = ko.observableArray(),
  13. paymentTypes = ko.observableArray(),
  14. allPartner = ko.observableArray(),
  15. filteredPartner = ko.observableArray();
  16. var partnerTypesForSearch = ko.observableArray(),
  17. contractClassesForSearch = ko.observableArray(),
  18. contractMethodsForSearch = ko.observableArray(),
  19. contractTypesForSearch = ko.observableArray(),
  20. paymentTypesForSearch = ko.observableArray();
  21. var ConstractInfo = ko.observableArray();
  22. var FmsConstractDataSource = BemsWebApplication.db.createDataSource('FmsContract');
  23. var RowName;
  24. var deferredForSearch = new $.Deferred();
  25. var dataSourceOptions = {
  26. select: [
  27. 'SiteId',
  28. 'ContractId',
  29. 'Name',
  30. 'PartnerTypeId',
  31. 'PartnerId',
  32. 'ContractDate',
  33. 'StartDate',
  34. 'EndDate',
  35. 'OwnerShipName',
  36. 'OwnerShipPhoneNo',
  37. 'CommitmentMan',
  38. 'Comment',
  39. 'ContractClassId',
  40. 'ContractTypeId',
  41. 'ContractMethodId',
  42. 'PaymentTypeId',
  43. 'CmPartner/Name',
  44. 'CmPartnerType/Name',
  45. 'FmsContractClass/Name',
  46. 'FmsContractType/Name',
  47. 'FmsContractMethod/Name',
  48. 'FmsPaymentType/Name'
  49. ],
  50. expand: [
  51. 'CmPartner', 'CmPartnerType', 'FmsContractClass', 'FmsContractType', 'FmsContractMethod', 'FmsPaymentType'
  52. ],
  53. extendOptions: {
  54. forceOriginalField: true
  55. },
  56. filter: [
  57. ['SiteId', '=', BWA.UserInfo.SiteId()],
  58. ]
  59. };
  60. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsContract', {
  61. dataSourceOptions: dataSourceOptions,
  62. columns: [
  63. { dataField: 'ContractId', caption: $G('number'), width: '10%', alignment: 'center', allowFiltering: false, sortOrder: 'desc' },
  64. { dataField: 'Name', caption: '계약명', width: '45%', alignment: 'center' },
  65. { dataField: 'CmPartnerType/Name', caption: '업체유형', width: '35%', alignment: 'center' },
  66. {
  67. dataField: 'StartDate', caption: '시작일', width: '15%', alignment: 'center', dataType: 'string',
  68. customizeText: function (cellInfo) {
  69. if (cellInfo.value != null) {
  70. if (cellInfo.value.getMonth() >= 9) {
  71. if (cellInfo.value.getDate() >= 10) {
  72. return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();
  73. }
  74. else {
  75. return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();
  76. }
  77. }
  78. else {
  79. if (cellInfo.value.getDate() >= 10) {
  80. return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();
  81. }
  82. else {
  83. return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();
  84. }
  85. }
  86. }
  87. }
  88. },
  89. {
  90. dataField: 'EndDate', caption: '종료일', width: '15%', alignment: 'center', dataType: 'string',
  91. customizeText: function (cellInfo) {
  92. if (cellInfo.value != null) {
  93. if (cellInfo.value.getMonth() >= 9) {
  94. if (cellInfo.value.getDate() >= 10) {
  95. return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();
  96. }
  97. else {
  98. return cellInfo.value.getFullYear() + "-" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();
  99. }
  100. }
  101. else {
  102. if (cellInfo.value.getDate() >= 10) {
  103. return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-" + cellInfo.value.getDate();
  104. }
  105. else {
  106. return cellInfo.value.getFullYear() + "-0" + (cellInfo.value.getMonth() + 1) + "-0" + cellInfo.value.getDate();
  107. }
  108. }
  109. }
  110. }
  111. },
  112. { dataField: 'CmPartner/Name', caption: '업체명', width: '25%', alignment: 'center' },
  113. { dataField: 'OwnerShipName', caption: '담당자', width: '20%', alignment: 'center' },
  114. { dataField: 'OwnerShipPhoneNo', caption: '전화번호', width: '25%', alignment: 'center' },
  115. ],
  116. paging: {
  117. pageSize: 18,
  118. enabled: true
  119. },
  120. pager: {},
  121. "export": {
  122. enabled: true,
  123. fileName: '계약 목록',
  124. },
  125. onExporting: function (e) {
  126. e.component.columnOption("ContractId", "visible", false);
  127. },
  128. onExported: function (e) {
  129. e.component.columnOption("ContractId", "visible", true);
  130. },
  131. searchViewItems: [
  132. { id: 'Name' },
  133. { id: 'StartDate', type: 'dateRange', isOnlyDate: true },
  134. { id: 'EndDate', type: 'dateRange', isOnlyDate: true },
  135. { id: 'CmPartner/Name' },
  136. { id: 'OwnerShipName' },
  137. { id: 'PartnerTypeId', ignoreValue: 0, defaultValue: 0, dataSource: partnerTypesForSearch },
  138. { id: 'ContractClassId', ignoreValue: 0, defaultValue: 0, dataSource: contractClassesForSearch },
  139. { id: 'ContractMethodId', ignoreValue: 0, defaultValue: 0, dataSource: contractMethodsForSearch },
  140. { id: 'ContractTypeId', ignoreValue: 0, defaultValue: 0, dataSource: contractTypesForSearch },
  141. { id: 'PaymentTypeId', ignoreValue: 0, defaultValue: 0, dataSource: paymentTypesForSearch },
  142. ],
  143. handleViewShowing: function (dataModel) {
  144. $.when(
  145. partnerTypeDataSource.load(),
  146. contractClassDataSource.load(),
  147. contractMethodDataSource.load(),
  148. contractTypeDataSource.load(),
  149. paymentTypeDataSource.load(),
  150. partnerDataSource.load()
  151. ).done(function (partnerTypeDataResult, contractClassDataResult, contractMethodDataResult, contractTypeDataResult, paymentTypeDataResult, partnerDataResult) {
  152. partnerTypes(partnerTypeDataResult[0]);
  153. contractClasses(contractClassDataResult[0]);
  154. contractMethods(contractMethodDataResult[0]);
  155. contractTypes(contractTypeDataResult[0]);
  156. paymentTypes(paymentTypeDataResult[0]);
  157. allPartner(partnerDataResult[0]);
  158. partnerTypesForSearch($SearchView.createArrayOfSelectBox('PartnerTypeId', partnerTypeDataResult[0]));
  159. contractClassesForSearch($SearchView.createArrayOfSelectBox('ContractClassId', contractClassDataResult[0]));
  160. contractMethodsForSearch($SearchView.createArrayOfSelectBox('ContractMethodId', contractMethodDataResult[0]));
  161. contractTypesForSearch($SearchView.createArrayOfSelectBox('ContractTypeId', contractTypeDataResult[0]));
  162. paymentTypesForSearch($SearchView.createArrayOfSelectBox('PaymentTypeId', paymentTypeDataResult[0]));
  163. deferredForSearch.resolve();
  164. });
  165. },
  166. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
  167. var data = clickRow.data;
  168. RowName = data.Name;
  169. popupVisible(true);
  170. },
  171. // 이름 중복 방지
  172. handlePopupShowing: function () {
  173. FmsConstractDataSource.filter([
  174. ["SiteId", "=", BWA.UserInfo.SiteId()]
  175. ]);
  176. FmsConstractDataSource.load().done(function (result) {
  177. ConstractInfo(result);
  178. });
  179. },
  180. beforeInsertingDataViewModel: function (dataModel, dbModelId) {
  181. var dfd = $.Deferred();
  182. var isDuplicated = false;
  183. if (dataModel.StartDate() > dataModel.EndDate())
  184. dfd.resolve(false, '시작일은 종료일 이전으로 선택해야 합니다.', 'error');
  185. for (var i = 0; i < ConstractInfo().length; i++) {
  186. if (dataModel.Name() == ConstractInfo()[i].Name()) {
  187. isDuplicated = true;
  188. break;
  189. }
  190. }
  191. if (!BWA.DataUtil.isValidInputValue(dataModel.Name()))
  192. return dfd.resolve(false, '저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)');
  193. else {
  194. if (isDuplicated)
  195. return dfd.resolve(false, '이미 동일 정보가 존재합니다.');
  196. else
  197. return dfd.resolve(true);
  198. }
  199. },
  200. beforeUpdateDataViewModel: function () {
  201. if (viewModel.dataModel.StartDate() > viewModel.dataModel.EndDate()) {
  202. utils.toast.show('시작일은 종료일 이전으로 선택해야 합니다.', 'error');
  203. return 0;
  204. }
  205. var isDuplicated = false;
  206. for (var i = 0; i < ConstractInfo().length; i++) {
  207. if (viewModel.dataModel.Name() == ConstractInfo()[i].Name() && RowName() != ConstractInfo()[i].Name()) {
  208. isDuplicated = true;
  209. break;
  210. }
  211. }
  212. if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
  213. utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
  214. return 0;
  215. }
  216. else {
  217. if (isDuplicated) {
  218. utils.toast.show('이미 동일 정보가 존재합니다.', 'error');
  219. return 0;
  220. }
  221. else
  222. return 2;
  223. }
  224. },
  225. });
  226. function processValueChange(e) {
  227. filteredPartner([]);
  228. _.each(allPartner(), function (partner) {
  229. if (e.value === partner.PartnerTypeId()) {
  230. filteredPartner.push(partner);
  231. }
  232. });
  233. if (!_.isEmpty(filteredPartner())) {
  234. viewModel.dataModel.PartnerId(filteredPartner()[0].PartnerId());
  235. }
  236. }
  237. viewModel.processValueChange = processValueChange;
  238. viewModel.partnerTypes = partnerTypes;
  239. viewModel.contractClasses = contractClasses;
  240. viewModel.contractMethods = contractMethods;
  241. viewModel.contractTypes = contractTypes;
  242. viewModel.paymentTypes = paymentTypes;
  243. viewModel.allPartner = allPartner;
  244. viewModel.filteredPartner = filteredPartner;
  245. return viewModel;
  246. };