You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1025 lines
54 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sViewPrgId = sProgramId.replace('_Upd', '_View'),
  5. sAction = getUrlParam('Action') || 'Add',
  6. sDataId = getUrlParam('Guid'),
  7. sCheckId = sDataId,
  8. fnPageInit = function () {
  9. var oCurData = { CheckOrder: [], PayeeInfo: [] },
  10. oForm = $('#form_main'),
  11. oGrid = null,
  12. oValidator = null,
  13. sOptionHtml_PrjCode = '',
  14. sOptionHtml_Currency = '',
  15. sOptionHtml_Bills = '',
  16. oAddItem = {},
  17. saUsers = [],
  18. /**
  19. * 獲取資料
  20. */
  21. fnGet = function () {
  22. if (sDataId) {
  23. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  24. {
  25. Guid: sDataId
  26. },
  27. function (res) {
  28. if (res.RESULT) {
  29. var oRes = res.DATA.rel;
  30. oCurData = oRes;
  31. oCurData.PayeeInfo = $.parseJSON(oCurData.PayeeInfo);
  32. oCurData.RemittanceInformation = $.parseJSON(oCurData.RemittanceInformation);
  33. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  34. setFormVal(oForm, oRes);
  35. $('.Applicant').text(oCurData.ApplicantName + '(' + oCurData.Applicant + ') ' + oCurData.DeptName);
  36. $('#PayeeCode').text(oCurData.CustomerNO);
  37. fnGetUploadFiles(oCurData.Guid, fnUpload);
  38. if (oCurData.Handle_DeptID) {
  39. fnSetUserDrop([
  40. {
  41. Select: $('#Handle_Person'),
  42. DepartmentID: oCurData.Handle_DeptID,
  43. ShowId: true,
  44. Select2: true,
  45. Action: sAction,
  46. DefultVal: oCurData.Handle_Person
  47. }
  48. ]);
  49. }
  50. if (oCurData.Flows_Lock === 'Y') {
  51. $(".checkordertoolbox").hide();
  52. }
  53. else {
  54. $(".checkordertoolbox").show();
  55. }
  56. if (oCurData.Handle_Lock === 'Y') {
  57. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  58. }
  59. else {
  60. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  61. }
  62. $("#jsGrid").jsGrid("loadData");
  63. $("#jsGrid1").jsGrid("loadData");
  64. setNameById().done(function () {
  65. getPageVal();//緩存頁面值,用於清除
  66. });
  67. }
  68. });
  69. }
  70. else {
  71. $('.Applicant').text(parent.UserInfo.MemberName + '(' + parent.UserInfo.MemberID + ') ' + parent.UserInfo.DepartmentName);
  72. $('#Applicant').val(parent.UserInfo.MemberID);
  73. oCurData.PayeeInfo = [];
  74. oCurData.CheckOrder = [];
  75. oCurData.Guid = guid();
  76. fnUpload();
  77. return $.Deferred().resolve().promise();
  78. }
  79. },
  80. /**
  81. * 新增資料
  82. * @param {String} sFlag 新增或儲存後新增
  83. */
  84. fnAdd = function (flag) {
  85. var data = getFormSerialize(oForm);
  86. data = packParams(data);
  87. data.OrgID = parent.OrgID;
  88. data.Guid = oCurData.Guid;
  89. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|IAC|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  90. data.CheckFlows = fnCheckFlows(oCurData, false, true, saUsers);
  91. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  92. data.PayeeInfo = JSON.stringify(oCurData.PayeeInfo);
  93. data.RemittanceInformation = JSON.stringify(data.RemittanceInformation);
  94. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  95. data.Status = 'A';
  96. data.IsHandled = 'N';
  97. data.PayeeType = 'C';
  98. data.Inspectors = '';
  99. data.Reminders = '';
  100. data.Flows_Lock = oCurData.Flows_Lock;
  101. data.Handle_Lock = oCurData.Handle_Lock;
  102. data.PayeeName = $('#Payee option:selected').text();
  103. if (data.PaymentType === 'A') {
  104. delete data.PaymentTime;
  105. }
  106. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  107. Params: {
  108. invoiceapplyinfo: data
  109. }
  110. }, function (res) {
  111. if (res.d > 0) {
  112. bRequestStorage = false;
  113. if (flag == 'add') {
  114. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Save_Success⇒新增成功╣
  115. }
  116. else {
  117. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  118. }
  119. }
  120. else {
  121. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  122. }
  123. }, function () {
  124. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  125. });
  126. },
  127. /**
  128. * 修改資料
  129. * @param {Boolean} balert 是否提示
  130. */
  131. fnUpd = function (balert) {
  132. var data = getFormSerialize(oForm);
  133. data = packParams(data, 'upd');
  134. data.CheckFlows = fnCheckFlows(oCurData, false, true, saUsers);
  135. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  136. data.PayeeInfo = JSON.stringify(oCurData.PayeeInfo);
  137. data.RemittanceInformation = JSON.stringify(data.RemittanceInformation);
  138. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  139. data.Flows_Lock = oCurData.Flows_Lock;
  140. data.Handle_Lock = oCurData.Handle_Lock;
  141. data.PayeeName = $('#Payee option:selected').text();
  142. if (data.PaymentType === 'A') {
  143. delete data.PaymentTime;
  144. }
  145. return CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  146. Params: {
  147. invoiceapplyinfo: {
  148. values: data,
  149. keys: { Guid: sDataId }
  150. }
  151. }
  152. }, function (res) {
  153. if (res.d > 0) {
  154. if (!balert) {
  155. bRequestStorage = false;
  156. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  157. if (window.bLeavePage) {
  158. setTimeout(function () {
  159. pageLeave();
  160. }, 1000);
  161. }
  162. }
  163. }
  164. else {
  165. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  166. }
  167. }, function () {
  168. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  169. });
  170. },
  171. /**
  172. * 資料刪除
  173. */
  174. fnDel = function () {
  175. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  176. Params: {
  177. invoiceapplyinfo: {
  178. Guid: sDataId
  179. }
  180. }
  181. }, function (res) {
  182. if (res.d > 0) {
  183. DelTask(sDataId);
  184. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  185. }
  186. else {
  187. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  188. }
  189. }, function () {
  190. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  191. });
  192. },
  193. /**
  194. * 設定受款人下拉選單
  195. */
  196. setPayeeDrop = function () {
  197. return g_api.ConnectLite(Service.sys, 'GetCustomerlist', {}, function (res) {
  198. if (res.RESULT) {
  199. var saPayee = res.DATA.rel;
  200. if (saPayee.length > 0) {
  201. $('#Payee').html(createOptions(saPayee, 'id', 'text')).change(function () {
  202. var sId = this.value,
  203. oPayee = $.grep(saPayee, function (item) { return item.id === sId; })[0];
  204. $('#PayeeCode').text(oPayee.CusNO);
  205. });
  206. select2Init($('#Payee').parent());
  207. }
  208. }
  209. });
  210. },
  211. /**
  212. * 上傳附件
  213. * @param {Array} files 上傳的文件
  214. */
  215. fnUpload = function (files) {
  216. var option = {};
  217. option.input = $('#fileInput');
  218. option.theme = 'dragdropbox';
  219. option.folder = 'InvoiceApplyForCustomer';
  220. option.type = 'list';
  221. option.parentid = oCurData.Guid;
  222. if (files) {
  223. option.files = files;
  224. }
  225. fnUploadRegister(option);
  226. },
  227. /**
  228. * 提交簽呈
  229. */
  230. fnSubmitPetition = function () {
  231. g_api.ConnectLite(sProgramId, 'InvoiceApplyForCustomerToAudit', {
  232. guid: oCurData.Guid
  233. }, function (res) {
  234. if (res.RESULT) {
  235. showMsgAndGo(i18next.t("message.ToAudit_Success"), sViewPrgId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.ToAudit_Success⇒提交審核成功╣
  236. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  237. }
  238. else {
  239. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  240. }
  241. }, function () {
  242. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  243. });
  244. },
  245. /**
  246. * 提交費用項目
  247. * TETG以TWD為主其他幣別為輔
  248. * SG以RMB為主其他幣別為輔
  249. */
  250. fnSumPayeeInfo = function () {
  251. //TE、TG以TWD為主,其他幣別為輔。
  252. //SG以RMB為主,其他幣別為輔。
  253. var iTotal_MainCurrency = 0;
  254. var iTotal_SecondCurrency = 0;
  255. var MainRoundingPoint = 0;
  256. var MainCurrency = 'NTD';
  257. var SecondCurrency = 'NTD';
  258. var SecondRoundingPoint = 2;
  259. if (parent.OrgID === 'SG') {
  260. MainCurrency = 'RMB';
  261. SecondCurrency = 'RMB';
  262. MainRoundingPoint = 2;
  263. }
  264. $.each(oCurData.PayeeInfo, function (idx, info) {
  265. let PayeeAmount = parseFloat((info.Amount || '0').toString().replaceAll(',', ''));
  266. if (info.Currency === MainCurrency) {
  267. iTotal_MainCurrency += PayeeAmount;
  268. }
  269. else {
  270. iTotal_SecondCurrency += PayeeAmount;
  271. SecondCurrency = info.Currency;
  272. if (info.Currency === 'NTD') {
  273. SecondRoundingPoint = 0;
  274. }
  275. }
  276. });
  277. $('#RemittanceInformation_TotalCurrencyTW').val(MainCurrency);
  278. $('#RemittanceInformation_InvoiceApplyTotalTW').val(fMoney(iTotal_MainCurrency, MainRoundingPoint, MainCurrency));
  279. $('#RemittanceInformation_TotalCurrency').val(SecondCurrency);
  280. $('#RemittanceInformation_InvoiceApplyTotal').val(fMoney(iTotal_SecondCurrency, SecondRoundingPoint, ''));
  281. },
  282. /**
  283. * 通過帳單號碼抓去專案代號
  284. * @param {HTMLElement} dom select控件
  285. */
  286. fnGetPrjCodeByBillNO = function (dom) {
  287. var sBillNO = dom.value;
  288. g_api.ConnectLite(Service.eip, 'GetPrjCodeByBillNO', {
  289. BillNO: sBillNO
  290. }, function (res) {
  291. if (res.RESULT) {
  292. var oRes = res.DATA.rel;
  293. $(dom).parent().next().find('select').val(oRes.PrjCode).trigger("change");
  294. }
  295. });
  296. },
  297. /**
  298. * ToolBar 按鈕事件 function
  299. * @param {Object}inst 按鈕物件對象
  300. * @param {Object} e 事件對象
  301. */
  302. fnButtonHandler = function (inst, e) {
  303. var sId = inst.id;
  304. switch (sId) {
  305. case "Toolbar_Qry":
  306. break;
  307. case "Toolbar_Save":
  308. if (!$("#form_main").valid()) {
  309. oValidator.focusInvalid();
  310. return false;
  311. }
  312. if (sAction === 'Add') {
  313. fnAdd('add');
  314. }
  315. else {
  316. fnUpd();
  317. }
  318. break;
  319. case "Toolbar_ReAdd":
  320. if (!$("#form_main").valid()) {
  321. oValidator.focusInvalid();
  322. return false;
  323. }
  324. fnAdd('readd');
  325. break;
  326. case "Toolbar_Clear":
  327. clearPageVal();
  328. break;
  329. case "Toolbar_Leave":
  330. pageLeave();
  331. break;
  332. case "Toolbar_Add":
  333. break;
  334. case "Toolbar_Upd":
  335. break;
  336. case "Toolbar_Copy":
  337. break;
  338. case "Toolbar_Petition":
  339. if (!$("#form_main").valid()) {
  340. oValidator.focusInvalid();
  341. return false;
  342. }
  343. fnUpd(true).done(function () {
  344. fnSubmitPetition();
  345. });
  346. break;
  347. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  348. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  349. fnDel();
  350. layer.close(index);
  351. });
  352. break;
  353. default:
  354. alert("No handle '" + sId + "'");
  355. break;
  356. }
  357. },
  358. /**
  359. * 初始化 function
  360. */
  361. init = function () {
  362. var saCusBtns = null;
  363. if (sAction === 'Upd') {
  364. saCusBtns = [{
  365. id: 'Toolbar_Petition',
  366. value: 'common.SubmitPetition'// ╠common.SubmitPetition⇒提交簽呈╣
  367. }];
  368. }
  369. commonInit({
  370. PrgId: sProgramId,
  371. ButtonHandler: fnButtonHandler,
  372. Buttons: saCusBtns,
  373. GoTop: true
  374. });
  375. oValidator = $("#form_main").validate();
  376. $.whenArray([
  377. fnSetDeptDrop($('#Handle_DeptID')),
  378. fnGetBills({
  379. CallBack: function (data) {
  380. sOptionHtml_Bills = createOptions(data, 'BillNO', 'BillNO');
  381. }
  382. }),
  383. setPayeeDrop(),
  384. fnSetFlowDrop({
  385. Flow_Type: parent.SysSet.Eip_006,
  386. ShareTo: parent.UserID,
  387. CallBack: function (data) {
  388. $.each(data, function (idx, item) {
  389. var saFlows = $.parseJSON(item.Flows),
  390. saFlowsText = [],
  391. sFlowsText = '';
  392. $.each(saFlows, function (idx, flow) {
  393. var sFlowType = i18next.t('common.' + flow.SignedWay);
  394. if (flow.SignedWay !== 'flow1') {
  395. saFlowsText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  396. }
  397. else {
  398. saFlowsText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  399. }
  400. });
  401. sFlowsText = saFlowsText.join(' → ');
  402. item.text = item.Flow_Name + ' - ' + (sFlowsText.length > 60 ? sFlowsText.substr(0, 60) + '...' : sFlowsText);
  403. });
  404. $('#FlowId').html(createOptions(data, 'Guid', 'text')).on('change', function () {
  405. var sFlowId = this.value;
  406. if (sFlowId) {
  407. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  408. Type: '',
  409. Params: {
  410. checkflow: {
  411. Guid: sFlowId
  412. }
  413. }
  414. }, function (res) {
  415. if (res.d) {
  416. var oRes = $.parseJSON(res.d);
  417. oRes.Flows = $.parseJSON(oRes.Flows);
  418. oCurData.CheckOrder = oRes.Flows;
  419. oCurData.Flows_Lock = oRes.Flows_Lock;
  420. oCurData.Handle_Lock = oRes.Handle_Lock;
  421. //選擇新流程,變更現有經辦人(Handle_Person)與經辦部門(Handle_DeptID)。
  422. //因為新增或者修改是fnHandleFlows(oCurData,saUsers); //Mark 20190617
  423. oCurData.Handle_Person = oRes.Handle_Person;
  424. oCurData.Handle_DeptID = oRes.Handle_DeptID;
  425. oCurData.Handle_PersonName = oRes.Handle_PersonName;
  426. //設置經辦部門
  427. $("#Handle_DeptID").val(oRes.Handle_DeptID);
  428. //設置經辦人員
  429. fnSetUserDrop([
  430. {
  431. Select: $('#Handle_Person'),
  432. DepartmentID: oRes.Handle_DeptID,
  433. ShowId: true,
  434. Select2: true,
  435. Action: sAction,
  436. DefultVal: oRes.Handle_Person
  437. }
  438. ]);
  439. //$("#Handle_Person").val(oRes.Handle_Person).trigger('change');
  440. if (oRes.Flows_Lock === 'Y') {
  441. $(".checkordertoolbox").hide();
  442. }
  443. else {
  444. $(".checkordertoolbox").show();
  445. }
  446. if (oRes.Handle_Lock === 'Y') {
  447. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  448. }
  449. else {
  450. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  451. }
  452. $("#jsGrid").jsGrid("loadData");
  453. }
  454. });
  455. }
  456. else {
  457. oCurData.CheckOrder = [];
  458. $(".checkordertoolbox").hide();
  459. $("#jsGrid").jsGrid("loadData");
  460. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  461. }
  462. });
  463. }
  464. }),
  465. fnSetEpoDrop({
  466. CallBack: function (data) {
  467. sOptionHtml_PrjCode = createOptions(data, 'ExhibitionCode', 'ExhibitioShotName_TW');
  468. }
  469. }),
  470. fnSetUserDrop([
  471. {
  472. ShowId: true,
  473. Select: $('#Handle_Person'),
  474. Select2: true,
  475. Action: sAction,
  476. CallBack: function (data) {
  477. saUsers = data;
  478. }
  479. }
  480. ]),
  481. fnSetArgDrop([
  482. {
  483. ArgClassID: 'Currency',
  484. CallBack: function (data) {
  485. sOptionHtml_Currency = createOptions(data, 'id', 'id');
  486. if (parent.OrgID === 'SG') {
  487. $('#RemittanceInformation_TotalCurrencyTW,#RemittanceInformation_TotalCurrency').html(sOptionHtml_Currency).val('RMB')[0].remove(0);
  488. }
  489. else {
  490. $('#RemittanceInformation_TotalCurrencyTW,#RemittanceInformation_TotalCurrency').html(sOptionHtml_Currency).val('NTD')[0].remove(0);
  491. }
  492. }
  493. }
  494. ])])
  495. .done(function () {
  496. fnGet();
  497. $("#jsGrid1").jsGrid({
  498. width: "100%",
  499. height: "auto",
  500. autoload: true,
  501. filtering: false,
  502. inserting: true,
  503. editing: true,
  504. pageLoading: true,
  505. confirmDeleting: true,
  506. invalidMessage: i18next.t('common.InvalidData'),// ╠common.InvalidData⇒输入的数据无效!╣
  507. deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
  508. pageIndex: 1,
  509. pageSize: 10000,
  510. fields: [
  511. {// ╠common.FeeItemName⇒費用名稱╣
  512. name: "FeeItemName", title: 'common.FeeItemName', width: 150, type: "text", validate: { validator: 'required', message: i18next.t('common.FeeItemName_required') },
  513. insertTemplate: function (val, item) {
  514. var oControl = $('<input />', {
  515. class: "form-control w100p"
  516. });
  517. return this.insertControl = oControl;
  518. },
  519. insertValue: function () {
  520. return this.insertControl.val();
  521. },
  522. editTemplate: function (val, item) {
  523. var oControl = $('<input />', {
  524. class: "form-control w100p",
  525. value: val
  526. });
  527. return this.editControl = oControl;
  528. },
  529. editValue: function () {
  530. return this.editControl.val();
  531. }
  532. },
  533. {
  534. name: "BillNO", title: 'common.BillNO', width: 120, type: "text",
  535. insertTemplate: function (val, item) {
  536. var oControl = $('<select />', {
  537. class: "form-control w100p",
  538. html: sOptionHtml_Bills,
  539. change: function () {
  540. fnGetPrjCodeByBillNO(this);
  541. }
  542. });
  543. setTimeout(function () {
  544. oControl.select2({ width: '180px' });
  545. }, 100);
  546. return this.insertControl = oControl;
  547. },
  548. insertValue: function () {
  549. return this.insertControl.val();
  550. },
  551. editTemplate: function (val, item) {
  552. var oControl = $('<select />', {
  553. class: "form-control w100p",
  554. html: sOptionHtml_Bills,
  555. change: function () {
  556. fnGetPrjCodeByBillNO(this);
  557. }
  558. });
  559. setTimeout(function () {
  560. oControl.select2({ width: '180px' });
  561. }, 100);
  562. return this.editControl = oControl.val(item.BillNO);
  563. },
  564. editValue: function () {
  565. return this.editControl.val();
  566. }
  567. },
  568. {
  569. name: "PrjCode", title: 'common.PrjCode', width: 160, type: "text",
  570. itemTemplate: function (val, item) {
  571. return val + (!item.PrjName ? '' : '(' + item.PrjName + ')');
  572. },
  573. insertTemplate: function (val, item) {
  574. var oControl = $('<select />', {
  575. class: "form-control w100p",
  576. html: sOptionHtml_PrjCode
  577. });
  578. setTimeout(function () {
  579. oControl.select2({ width: '240px' });
  580. }, 1000);
  581. return this.insertControl = oControl;
  582. },
  583. insertValue: function () {
  584. var SelectedOption = this.insertControl.find('option:selected');
  585. if (this.insertControl.val() && SelectedOption.val()) {
  586. oAddItem.PrjName = SelectedOption.text();
  587. }
  588. else {
  589. oAddItem.PrjName = '';
  590. }
  591. return this.insertControl.val();
  592. },
  593. editTemplate: function (val, item) {
  594. var oControl = $('<select />', {
  595. class: "form-control w100p",
  596. html: sOptionHtml_PrjCode,
  597. change: function () {
  598. var SelectedOption = $(this).find('option:selected');
  599. if (SelectedOption.val()) {
  600. item.PrjName = SelectedOption.text();
  601. }
  602. else {
  603. item.PrjName = '';
  604. }
  605. }
  606. });
  607. setTimeout(function () {
  608. oControl.select2({ width: '240px' });
  609. }, 100);
  610. return this.editControl = oControl.val(item.PrjCode);
  611. },
  612. editValue: function () {
  613. return this.editControl.val();
  614. }
  615. },
  616. {
  617. name: "Currency", title: 'common.Financial_Currency', width: 60, type: "text", validate: { validator: 'required', message: i18next.t('common.Currency_required') },// ╠common.Currency_required⇒請選擇幣別╣
  618. insertTemplate: function (val, item) {
  619. var oControl = $('<select />', {
  620. class: "form-control w100p",
  621. html: sOptionHtml_Currency
  622. });
  623. return this.insertControl = oControl;
  624. },
  625. insertValue: function () {
  626. return this.insertControl.val();
  627. },
  628. editTemplate: function (val, item) {
  629. var oControl = $('<select />', {
  630. class: "form-control w100p",
  631. html: sOptionHtml_Currency
  632. });
  633. return this.editControl = oControl.val(item.Currency);
  634. },
  635. editValue: function () {
  636. return this.editControl.val();
  637. }
  638. },
  639. {
  640. name: "Amount", title: 'common.Financial_Amount', width: 70, type: "text", align: "right", validate: { validator: 'required', message: i18next.t('common.Amount_required') },
  641. itemTemplate: function (val, item) {
  642. return val.toString().toMoney();
  643. },
  644. insertTemplate: function (val, item) {
  645. var oControl = $('<input />', {
  646. class: "form-control w100p",
  647. 'data-type': 'int',
  648. 'data-name': 'int',
  649. value: val
  650. });
  651. moneyInput(oControl, 2, true);
  652. return this.insertControl = oControl;
  653. },
  654. insertValue: function () {
  655. if (this._grid.fields[3].insertControl.val() == 'NTD') {
  656. let AmountStr = this.insertControl.val().replaceAll(',', '');
  657. let PositiveInt = parseInt(AmountStr);
  658. this.insertControl.val(PositiveInt);
  659. this.insertControl[0].dataset.value = PositiveInt;
  660. }
  661. return this.insertControl.attr('data-value');
  662. },
  663. editTemplate: function (val, item) {
  664. var oControl = $('<input />', {
  665. class: "form-control w100p",
  666. 'data-type': 'int',
  667. 'data-name': 'int',
  668. value: val
  669. });
  670. moneyInput(oControl, 2, true);
  671. return this.editControl = oControl.val(val);
  672. },
  673. editValue: function () {
  674. if (this._grid.fields[3].editControl.val() == 'NTD') {
  675. let AmountStr = this.editControl.val().replaceAll(',', '');
  676. let PositiveInt = parseInt(AmountStr);
  677. this.editControl.val(PositiveInt);
  678. this.editControl[0].dataset.value = PositiveInt;
  679. }
  680. return this.editControl.attr('data-value');
  681. }
  682. },
  683. {
  684. type: "control", width: 50
  685. }
  686. ],
  687. controller: {
  688. loadData: function (args) {
  689. return {
  690. data: oCurData.PayeeInfo,
  691. itemsCount: oCurData.PayeeInfo.length //data.length
  692. };
  693. },
  694. insertItem: function (args) {
  695. args.guid = guid();
  696. args.Index = oCurData.PayeeInfo.length + 1;
  697. args.PrjName = oAddItem.PrjName;
  698. oCurData.PayeeInfo.push(args);
  699. fnSumPayeeInfo();
  700. },
  701. updateItem: function (args) {
  702. $.each(oCurData.PayeeInfo, function (idx, _data) {
  703. if (_data.guid === args.guid) {
  704. _data.Amount = args.Amount;
  705. _data.BillNO = args.BillNO;
  706. _data.Currency = args.Currency;
  707. _data.FeeItemName = args.FeeItemName;
  708. _data.PrjCode = args.PrjCode;
  709. _data.PrjName = args.PrjName;
  710. }
  711. });
  712. fnSumPayeeInfo();
  713. },
  714. deleteItem: function (args) {
  715. var saPayeeInfo = [];
  716. $.each(oCurData.PayeeInfo, function (idx, _data) {
  717. if (_data.guid !== args.guid) {
  718. saPayeeInfo.push(_data);
  719. }
  720. });
  721. $.each(saPayeeInfo, function (idx, _data) {
  722. _data.Index = idx + 1;
  723. });
  724. oCurData.PayeeInfo = saPayeeInfo;
  725. fnSumPayeeInfo();
  726. }
  727. },
  728. onInit: function (args) {
  729. oGrid = args.grid;
  730. }
  731. });
  732. });
  733. $('#Handle_DeptID').on('change', function () {
  734. fnSetUserDrop([
  735. {
  736. Select: $('#Handle_Person'),
  737. DepartmentID: this.value,
  738. ShowId: true,
  739. Select2: true,
  740. Action: sAction
  741. }
  742. ]);
  743. });
  744. $('#Agent_Person').on('change', function () {
  745. oCurData.Agent_Person = this.value;
  746. });
  747. $('[name="PaymentType"]').on('click', function () {
  748. if (this.value === 'A') {
  749. $('#PaymentTime').removeAttr('required');
  750. }
  751. else {
  752. $('#PaymentTime').attr('required', true);
  753. }
  754. });
  755. $('.flowlink').on('click', function () {
  756. var oOption = {};
  757. oOption.SignedWay = this.id;
  758. oOption.Callback = function (data) {
  759. if (data.Users.length > 0) {
  760. var oFlow = {};
  761. if (data.FlowType === 'flow1') {
  762. $.each(data.Users, function (idx, user) {
  763. oFlow = {};
  764. oFlow.id = guid();
  765. oFlow.Order = oCurData.CheckOrder.length + 1;
  766. oFlow.SignedWay = data.FlowType;
  767. oFlow.SignedMember = [{
  768. id: user.id,
  769. name: user.name,
  770. deptname: user.deptname,
  771. jobname: user.jobname
  772. }];
  773. oCurData.CheckOrder.push(oFlow);
  774. });
  775. }
  776. else {
  777. var saSignedMember = [];
  778. $.each(data.Users, function (idx, user) {
  779. saSignedMember.push({
  780. id: user.id,
  781. name: user.name,
  782. deptname: user.deptname,
  783. jobname: user.jobname
  784. });
  785. });
  786. oFlow.id = guid();
  787. oFlow.Order = oCurData.CheckOrder.length + 1;
  788. oFlow.SignedWay = data.FlowType;
  789. oFlow.SignedMember = saSignedMember;
  790. oCurData.CheckOrder.push(oFlow);
  791. }
  792. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  793. $("#jsGrid").jsGrid("loadData");
  794. }
  795. };
  796. oPenUserListPop(oOption);
  797. });
  798. $("#jsGrid").jsGrid({
  799. width: "100%",
  800. height: "auto",
  801. autoload: true,
  802. filtering: false,
  803. pageLoading: true,
  804. pageIndex: 1,
  805. pageSize: 10000,
  806. fields: [
  807. {
  808. name: "Order", title: 'common.Order', width: 50, align: "center",
  809. itemTemplate: function (val, item) {
  810. return val < 10 ? '0' + val : val;
  811. }
  812. },
  813. {
  814. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  815. itemTemplate: function (val, item) {
  816. return i18next.t('common.' + val);
  817. }
  818. },
  819. {
  820. type: "Icon", width: 50, align: "center",
  821. itemTemplate: function (val, item) {
  822. var oIcon = {
  823. flow1: '<img src="../../images/flow_check.gif">',
  824. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  825. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  826. flow4: '<img src="../../images/flow4.gif">'
  827. },
  828. sIcon = oIcon[item.SignedWay];
  829. if (item.Order !== oCurData.CheckOrder.length) {
  830. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  831. }
  832. return sIcon;
  833. }
  834. },
  835. {
  836. name: "SignedMember", title: 'common.SignedMember', width: 500,
  837. itemTemplate: function (val, item) {
  838. return Enumerable.From(val).ToString(",", "$.name");
  839. }
  840. },
  841. {
  842. type: "control", title: 'common.Action', width: 200,
  843. itemTemplate: function (val, item) {
  844. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  845. class: 'glyphicon glyphicon-pencil' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  846. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  847. click: function () {
  848. if ($(this).hasClass('disabled')) { return false; }
  849. var oOption = {};
  850. oOption.SignedWay = item.SignedWay;
  851. oOption.SignedMember = item.SignedMember;
  852. oOption.Callback = function (data) {
  853. if (data.Users.length > 0) {
  854. var oFlow = {};
  855. if (data.FlowType === 'flow1') {
  856. $.each(data.Users, function (idx, user) {
  857. var oFlow = {};
  858. oFlow.id = guid();
  859. oFlow.Order = item.Order + idx;
  860. oFlow.SignedWay = data.FlowType;
  861. oFlow.SignedMember = [{
  862. id: user.id,
  863. name: user.name,
  864. deptname: user.deptname,
  865. jobname: user.jobname
  866. }];
  867. oCurData.CheckOrder.insert(item.Order + idx, oFlow);
  868. });
  869. }
  870. else {
  871. var saSignedMember = [];
  872. $.each(data.Users, function (idx, user) {
  873. saSignedMember.push({
  874. id: user.id,
  875. name: user.name,
  876. deptname: user.deptname,
  877. jobname: user.jobname
  878. });
  879. });
  880. oFlow.id = guid();
  881. oFlow.Order = item.Order;
  882. oFlow.SignedWay = data.FlowType;
  883. oFlow.SignedMember = saSignedMember;
  884. oCurData.CheckOrder.insert(item.Order, oFlow);
  885. }
  886. var iOrder = 1;
  887. $.each(oCurData.CheckOrder, function (idx, _data) {
  888. if (item.id !== _data.id) {
  889. _data.Order = iOrder;
  890. iOrder++;
  891. }
  892. });
  893. oCurData.CheckOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  894. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  895. $("#jsGrid").jsGrid("loadData");
  896. }
  897. };
  898. oPenUserListPop(oOption);
  899. }
  900. })),
  901. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  902. class: 'glyphicon glyphicon-trash' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  903. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  904. click: function () {
  905. if ($(this).hasClass('disabled')) { return false; }
  906. var saNewList = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  907. oCurData.CheckOrder = saNewList;
  908. $.each(oCurData.CheckOrder, function (idx, _data) {
  909. _data.Order = idx + 1;
  910. });
  911. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  912. $("#jsGrid").jsGrid("loadData");
  913. }
  914. }))];
  915. if (oCurData.CheckOrder.length !== item.Order) {
  916. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  917. class: 'glyphicon glyphicon-arrow-down' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  918. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  919. click: function () {
  920. if ($(this).hasClass('disabled')) { return false; }
  921. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  922. iOrder = sOrder * 1;
  923. $.each(oCurData.CheckOrder, function (idx, _data) {
  924. if (iOrder === _data.Order) {
  925. _data.Order++;
  926. }
  927. else if ((iOrder + 1) === _data.Order) {
  928. _data.Order--;
  929. }
  930. });
  931. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  932. $("#jsGrid").jsGrid("loadData");
  933. }
  934. })));
  935. }
  936. else {
  937. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  938. }
  939. if (1 !== item.Order) {
  940. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  941. class: 'glyphicon glyphicon-arrow-up' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  942. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  943. click: function () {
  944. if ($(this).hasClass('disabled')) { return false; }
  945. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  946. iOrder = sOrder * 1;
  947. $.each(oCurData.CheckOrder, function (idx, _data) {
  948. if (iOrder === _data.Order) {
  949. _data.Order--;
  950. }
  951. else if ((iOrder - 1) === _data.Order) {
  952. _data.Order++;
  953. }
  954. });
  955. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  956. $("#jsGrid").jsGrid("loadData");
  957. }
  958. })));
  959. }
  960. return oBtns;
  961. }
  962. }
  963. ],
  964. controller: {
  965. loadData: function (args) {
  966. return {
  967. data: oCurData.CheckOrder,
  968. itemsCount: oCurData.CheckOrder.length //data.length
  969. };
  970. },
  971. insertItem: function (args) {
  972. },
  973. updateItem: function (args) {
  974. },
  975. deleteItem: function (args) {
  976. }
  977. }
  978. });
  979. };
  980. init();
  981. };
  982. require(['base', 'select2', 'jsgrid', 'formatnumber', 'filer', 'common_eip', 'util'], fnPageInit);