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.

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