33db9c56ecda01cc32d31d518282763fe0d177bd.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. BemsWebApplication.WorkHistory = function (params, viewInfo) {
  2. "use strict";
  3. //권한설정
  4. var hasnotModificationPermission = ko.observable(true);
  5. var endpointSelector;
  6. if (BemsWebApplication.config.mode == "production") {
  7. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  8. } else {
  9. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  10. }
  11. var FmsMaterialExdataSource = new DevExpress.data.DataSource({
  12. store: BemsWebApplication.odata.FmsMaterialEx,
  13. requireTotalCount: true,
  14. pageSize: 100
  15. });
  16. var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
  17. var businessFieldDataSource = BemsWebApplication.db.createDataSource('CmBusinessField', true, true, true),
  18. workTypeDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeType'),
  19. progressDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeProgress'),
  20. businessFields = ko.observableArray(),
  21. workTypes = ko.observableArray(),
  22. progresses = ko.observableArray();
  23. var WORK_PLAN = $Code.WorkProgress.WORK_PLAN;
  24. var isVisibleExecutionButton = ko.observable(true);
  25. var isVisibleApproalButton = ko.observable(true);
  26. var isEditModeInPopup = ko.observable(true);
  27. var isEditHistoryButton = ko.observable(false);
  28. var isAddHistoryButton = ko.observable(false);
  29. var isWorkDone = ko.observable(false);
  30. var isWorkHold = ko.observable(false);
  31. var popup, addWorkResultCheckItemPopup = null;
  32. var workResultCheckItemMaterialPopup = null;
  33. var WorkResultCheckItemFacilityPopup = null;
  34. //var workApprovalMaterialPopup = null;
  35. //var workExecutionRegisterPopup = null;
  36. // hcLee 2018 01 29 -->
  37. var imagefileUrl1 = ko.observable(),
  38. imagefileUrl2 = ko.observable(),
  39. dropZone1 = null,
  40. dropZone2 = null,
  41. uploadedFileInfo = {},
  42. uploadedFileInfo2 = {};
  43. // <-- hcLee 2018 01 29
  44. var deferredForSearch = new $.Deferred();
  45. var SiteId = BWA.UserInfo.SiteId();
  46. var workTypesForSearch = ko.observableArray(),
  47. businessFieldsForSearch = ko.observableArray(),
  48. progressesForSearch = ko.observableArray();
  49. var eq = BWA.DataUtil.constructEqualFilter,
  50. or = BWA.DataUtil.orFilter,
  51. and = BWA.DataUtil.andFilter,
  52. noteq = BWA.DataUtil.constructNotEqualFilter;
  53. var selectedFacilityData = ko.observable(),
  54. selectedUserData = params.selectedUserData || ko.observable();
  55. var dataSourceOptions = {
  56. select: [
  57. 'SiteId', 'WorkRequestId', 'BusinessFieldId',
  58. 'FmsWorkResult/StartDate', 'FmsWorkResult/EndDate',
  59. 'FmsWorkResult/ConfirmedDate', 'FmsWorkResult/ConfirmedUserId', 'FmsWorkResult/IsConfirmed',
  60. 'FmsWorkResult/CauseClassId', 'FmsWorkResult/Content', 'FmsWorkResult/ConfirmDesc',//추가
  61. 'WorkTypeId', 'StartWorkDate',
  62. 'FmsWorkOrder/CmBusinessField',
  63. 'CmUser/Name', // 신청자
  64. 'Title', // 제목
  65. 'Content', // 내용
  66. 'FmsWorkOrder/OrderDate',
  67. 'WorkProgressId',
  68. 'FmsWorkResult/CmUser/Name', // 작업자
  69. 'FmsWorkResult/CmUser1/Name', // 승인자
  70. 'FmsWorkCodeType/Name',
  71. 'CmBusinessField/Name',
  72. 'FmsWorkCodeProgress/Name',
  73. 'CmUser1/Name', // 반려자
  74. 'RejectDate', 'RejectReason',
  75. 'FmsWorkOrder/Content'
  76. ],
  77. expand: [
  78. 'FmsWorkResult',
  79. 'FmsWorkOrder',
  80. 'FmsWorkCodeType',
  81. 'FmsWorkCodeProgress',
  82. 'CmBusinessField',
  83. 'FmsWorkOrder/CmBusinessField',
  84. 'CmUser', 'CmUser1',
  85. 'FmsWorkResult/CmUser', 'FmsWorkResult/CmUser1'],
  86. extendOptions: {
  87. forceOriginalField: true
  88. }
  89. };
  90. if (!useBusinessFiltering) {
  91. dataSourceOptions.filter = [
  92. eq('SiteId', SiteId),
  93. and,
  94. ['WorkProgressId', '>', WORK_PLAN],
  95. ];
  96. }
  97. else {
  98. dataSourceOptions.filter = [
  99. eq('SiteId', SiteId),
  100. and,
  101. ['WorkProgressId', '>', WORK_PLAN],
  102. and,
  103. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]];
  104. }
  105. //var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkResult', {
  106. var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsWorkRequest', {
  107. popupWidth: 890,
  108. dataSourceOptions: dataSourceOptions,
  109. columns: [
  110. { dataField: 'WorkRequestId', caption: $G('number'), width: '8%', alignment: 'center' },
  111. { dataField: 'CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' },
  112. //{ dataField: 'FmsWorkOrder/CmBusinessField/Name', caption: $G('businessFieldName'), width: '10%', alignment: 'center' },
  113. { dataField: 'FmsWorkCodeType/Name', caption: $G('workTypeName'), width: '10%', alignment: 'center' },
  114. {
  115. dataField: 'FmsWorkOrder/OrderDate', caption: $G('orderedDate'), width: '12%', alignment: 'center', visible: false
  116. // , sortOrder: 'desc' ,customizeText: function (cellInfo) { return $G.date(cellInfo.value); }
  117. },
  118. {
  119. dataField: 'FmsWorkResult/StartDate', caption: $G('startDate'), width: '12%', alignment: 'center', dataType: "shortDate", format: 'yyyy-MM-dd',
  120. customizeText: function (cellInfo) {
  121. return cellInfo.valueText;
  122. }
  123. },
  124. {
  125. dataField: 'FmsWorkResult/EndDate', caption: '종료일', width: '12%', alignment: 'center', dataType: "shortDate", format: 'yyyy-MM-dd', sortOrder: 'desc',
  126. customizeText: function (cellInfo) {
  127. return cellInfo.valueText;
  128. }
  129. },
  130. {
  131. dataField: 'FmsWorkResult/ConfirmedDate', caption: '승인일', width: '12%', alignment: 'center', dataType: "shortDate", format: 'yyyy-MM-dd',
  132. customizeText: function (cellInfo) {
  133. return cellInfo.valueText;
  134. }
  135. },
  136. { dataField: 'Title', caption: '작업명', width: '50%', alignment: 'center' },
  137. { dataField: 'FmsWorkCodeProgress/Name', caption: $G('workProgressName'), width: '10%', alignment: 'center' },
  138. { dataField: 'CmUser/Name', caption: '신청자', width: '12%', alignment: 'center' },
  139. { dataField: 'CmUser1/Name', caption: '반려자', width: '12%', alignment: 'center', visible: false },
  140. { dataField: 'FmsWorkResult/CmUser/Name', caption: '작업자', width: '12%', alignment: 'center' },
  141. { dataField: 'FmsWorkResult/CmUser1/Name', caption: '승인자', width: '12%', alignment: 'center' },
  142. { dataField: 'FmsWorkOrder/Content', caption: '오더내용', width: '0%', alignment: 'center' }
  143. ],
  144. "export": {
  145. enabled: true,
  146. fileName: '작업 이력 목록',
  147. },
  148. onExporting: function (e) {
  149. e.component.columnOption("WorkRequestId", "visible", false);
  150. },
  151. onExported: function (e) {
  152. e.component.columnOption("WorkRequestId", "visible", true);
  153. },
  154. promiseDataInSearchView: deferredForSearch.promise(),
  155. searchViewItems: _.compact([
  156. //{ id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
  157. { id: 'BusinessFieldId', ignoreValue: 0, defaultValue: 0, dataSource: businessFieldsForSearch },
  158. { id: 'WorkTypeId', ignoreValue: 0, defaultValue: 0, dataSource: workTypesForSearch },
  159. { id: 'CmUser/Name' },
  160. { id: 'CmUser1/Name' },
  161. { id: 'FmsWorkResult/CmUser/Name' },
  162. { id: 'FmsWorkResult/CmUser1/Name' },
  163. { id: 'Title' },
  164. { id: 'WorkProgressId', ignoreValue: 0, defaultValue: 0, dataSource: progressesForSearch },
  165. { id: 'FmsWorkResult/StartDate', type: 'dateRange', isOnlyDate: true },
  166. { id: 'FmsWorkResult/EndDate', type: 'dateRange', isOnlyDate: true },
  167. { id: 'FmsWorkResult/ConfirmedDate', type: 'dateRange', isOnlyDate: true }
  168. ]),
  169. getAddedToolbarItemsInPopup: function (e) {
  170. //var isEditModeInPopup = e.isEditModeInPopup;
  171. //var isVisibleApproalButton = e.dataViewModel.IsConfirmed;
  172. return [
  173. {
  174. location: 'after', widget: 'button', options: {
  175. text: '승인', icon: 'add', type: 'success', visible: isVisibleApproalButton, disabled: hasnotModificationPermission,
  176. clickAction: approvalWorkResult
  177. }
  178. },
  179. {
  180. location: 'after', widget: 'button', options: {
  181. text: "삭제", icon: 'remove', type: 'danger', visible: isEditModeInPopup, disabled: hasnotModificationPermission,
  182. clickAction: removeWorkResult
  183. }
  184. }
  185. ];
  186. //{
  187. // location: 'after', widget: 'button', options: {
  188. // text: '작업이력수정', icon: 'save',
  189. // clickAction: function () {
  190. // if (popup && popup.modifyWorkItem) {
  191. // popup.modifyWorkItem();
  192. // }
  193. // }
  194. // }
  195. //},
  196. //{
  197. // location: 'after', widget: 'button', options: {
  198. // text: $G('facilityInsertion'), icon: 'search', visible: isEditModeInPopup,
  199. // clickAction: function () {
  200. // popup.facilitySearchPopup.show();
  201. // }
  202. // }
  203. //},
  204. //{
  205. // location: 'after', widget: 'button', options: {
  206. // text: $G('facilityDeletion'), icon: 'remove', type: 'danger', visible: isEditModeInPopup,
  207. // clickAction: removeWorkResult
  208. // }
  209. //}
  210. },
  211. beforeInsertingDataViewModel: function (dataModel) {
  212. return true; // hcLee
  213. },
  214. handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) { //추가
  215. dataGrid.clearSelection();
  216. var data = clickRow.data;
  217. var dataModel = viewModel.dataModel;
  218. //viewModel.dataModel.StartDate = ko.observable();
  219. //viewModel.dataModel.EndDate = ko.observable();
  220. //if (data['FmsWorkResult/StartDate'] !== undefined) {
  221. // viewModel.dataModel.StartDate(data['FmsWorkResult/StartDate']());
  222. // viewModel.dataModel.EndDate(data['FmsWorkResult/EndDate']());
  223. //}
  224. // hcLee 2016 04 04
  225. if (data['WorkProgressId']() >= $Code.WorkProgress.WORK_COMPLETE)
  226. isWorkDone(true);
  227. else
  228. isWorkDone(false);
  229. if (data['WorkProgressId']() == $Code.WorkProgress.WORK_HOLD) {
  230. isWorkHold(true);
  231. isWorkDone(false);
  232. }
  233. else {
  234. isWorkHold(false);
  235. }
  236. isVisibleApproalButton(false);
  237. if (popup && popup.handleBeforeShowingPopupForEdit) {
  238. popup.handleBeforeShowingPopupForEdit(data, dataModel);
  239. }
  240. //popup.show();
  241. popupVisible(true);
  242. if (dataModel.WorkProgressId() >= $Code.WorkProgress.WORKING) {
  243. workResultCheckItemMaterialPopup.visible(true);
  244. //workApprovalMaterialPopup.visible(true);
  245. }
  246. },
  247. handleBeforePopupShowingPromise: function () {
  248. if (popup && popup.handleBeforePopupShowingPromise) {
  249. popup.handleBeforePopupShowingPromise.apply(popup, arguments);
  250. }
  251. },
  252. handleAfterLoadingModelByKey: function () {
  253. if (popup && popup.handleAfterLoadingModelByKey) {
  254. popup.handleAfterLoadingModelByKey.apply(popup, arguments);
  255. }
  256. },
  257. handlePopupShowing: function () {
  258. if (popup && popup.handlePopupShowing) {
  259. popup.handlePopupShowing.apply(this, arguments);
  260. }
  261. },
  262. handlePopupShown: function (editMode, isNewInPopup, dataModel) {
  263. if (popup && popup.handlePopupShowing) {
  264. popup.handlePopupShown.apply(this, arguments);
  265. }
  266. },
  267. handleSaveButtonInPopup: function (isInsert) {
  268. if (isInsert === false) {
  269. if (popup && popup.handleAfterSave) {
  270. popup.handleAfterSave(undefined);
  271. }
  272. }
  273. },
  274. handleAfterSaveInPopup: function (responseKey, response) {
  275. if (popup && popup.handleAfterSave) {
  276. popup.handleAfterSave(responseKey, response);
  277. }
  278. },
  279. handleViewShowing: function (dataModel) {
  280. //권한설정
  281. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  282. FmsMaterialExdataSource.filter([
  283. ["SiteId", "=", BWA.UserInfo.SiteId()]
  284. ]);
  285. FmsMaterialExdataSource.load().done(function (result) {
  286. if (result != null) {
  287. viewModel.dataModel.MaterialExdataSource(result);
  288. }
  289. }).fail(function (error) {
  290. utils.toast.show(error);
  291. });
  292. if (useBusinessFiltering) {
  293. businessFieldDataSource.filter([
  294. eq('SiteId', SiteId),
  295. and,
  296. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]
  297. ]);
  298. }
  299. $.when(
  300. businessFieldDataSource.load(),
  301. workTypeDataSource.load(),
  302. progressDataSource.load()
  303. ).done(function (businessFieldResult, workTypeResult, progressResult) {
  304. businessFields(businessFieldResult[0]);
  305. workTypes(workTypeResult[0]);
  306. //progressResult[0].items.Remove[0];
  307. progresses(progressResult[0]);
  308. progresses.shift();
  309. businessFieldsForSearch($SearchView.createArrayOfSelectBox('BusinessFieldId', businessFields()));
  310. workTypesForSearch($SearchView.createArrayOfSelectBox('WorkTypeId', workTypes()));
  311. //progressesForSearch($SearchView.createArrayOfSelectBox('ProgressId', progresses())); hcLee 2016 02 01 'ProgressId' -> 'WorkProgressId'
  312. progressesForSearch($SearchView.createArrayOfSelectBox('WorkProgressId', progresses()));
  313. deferredForSearch.resolve();
  314. });
  315. },
  316. handleViewShown: function () {
  317. $("#gridContainer").dxDataGrid({
  318. paging: {
  319. pageSize: 18,
  320. enabled: true
  321. }
  322. });
  323. }
  324. });
  325. viewModel.isEditHistoryButton = isEditHistoryButton;
  326. viewModel.isAddHistoryButton = isAddHistoryButton;
  327. viewModel.isWorkDone = isWorkDone;
  328. viewModel.isWorkHold = isWorkHold;
  329. viewModel.dataModel.MaterialExdataSource = ko.observable();
  330. // hcLee 2018 01 29 -->
  331. viewModel.imagefileUrl1 = imagefileUrl1;
  332. viewModel.imagefileUrl2 = imagefileUrl2;
  333. // <-- hcLee 2018 01 29
  334. viewModel.businessFields = businessFields;
  335. viewModel.workTypes = workTypes;
  336. viewModel.isAddPopup = ko.observable(false);
  337. viewModel.isApprovalMode = ko.observable(false);
  338. // 작업이력 화면인지 여부
  339. viewModel.isWorkHistory = ko.observable(true);
  340. addWorkResultCheckItemPopup = viewModel.addWorkResultCheckItemPopup = BWA.Popup.AddWorkResultCheckItem.create(viewInfo, viewModel);
  341. popup = viewModel.popup = BWA.Popup.WorkHistory.create(viewInfo, viewModel);
  342. workResultCheckItemMaterialPopup = viewModel.workResultCheckItemMaterialPopup = BWA.Popup.WorkResultCheckItemMaterial.create(viewInfo, viewModel);
  343. WorkResultCheckItemFacilityPopup = viewModel.WorkResultCheckItemFacilityPopup = BWA.Popup.WorkResultCheckItemFacility.create(viewInfo, viewModel);
  344. //workApprovalMaterialPopup = viewModel.workApprovalMaterialPopup = BWA.Popup.WorkApprovalMaterial.create(viewInfo, viewModel);
  345. function approvalWorkResult() {
  346. viewModel.dataModel.ConfirmedDate(new Date());
  347. viewModel.dataModel.IsConfirmed(true);
  348. viewModel.dataModel.ConfirmedUserId(BWA.UserInfo.UserId());
  349. var keys = BWA.db.extractKeysObject('FmsWorkResult', viewModel.dataModel);
  350. BWA.db.FmsWorkResult.update(keys, viewModel.dataModel.toJS()).done(function (res) {
  351. var parameters = {
  352. SiteId: SiteId,
  353. WorkRequestId: viewModel.dataModel.WorkRequestId(),
  354. WorkProgressId: $Code.WorkProgress.WORK_CONFIRM
  355. };
  356. // FmsWorkRequest 업데이트: WorkProgressId(6)
  357. BWA.api.post('FmsWorkRequest', null, parameters);
  358. utils.toast.show($G('successDatabaseUpdateMsg'));
  359. //popup.popupVisible(false);
  360. viewModel.popupOptions.visible(false);
  361. viewModel.gridView().refresh();
  362. });
  363. utils.toast.show('Approval Clicked!');
  364. }
  365. function removeWorkResult() {
  366. var WorkRequestId = viewModel.dataModel.WorkRequestId();
  367. var WorkProgressId = viewModel.dataModel.WorkScheduleId();
  368. BWA.api.post('FmsWorkHistory/Remove', {
  369. SiteId: SiteId,
  370. WorkRequestId: WorkRequestId,
  371. }).done(function () {
  372. utils.toast.show("데이터를 삭제하였습니다.");
  373. $('#gridContainer').dxDataGrid('instance').refresh();
  374. viewModel.popupOptions.visible(false);
  375. }).fail(function (error) {
  376. utils.toast.show("데이터 삭제를 실패하였습니다.", 'error');
  377. });
  378. }
  379. viewModel.popupOptions.position = { offset: '-200 0' };
  380. viewModel.popupOptions.height = '930px';
  381. return viewModel;
  382. };