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.

707 lines
32 KiB

2 years ago
  1. (function ($, w, d) {
  2. 'use strict';
  3. /**
  4. * 上海駒驛須移除選項
  5. * @param {Object} input jquery 物件;
  6. */
  7. w.fnKeyUnit = function (input) {
  8. input.value = input.value.toUpperCase();
  9. };
  10. /**
  11. * 上海駒驛須移除選項
  12. * @param {Object} handle jquery 物件;
  13. */
  14. w.fnSGMod = function (handle) {
  15. var oHandle = handle || $('.shjy-box');
  16. if (parent.OrgID !== 'SG') {
  17. oHandle.remove();
  18. }
  19. };
  20. /**
  21. * 更新帳單信息
  22. * @param {String} servname 服務端類名稱
  23. * @param {String} xbid 當前資料id
  24. * @param {String} billno 帳單號碼
  25. */
  26. w.fnUpdateBillInfo = function (servname, xbid, billno) {
  27. var oPm = { Guid: xbid };
  28. if (billno) {
  29. oPm.BillNO = billno;
  30. }
  31. g_api.ConnectLite(servname, 'UpdateBillInfo', oPm, function (res) {
  32. if (res.RESULT) {
  33. console.log(res);
  34. }
  35. });
  36. };
  37. /**
  38. * 更新帳單信息
  39. * @param {String} billno 帳單號碼
  40. */
  41. w.fnDeleteBillInfo = function (billno) {
  42. var oPm = { BillNO: billno };
  43. g_api.ConnectLite('Exhibition', 'DeleteBillInfo', oPm, function (res) {
  44. if (res.RESULT) {
  45. console.log(res);
  46. }
  47. });
  48. };
  49. //取得下拉已選的數值
  50. w.getSelectedValues = function (strSelector) {
  51. let result = [];
  52. let collection = document.querySelectorAll(strSelector + " option");
  53. collection.forEach(function (x) {
  54. if (x.selected) {
  55. result.push(x.value);
  56. }
  57. });
  58. return result;
  59. };
  60. /**
  61. * 驗證是否存在的的有效的帳單資料
  62. * @param {Array} bills 帳單
  63. * @return {Boolean} 是否有效
  64. */
  65. w.fnCheckBillEffective = function (bills) {
  66. var saBill_Effective = [];
  67. if (bills && bills.length > 0) {
  68. saBill_Effective = $.grep(bills, function (bill) {
  69. return bill.AuditVal !== '6';
  70. });
  71. }
  72. return saBill_Effective.length > 0;
  73. };
  74. /**
  75. * 驗證是否存在的的有效的帳單資料
  76. * @param {Array} bills 退運帳單
  77. * @return {Boolean} 是否有效
  78. */
  79. w.fnCheckRtnBillEffective = function (bills) {
  80. var saBill_Effective = [];
  81. if (bills && bills.length > 0) {
  82. $.grep(bills, function (_bill) {
  83. if (_bill.Bills && _bill.Bills.length > 0) {
  84. saBill_Effective.push($.grep(_bill.Bills, function (bill) {
  85. return bill.AuditVal !== '6';
  86. }));
  87. }
  88. });
  89. }
  90. return saBill_Effective.length > 0;
  91. };
  92. /**
  93. * 添加費用明細
  94. * @param {Object} option 配置
  95. */
  96. w.fnStarFeeItems = function (option) {
  97. option = option || {};
  98. var oGrid = null,
  99. saItems = [],
  100. saProfileGets = [],
  101. fnSetProfileDrop = function (handle) {
  102. return CallAjax(ComFn.W_Com, ComFn.GetList, {
  103. Type: '', Params: {
  104. profiles: {
  105. ProfileType: 'FeeClass',
  106. OrgID: parent.OrgID,
  107. UserID: parent.UserID
  108. },
  109. sort: { SN: 'asc' }
  110. }
  111. }, function (res) {
  112. if (res.d) {
  113. saProfileGets = JSON.parse(res.d);
  114. handle.html(createOptions(saProfileGets, 'SN', 'ProfileName'));
  115. }
  116. });
  117. },
  118. fnAddProfile = function (layero) {
  119. var oAddPm = {};
  120. oAddPm.OrgID = parent.OrgID;
  121. oAddPm.UserID = parent.UserID;
  122. oAddPm.ProfileType = 'FeeClass';
  123. oAddPm.ProfileName = layero.find('#ProfileName').val();
  124. oAddPm.ProfileSet = [];
  125. layero.find('#lstRight option').each(function () {
  126. oAddPm.ProfileSet.push(this.value);
  127. });
  128. oAddPm.ProfileSet = JSON.stringify(oAddPm.ProfileSet);
  129. oAddPm = packParams(oAddPm);
  130. if (!oAddPm.ProfileName) {
  131. showMsg(i18next.t("message.ProfileFeesClassName_Required")); //╠message.ProfileFeesClassName_Required⇒請填寫個人化費用類別名稱╣
  132. return false;
  133. }
  134. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  135. Params: {
  136. profiles: oAddPm
  137. }
  138. }, function (res) {
  139. if (res.d > 0) {
  140. fnSetProfileDrop(layero.find('#ProfileClass')).done(function () {
  141. layero.find('#ProfileClass option').each(function () {
  142. if ($(this).text() === oAddPm.ProfileName) {
  143. layero.find('#ProfileClass').val(this.value);
  144. return false;
  145. }
  146. });
  147. });
  148. showMsg(i18next.t("message.Save_Success"), 'success'); // ╠message.Save_Success⇒新增成功╣
  149. }
  150. else {
  151. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  152. }
  153. }, function () {
  154. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  155. });
  156. },
  157. fnUpdProfile = function (layero) {
  158. var oUpdPm = {},
  159. sId = layero.find('#ProfileClass').val();
  160. oUpdPm.ProfileName = layero.find('#ProfileName').val();
  161. oUpdPm.ProfileSet = [];
  162. layero.find('#lstRight option').each(function () {
  163. oUpdPm.ProfileSet.push(this.value);
  164. });
  165. oUpdPm.ProfileSet = JSON.stringify(oUpdPm.ProfileSet);
  166. oUpdPm = packParams(oUpdPm, 'upd');
  167. if (!oUpdPm.ProfileName) {
  168. showMsg(i18next.t("message.ProfileFeesClassName_Required")); // 請填寫個人化費用類別名稱
  169. return false;
  170. }
  171. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  172. Params: {
  173. profiles: {
  174. values: oUpdPm,
  175. keys: { SN: sId }
  176. }
  177. }
  178. }, function (res) {
  179. if (res.d > 0) {
  180. fnSetProfileDrop(layero.find('#ProfileClass')).done(function () {
  181. layero.find('#ProfileClass').val(sId);
  182. });
  183. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  184. }
  185. else {
  186. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  187. }
  188. }, function () {
  189. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  190. });
  191. },
  192. fnDelProfile = function (layero) {
  193. var sId = layero.find('#ProfileClass').val();
  194. if (!sId) {
  195. showMsg(i18next.t("message.DeleteItem_Required")); //╠message.DeleteItem_Required⇒請選擇要刪除的項目╣
  196. return false;
  197. }
  198. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  199. Params: {
  200. profiles: {
  201. SN: sId
  202. }
  203. }
  204. }, function (res) {
  205. if (res.d > 0) {
  206. fnSetProfileDrop(layero.find('#ProfileClass'));
  207. layero.find('#ProfileName').val('');
  208. layero.find('#lstRight').html('');
  209. layero.find('#lstLeft').html(createOptions(saItems, 'id', 'text', true));
  210. layero.find('#lstLeft').find('option:first').remove();
  211. showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣
  212. }
  213. else {
  214. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  215. }
  216. }, function () {
  217. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  218. });
  219. };
  220. getHtmlTmp('/Page/Pop/ProfileFees.html').done(function (html) {
  221. layer.open({
  222. type: 1,
  223. title: i18next.t('common.ProfileFees'),// ╠common.ProfileFees⇒個人化費用項目╣
  224. shadeClose: false,
  225. shade: 0.1,
  226. maxmin: true, //开启最大化最小化按钮
  227. area: ['600px', '500px'],
  228. content: html,
  229. success: function (layero, index) {
  230. var elIistLeft = layero.find('#lstLeft'),
  231. elLstRight = layero.find('#lstRight');
  232. fnSetProfileDrop(layero.find('#ProfileClass'));
  233. fnSetArgDrop([
  234. {
  235. ArgClassID: 'FeeClass',
  236. Select: elIistLeft,
  237. ShowId: true,
  238. CallBack: function (data) {
  239. saItems = data;
  240. }
  241. }
  242. ]).done(function () {
  243. elIistLeft.find('option:first').remove();
  244. optionListSearch(elIistLeft, elLstRight, layero.find('#ProfileFilter'));
  245. });
  246. layero.find('#ProfileClass').on('change', function () {
  247. var sProfile = this.value,
  248. saProfileSet = [];
  249. if (sProfile) {
  250. var oProfileGet = $.grep(saProfileGets, function (e) { return e.SN.toString() === sProfile; })[0];
  251. saProfileSet = JSON.parse(oProfileGet.ProfileSet || '[]');
  252. layero.find('#ProfileName').val(oProfileGet.ProfileName);
  253. }
  254. else {
  255. layero.find('#ProfileName').val('');
  256. }
  257. elLstRight.html('');
  258. elIistLeft.html(createOptions(saItems, 'id', 'text', true)).find('option:first').remove();
  259. layero.find('#lstLeft option').each(function () {
  260. var sId = $(this).val();
  261. if (saProfileSet.indexOf(sId) > -1) {
  262. $(this).appendTo(elLstRight);
  263. }
  264. });
  265. });
  266. layero.find('.cusclass-add').on('click', function () {
  267. fnAddProfile(layero);
  268. });
  269. layero.find('.cusclass-upd').on('click', function () {
  270. fnUpdProfile(layero);
  271. });
  272. layero.find('.cusclass-del').on('click', function () {
  273. fnDelProfile(layero);
  274. });
  275. layero.find('#btnToRight').on('click', function () {
  276. optionListMove(elIistLeft, elLstRight);
  277. });
  278. layero.find('#btnToLeft').on('click', function () {
  279. optionListMove(elLstRight, elIistLeft);
  280. });
  281. layero.find('#btnToUp').on('click', function () {
  282. optionListOrder(elLstRight, true);
  283. });
  284. layero.find('#btnToDown').on('click', function () {
  285. optionListOrder(elLstRight, false);
  286. });
  287. transLang(layero);
  288. },
  289. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  290. yes: function (index, layero) {
  291. var saRetn = [];
  292. layero.find('#lstRight option').each(function () {
  293. var sId = $(this).val();
  294. saRetn.push({
  295. guid: guid(),
  296. FinancialCode: $(this).val(),
  297. FinancialCostStatement: $(this).text(),
  298. Memo: '',
  299. FinancialCurrency: 'NTD',
  300. FinancialUnitPrice: '0',
  301. FinancialNumber: '',
  302. FinancialUnit: '',
  303. FinancialAmount: '0',
  304. FinancialExchangeRate: '1',
  305. FinancialTWAmount: '0',
  306. FinancialTaxRate: '0',
  307. FinancialTax: '0',
  308. CreateUser: parent.UserID,
  309. CreateDate: newDate()
  310. });
  311. });
  312. if (typeof option.Callback === 'function') option.Callback(saRetn);
  313. layer.close(index);
  314. },
  315. cancel: function () {
  316. if (typeof option.CancelCallback === 'function') option.CancelCallback();
  317. }
  318. });
  319. });
  320. };
  321. /**
  322. * 複製費用項目
  323. * @param {Object} option 配置
  324. */
  325. w.fnCopyFee = function (option) {
  326. option = option || {};
  327. var oGrid = null,
  328. oBilllist = null,
  329. saLastData = [],
  330. saFeeList = [],
  331. fnGetBillList = function (exhibitionno, billno, flag) {
  332. return g_api.ConnectLite(Service.opm, 'GetBillInfos',
  333. {
  334. ExhibitionNO: exhibitionno || '',
  335. BillNO: billno || ''
  336. },
  337. function (res) {
  338. if (res.RESULT) {
  339. var saData = res.DATA.rel;
  340. if (saData.length > 0) {
  341. saLastData = JSON.parse(saData[0].FeeItems);
  342. }
  343. else {
  344. saLastData = [];
  345. }
  346. if (flag) {
  347. if (saData.length > 0) {
  348. var sBilllistHtml = '';
  349. $.each(saData, function (idx, _data) {
  350. sBilllistHtml += (idx === 0 ? '<li class="active">' : '<li>') + _data.BillNO + '</li>';
  351. });
  352. oBilllist.html(sBilllistHtml).find('li').click(function () {
  353. oBilllist.find('li').removeClass('active');
  354. var sBillNO = $(this).addClass('active').text(),
  355. sExhibitionNO = $('#ExhibitionName').val();
  356. fnGetBillList(sExhibitionNO, sBillNO, false);
  357. });
  358. }
  359. else {
  360. oBilllist.html('');
  361. }
  362. }
  363. oGrid.jsGrid("loadData");
  364. }
  365. });
  366. }, //╠common.ExhibitionName⇒展覽名稱╣ ╠common.BillNO⇒帳單號碼╣
  367. sContent = '<style>.select2-container--open { z-index: 1000000001;}.jsgrid-header-cell{padding:0 0;}</style>\
  368. <div class="row popsrow">\
  369. <label class="col-sm-2 control-label wright" for="input-Default"><span data-i18n="common.ExhibitionName">展覽名稱</span></label>\
  370. <div class="col-sm-4">\
  371. <select class="form-control" id="ExhibitionName"></select>\
  372. </div>\
  373. <label class="col-sm-1 control-label wright" for="input-Default"><span data-i18n="common.BillNO">帳單號碼</span></label>\
  374. <div class="col-sm-4">\
  375. <input type="text" class="form-control w100p" id="BillNO" maxlength="50">\
  376. </div>\
  377. </div>\
  378. <div class="row popsrow">\
  379. <div class="col-sm-2">\
  380. <div class="bill-box slimscroll">\
  381. <ul class="bill-list">\
  382. </ul>\
  383. </div>\
  384. </div>\
  385. <div class="col-sm-10">\
  386. <div id="jsGrid_Fees"></div>\
  387. </div>\
  388. <div class="col-sm-2"></div>\
  389. </div>';
  390. layer.open({
  391. type: 1,
  392. title: i18next.t('common.CopyFeeItems'),//╠common.CopyFeeItems⇒複製費用項目╣
  393. shadeClose: false,
  394. shade: 0.1,
  395. maxmin: true, //开启最大化最小化按钮
  396. area: ['800px', '500px'],
  397. content: sContent,
  398. success: function (layero, index) {
  399. fnSetEpoDrop({
  400. Select: $('#ExhibitionName'),
  401. Select2: true
  402. });
  403. oBilllist = layero.find('.bill-list');
  404. oGrid = $("#jsGrid_Fees").jsGrid({
  405. width: "100%",
  406. height: "320px",
  407. autoload: true,
  408. filtering: false,
  409. pageLoading: true,
  410. pageIndex: 1,
  411. pageSize: 10000,
  412. fields: [
  413. {
  414. name: "OrderBy", title: '#', width: 30, align: "center"
  415. },
  416. {
  417. width: 50, sorting: false, align: "center",
  418. headerTemplate: function () {
  419. return [$("<input>", {
  420. id: 'SelectAll',
  421. type: 'checkbox', click: function () {
  422. if (this.checked) {
  423. $("#jsGrid_Fees").find('[type=checkbox]').each(function () {
  424. this.checked = true;
  425. });
  426. saFeeList = clone(saLastData);
  427. }
  428. else {
  429. $("#jsGrid_Fees").find('[type=checkbox]').each(function () {
  430. this.checked = false;
  431. });
  432. saFeeList = [];
  433. }
  434. }
  435. }), $('<label />', { for: 'SelectAll', 'data-i18n': 'common.SelectAll' })];//╠common.SelectAll⇒全選╣
  436. },
  437. itemTemplate: function (value, item) {
  438. return $("<input>", {
  439. type: 'checkbox', click: function (e) {
  440. e.stopPropagation();
  441. if (this.checked) {
  442. saFeeList.push(item);
  443. }
  444. else {
  445. var saNewList = [];
  446. $.each(saFeeList, function (idx, data) {
  447. if (item.guid !== data.guid) {
  448. saNewList.push(data);
  449. }
  450. });
  451. saFeeList = saNewList;
  452. $('#jsGrid_Fees').find('#SelectAll')[0].checked = false;
  453. }
  454. }
  455. });
  456. }
  457. },
  458. {
  459. name: "FinancialCode", title: 'common.Financial_Code', width: 70, type: "text"
  460. },
  461. {
  462. name: "FinancialCostStatement", title: 'common.Financial_CostStatement', width: 150, type: "text",
  463. itemTemplate: function (val, item) {
  464. return val === '' ? item.Memo : val;
  465. }
  466. },
  467. {
  468. name: "FinancialCurrency", title: 'common.Financial_Currency', width: 60, type: "text", align: "center"
  469. },
  470. {
  471. name: "FinancialUnitPrice", title: 'common.Financial_UnitPrice', width: 80, align: "right", type: "text",
  472. itemTemplate: function (val, item) {
  473. return fMoney(val || 0, 2);
  474. }
  475. },
  476. {
  477. name: "FinancialNumber", title: 'common.Financial_Number', width: 80, type: "text", align: "right"
  478. },
  479. {
  480. name: "FinancialUnit", title: 'common.Financial_Unit', width: 80, type: "text"
  481. },
  482. {
  483. name: "FinancialAmount", title: 'common.Financial_Amount', width: 80, type: "text", align: "right",
  484. itemTemplate: function (val, item) {
  485. return fMoney(val || 0, 2);
  486. }
  487. },
  488. {
  489. name: "FinancialExchangeRate", title: 'common.ExchangeRate', width: 60, type: "text", align: "center"
  490. },
  491. {
  492. name: "FinancialTWAmount", title: 'common.Financial_TWAmount', width: 80, align: "right", type: "text",
  493. itemTemplate: function (val, item) {
  494. return fMoney(val || 0, 2);
  495. }
  496. },
  497. {
  498. name: "FinancialTaxRate", title: 'common.Financial_TaxRate', width: 60, align: "center", type: "text"
  499. },
  500. {
  501. name: "FinancialTax", title: 'common.Financial_Tax', width: 80, align: "right", type: "text",
  502. itemTemplate: function (val, item) {
  503. return fMoney(val || 0, 2);
  504. }
  505. }
  506. ],
  507. controller: {
  508. loadData: function (args) {
  509. return {
  510. data: saLastData,
  511. itemsCount: saLastData.length //data.length
  512. };
  513. }
  514. }
  515. });
  516. layero.find('.layui-layer-btn1').css({ 'border-color': '#4898d5', 'background-color': '#1E9FFF', 'color': '#fff' });
  517. },
  518. btn: [i18next.t('common.Toolbar_Qry'), i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Toolbar_Qry⇒查詢╣ ╠common.Confirm⇒確定╣ ╠common.Cancel⇒取消╣
  519. yes: function (index, layero) {
  520. var sExhibitionNO = layero.find('#ExhibitionName').val(),
  521. sBillNO = layero.find('#BillNO ').val();
  522. fnGetBillList(sExhibitionNO, sBillNO, true);
  523. },
  524. btn2: function (index, layero) {
  525. if (typeof option.Callback === 'function') option.Callback(saFeeList);
  526. layer.close(index);
  527. }
  528. });
  529. };
  530. w.fnGetCurrencyByYear = function (opm) {
  531. return g_api.ConnectLite('CurrencySetup_Qry', 'GetCurrencyByYear', {
  532. year: opm.Year
  533. }, function (res) {
  534. if (res.RESULT) {
  535. var saList = res.DATA.rel;
  536. if (opm.CallBack && typeof opm.CallBack === 'function') {
  537. opm.CallBack(saList);
  538. }
  539. }
  540. }, {}, false);
  541. };
  542. w.roundDecimal = function (val, precision) {
  543. return Math.round(Math.round(val * Math.pow(10, (precision || 0) + 1)) / 10) / Math.pow(10, (precision || 0));
  544. };
  545. /**
  546. * 檢驗單據是否有權限存取
  547. * @param {Object} option 配置
  548. */
  549. w.ExhibitionBillAuthorize = function (Opm) {
  550. //人員:負責業務、創建人、老闆、部門主管、直屬主管
  551. //角色:財務組、Admin
  552. //BillAutherizedList 例外清單
  553. var BillAutherizedList = parent.SysSet.BillAutherizedList.toLowerCase().indexOf(parent.UserID) > -1;
  554. var AccessAuthorize = false;
  555. var CurrentUserID = parent.UserID;
  556. var ResponsibleToThisExhibition = Opm.ResponsiblePerson === CurrentUserID || Opm.CreateUser === CurrentUserID;
  557. if (!ResponsibleToThisExhibition && !BillAutherizedList) {
  558. var QueryData = {
  559. RuleID: 'Account,Admin',
  560. ResponsiblePerson: Opm.ResponsiblePerson
  561. };
  562. g_api.ConnectLite(Service.opm, 'GetExhibitionBillAuthorize', QueryData, function (res) {
  563. if (res.RESULT) {
  564. AccessAuthorize = res.DATA.rel.indexOf(parent.UserID) > -1
  565. }
  566. else {
  567. AccessAuthorize = false;
  568. }
  569. }, {}, false);
  570. }
  571. return ResponsibleToThisExhibition || AccessAuthorize || BillAutherizedList;
  572. };
  573. /**
  574. * 開放權限可以編輯
  575. */
  576. w.fnOpenAccountingArea = function (group, userid) {
  577. if (userid.indexOf('Admin') > -1 || userid.indexOf('Account') > -1 && group.length > 0) {
  578. group.find('input').removeAttr('disabled');
  579. group.find('select').removeAttr('disabled');
  580. }
  581. };
  582. /**
  583. * 計算報價費用
  584. */
  585. w.fnCalcuQuotationFee = function (OriginFeeField, CountFeeField, CurrencyID, ExchangeRate) {
  586. let RoundingPoint = CurrencyID === 'NTD' ? 0 : 2;
  587. $.each(CountFeeField, function (idx, item) {
  588. var OFF = OriginFeeField[idx];
  589. if ('TG,TE'.indexOf(parent.OrgID) > -1)
  590. RoundingPoint = 0;
  591. let prepay = 0;
  592. if ($(OFF).find('.prepay').val())
  593. prepay = roundDecimal(parseFloat($(OFF).find('.prepay').val().replaceAll(',', '')) * ExchangeRate, RoundingPoint);
  594. let subtotal = roundDecimal(parseFloat($(OFF).find('.subtotal').val().replaceAll(',', '')) * ExchangeRate, RoundingPoint);
  595. let taxtotal = roundDecimal(parseFloat($(OFF).find('.taxtotal').val().replaceAll(',', '')) * ExchangeRate, RoundingPoint);
  596. let boxtotal = (subtotal + taxtotal) - prepay;
  597. //let boxtotal = roundDecimal(parseFloat($(OFF).find('.boxtotal').val().replaceAll(',', '')) * ExchangeRate, RoundingPoint);
  598. $(item).find('.mprepay ').val(fMoney(prepay, RoundingPoint, ''));
  599. $(item).find('.msubtotal').val(fMoney(subtotal, RoundingPoint, ''));
  600. $(item).find('.mtaxtotal').val(fMoney(taxtotal, RoundingPoint, ''));
  601. $(item).find('.mboxtotal').val(fMoney(boxtotal, RoundingPoint, ''));
  602. });
  603. };
  604. w.fnCalcuBillsFee = function (oBillBox, OriginFeeField, CountFeeField, CurrencyID, ExchangeRate) {
  605. let RoundingPoint = CurrencyID === 'NTD' ? 0 : 2;
  606. if ('TG,TE'.indexOf(parent.OrgID) > -1) {
  607. RoundingPoint = 0;
  608. }
  609. let OFF = oBillBox.find(OriginFeeField);
  610. let iAdvance = roundDecimal(parseFloat($(OFF).find('.prepay').val().replaceAll(',', '')) * ExchangeRate, RoundingPoint);
  611. let iSubtotal = roundDecimal(parseFloat($(OFF).find('.subtotal').val().replaceAll(',', '')) * ExchangeRate, RoundingPoint);
  612. let iTaxtotal = roundDecimal(parseFloat($(OFF).find('.taxtotal').val().replaceAll(',', '')) * ExchangeRate, RoundingPoint);
  613. let iTaxSubtotal = iSubtotal + iTaxtotal;
  614. let iPaytotal = iTaxSubtotal - iAdvance;
  615. //let iTaxSubtotal = parseFloat($(OFF).find('.boxtotal').val().replaceAll(',', '')) * ExchangeRate;
  616. //let iPaytotal = parseFloat($(OFF).find('.paytotal').val().replaceAll(',', '')) * ExchangeRate;
  617. oBillBox.find(CountFeeField + ' .mprepay').val(fMoney(iAdvance, RoundingPoint, ''));
  618. oBillBox.find(CountFeeField + ' .msubtotal').val(fMoney(iSubtotal, RoundingPoint, ''));
  619. oBillBox.find(CountFeeField + ' .mtaxtotal').val(fMoney(iTaxtotal, RoundingPoint, ''));
  620. oBillBox.find(CountFeeField + ' .mboxtotal').val(fMoney(iTaxSubtotal, RoundingPoint, ''));
  621. oBillBox.find(CountFeeField + ' .mpaytotal').val(fMoney(iPaytotal, RoundingPoint, ''));
  622. };
  623. /**
  624. * 輸入預收事件
  625. */
  626. w.SetBillPrepayEvent = function SetBillPrepayEvent(oBillBox, bill) {
  627. oBillBox.find('[data-id="Advance"]').on('keyup blur', function (e) {
  628. //bill.AmountTaxSum紀錄外幣為主
  629. var ExchangeRate = (bill.ExchangeRate || 1.00);
  630. var iAdvance = parseFloat((this.value === '' ? '0' : this.value).replaceAll(',', ''));
  631. var iTotal = bill.AmountTaxSum;
  632. var iTotalReceivable = iTotal - iAdvance;
  633. oBillBox.find('.paytotal').val(fMoney(iTotalReceivable, 2, bill.Currency));
  634. bill.Advance = iAdvance;
  635. bill.TotalReceivable = iTotalReceivable;
  636. var iAdvance_main = iAdvance * ExchangeRate;
  637. var iTotal_main = iTotal * ExchangeRate;
  638. oBillBox.find('[data-id="mAdvance"]').val(fMoney(iAdvance_main, 0, 'NTD'));
  639. oBillBox.find('.mpaytotal').val(fMoney((iTotal_main - iAdvance_main), 0, 'NTD'));
  640. });
  641. oBillBox.find('[data-id="mAdvance"]').on('keyup blur', function (e) {
  642. var ExchangeRate = (bill.ExchangeRate || 1.00);
  643. var iAdvance = parseFloat((this.value === '' ? '0' : this.value).replaceAll(',', ''));
  644. var iTotal = parseFloat((bill.AmountTaxSum || 0) * ExchangeRate);
  645. oBillBox.find('.mpaytotal').val(fMoney((iTotal - iAdvance), 0, 'NTD'));
  646. var iAdvance_foreign = iAdvance / ExchangeRate;
  647. var iTotal_foreign = bill.AmountTaxSum;
  648. var TotalReceivable_foreign = iTotal_foreign - iAdvance_foreign;
  649. oBillBox.find('[data-id="Advance"]').val(fMoney(iAdvance_foreign, 2, bill.Currency));
  650. oBillBox.find('.paytotal').val(fMoney(TotalReceivable_foreign, 2, bill.Currency));
  651. bill.Advance = iAdvance_foreign;
  652. bill.TotalReceivable = TotalReceivable_foreign;
  653. });
  654. }
  655. /**
  656. * 檢查主幣別
  657. */
  658. w.fnCheckMainOrForeignCurrency = function (chosenCurrency) {
  659. var TWDAsAMainCurrency = 'TE,TG'.indexOf(parent.OrgID) > -1;
  660. var UsingMainCurrency = false;
  661. switch (TWDAsAMainCurrency) {
  662. case true:
  663. {
  664. if (chosenCurrency === 'NTD') {
  665. UsingMainCurrency = true;
  666. }
  667. }
  668. break;
  669. case false:
  670. {
  671. if (chosenCurrency === 'CNY' || chosenCurrency === 'RMB') {
  672. UsingMainCurrency = true;
  673. }
  674. }
  675. break;
  676. default:
  677. break;
  678. }
  679. return UsingMainCurrency;
  680. };
  681. })(jQuery, window, document);