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.

5977 lines
355 KiB

3 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sAction = getUrlParam('Action') || 'Add',
  5. sDataId = getUrlParam('ExportBillNO'),
  6. sFlag = getUrlParam('Flag'),
  7. sGoTab = getUrlParam('GoTab'),
  8. sBillNOGO = getUrlParam('BillNO'),
  9. sExhibitionNO = getUrlParam('ExhibitionNO'),
  10. sNewCustomers = getUrlParam('NewCustomers'),
  11. sCheckId = sDataId,
  12. sOrganizers = [],
  13. sSelectedOrganizers = [],
  14. MaxOrganizerCount = $(".Organizer").length + 1,//organizer count
  15. oGlobalItem = {},
  16. fnPageInit = function () {
  17. var FeeItemCurrency = "TE,TG".indexOf(parent.UserInfo.OrgID) > -1 ? 'NTD' : 'RMB';
  18. var oGrid = null,
  19. oForm = $('#form_main'),
  20. oValidator = null,
  21. sServiceCode = '',
  22. sDeptCode = '',
  23. sCustomersOptionsHtml = '',
  24. sCustomersNotAuditOptionsHtml = '',
  25. sCurrencyOptionsHtml = '',
  26. sAccountingCurrencyOptionsHtml = '',
  27. sTransportOptionsHtml = '',
  28. oAddItem = {},
  29. oCurSupplierData = {},
  30. oPrintMenu = {},
  31. oCurData = {},
  32. saGridData = [],
  33. saCustomers = [],
  34. saBatchArr = [],
  35. saPort = [],
  36. saCurrency = [],
  37. saFeeClass = [],
  38. saAccountingCurrency = [],
  39. saNewExhibition = {},
  40. saNewCustomers = [],
  41. nowResponsiblePerson = '',
  42. /**
  43. * 獲取資料
  44. * @return {Object} ajax物件
  45. */
  46. fnGet = function () {
  47. if (sDataId) {
  48. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  49. {
  50. Guid: sDataId
  51. },
  52. function (res) {
  53. if (res.RESULT) {
  54. var oRes = res.DATA.rel;
  55. $('#VoidReason').text(oRes.VoidReason);
  56. if (oRes.Organizer.indexOf("]") === -1)
  57. oRes.Organizer = '["' + oRes.Organizer + '"]';
  58. sOrganizers = $.parseJSON(oRes.Organizer);
  59. if (oRes.IsVoid === 'Y') {
  60. $('.voidreason').show();
  61. $('#Toolbar_Void').attr({ 'id': 'Toolbar_OpenVoid', 'data-i18n': 'common.Toolbar_OpenVoid' });
  62. }
  63. else {
  64. $('.voidreason').hide();
  65. $('#Toolbar_OpenVoid').attr({ 'id': 'Toolbar_Void', 'data-i18n': 'common.Toolbar_Void' });
  66. }
  67. transLang($('#Toolbar'));
  68. }
  69. });
  70. }
  71. else {
  72. oCurData.Quote = { guid: guid(), KeyName: 'Quote', AuditVal: '0', FeeItems: [] };
  73. oCurData.EstimatedCost = { guid: guid(), KeyName: 'EstimatedCost', AuditVal: '0', FeeItems: [] };
  74. oCurData.ActualCost = { guid: guid(), KeyName: 'ActualCost', AuditVal: '0', FeeItems: [] };
  75. oCurData.Bills = [];
  76. oCurData.ReturnBills = [];
  77. $('#AgentContactor').html(createOptions([]));
  78. fnSetPermissions();
  79. return $.Deferred().resolve().promise();
  80. }
  81. },
  82. /**
  83. * 獲取由名單過來的展覽資料
  84. * @return {Object} ajax物件
  85. */
  86. fnGetNewExhibition = function () {
  87. if (sAction === 'Add' && sExhibitionNO) {
  88. return g_api.ConnectLite('Exhibition_Qry', 'QueryOne',
  89. {
  90. Guid: sExhibitionNO
  91. },
  92. function (res) {
  93. if (res.RESULT) {
  94. saNewExhibition = res.DATA.rel;
  95. }
  96. });
  97. }
  98. else {
  99. return $.Deferred().resolve().promise();
  100. }
  101. },
  102. /**
  103. * 獲取由名單過來的參展廠商資料
  104. * @return {Object} ajax物件
  105. */
  106. fnGetNewCustomers = function () {
  107. if (sExhibitionNO && sNewCustomers) {
  108. return g_api.ConnectLite('Exhibition_Upd', 'GetNewCustomers',
  109. {
  110. SN: sExhibitionNO,
  111. Guid: sNewCustomers
  112. },
  113. function (res) {
  114. if (res.RESULT) {
  115. saNewCustomers = res.DATA.rel;
  116. }
  117. });
  118. }
  119. else {
  120. return $.Deferred().resolve().promise();
  121. }
  122. },
  123. /**
  124. * 新增或修改完之后重新查询资料
  125. */
  126. fnReSet = function () {
  127. fnGet().done(function (res) {
  128. var oRes = res.DATA.rel;
  129. $('#VoidReason').text(oRes.VoidReason);
  130. if (oRes.VoidReason) { $('.voidreason').show(); } else { $('.voidreason').hide(); }
  131. getPageVal(); //緩存頁面值,用於清除
  132. });
  133. },
  134. /**
  135. * 獲取貨物狀態
  136. * @param {Object} data 當前流程對象
  137. * @return {String} 當前流程名稱
  138. */
  139. fnGetFlowStatus = function (data) {
  140. var sFlowStatus = '';
  141. if (data.ReturnType !== '') {
  142. sFlowStatus = '退運';
  143. }
  144. else if (data.ClearanceData.ServiceBooth.Checked) {
  145. sFlowStatus = '送達攤位';
  146. }
  147. else if (data.ClearanceData.WaitingApproach.Checked) {
  148. sFlowStatus = '等待進場';
  149. }
  150. else if (data.ClearanceData.CargoRelease.Checked) {
  151. sFlowStatus = '貨物放行';
  152. }
  153. else if (data.ClearanceData.GoodsArrival.Checked) {
  154. sFlowStatus = '貨物抵港';
  155. }
  156. else if (data.ExportData.ExportRelease.Checked) {
  157. sFlowStatus = '出口放行';
  158. }
  159. else if (data.ExportData.CustomsDeclaration.Checked) {
  160. sFlowStatus = '報關作業';
  161. }
  162. else if (data.ExportData.Intowarehouse.Checked) {
  163. sFlowStatus = '貨物進倉';
  164. }
  165. else if (data.ExportData.ReceiveFile.Checked) {
  166. sFlowStatus = '已收文件';
  167. }
  168. return sFlowStatus;
  169. },
  170. /**
  171. * 新增資料
  172. * @param {String} flag 新增或儲存後新增
  173. * @return {Object} ajax物件
  174. */
  175. fnAdd = function (flag) {
  176. var data = getFormSerialize(oForm),
  177. fnGetAdd = function () {
  178. data.Exhibitors = JSON.stringify(saGridData);
  179. data.Organizer = JSON.stringify(sOrganizers);
  180. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  181. Params: { exportexhibition: data }
  182. }, function (res) {
  183. if (res.d > 0) {
  184. bRequestStorage = false;
  185. if (flag === 'add') {
  186. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&ExportBillNO=' + sDataId); // ╠message.Save_Success⇒新增成功╣
  187. }
  188. else {
  189. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  190. }
  191. }
  192. else {
  193. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  194. }
  195. }, function () {
  196. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  197. });
  198. };
  199. data = packParams(data);
  200. data.OrgID = parent.OrgID;
  201. data.IsVoid = 'N';
  202. data.DepartmentID = sDeptCode;
  203. data.Flow_Status = oCurData.Flow_Status || '';
  204. data.Quote = oCurData.Quote || {};
  205. data.Quote.AuditVal = oCurData.Quote.AuditVal || '0';
  206. data.Quote.FeeItems = oCurData.Quote.FeeItems || [];
  207. data.EstimatedCost = oCurData.EstimatedCost || {};
  208. data.EstimatedCost.AuditVal = oCurData.EstimatedCost.AuditVal || '0';
  209. data.EstimatedCost.FeeItems = oCurData.EstimatedCost.FeeItems || [];
  210. data.ActualCost = oCurData.ActualCost || {};
  211. data.ActualCost.AuditVal = oCurData.ActualCost.AuditVal || '0';
  212. data.ActualCost.FeeItems = oCurData.ActualCost.FeeItems || [];
  213. data.Bills = oCurData.Bills || [];
  214. data.ReturnBills = oCurData.ReturnBills || [];
  215. data.Quote = JSON.stringify(data.Quote);
  216. data.EstimatedCost = JSON.stringify(data.EstimatedCost);
  217. data.ActualCost = JSON.stringify(data.ActualCost);
  218. data.Bills = JSON.stringify(data.Bills);
  219. data.ReturnBills = JSON.stringify(data.ReturnBills);
  220. if (data.AgentContactor) {
  221. data.AgentContactorName = $('#AgentContactor option:selected').text();
  222. }
  223. else {
  224. data.AgentContactorName = '';
  225. }
  226. if (data.ExhibitionNO) {
  227. data.ExportBillName = $('#ExhibitionNO option:selected').text();
  228. }
  229. else {
  230. data.ExhibitionName = '';
  231. }
  232. if (!data.DocumentDeadline) delete data.DocumentDeadline;
  233. if (!data.ClosingDate) delete data.ClosingDate;
  234. if (!data.ETC) delete data.ETC;
  235. if (!data.ETD) delete data.ETD;
  236. if (!data.ETA) delete data.ETA;
  237. if (!data.ReminderAgentExecutionDate) delete data.ReminderAgentExecutionDate;
  238. if (!data.PreExhibitionDate) delete data.PreExhibitionDate;
  239. if (!data.ExitDate) delete data.ExitDate;
  240. if (!data.ExhibitionDateStart) delete data.ExhibitionDateStart;
  241. if (!data.ExhibitionDateEnd) delete data.ExhibitionDateEnd;
  242. data.ExportBillNO = sDataId = guid();
  243. return g_api.ConnectLite(Service.com, ComFn.GetSerial, {
  244. Type: 'C' + parent.UserInfo.OrgID + 'E',
  245. Flag: 'MinYear',
  246. Len: 3,
  247. Str: sServiceCode,
  248. AddType: sServiceCode,
  249. PlusType: ''
  250. }, function (res) {
  251. if (res.RESULT) {
  252. data.RefNumber = res.DATA.rel;
  253. var bRelease = true,
  254. sSuppliers = '',
  255. saPost = [];
  256. $.each(saGridData, function (idx, item) {
  257. item.RefSupplierNo = data.RefNumber + rndnum(3);
  258. if (!item.VoidContent) {
  259. if (bRelease && !item.VoidContent && (item.ExportData && !item.ExportData.ExportRelease.Checked) || !item.ExportData) {
  260. bRelease = false;
  261. }
  262. }
  263. sSuppliers += item.SupplierName + '|';
  264. });
  265. data.Suppliers = sSuppliers;
  266. data.Release = saGridData.length > 0 ? (bRelease ? 'Y' : 'N') : 'N';
  267. fnGetAdd();
  268. }
  269. else {
  270. showMsg(i18next.t("message.Save_Failed") + '<br>' + res.MSG, 'error');// ╠message.Save_Failed⇒新增失敗╣
  271. }
  272. }, function () {
  273. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  274. });
  275. },
  276. /**
  277. * 修改資料
  278. */
  279. fnUpd = function () {
  280. var data = getFormSerialize(oForm),
  281. bRelease = true,
  282. sSuppliers = '';
  283. data = packParams(data, 'upd');
  284. data.Organizer = JSON.stringify(sOrganizers);
  285. $.each(saGridData, function (idx, item) {
  286. if (!item.VoidContent) {
  287. if (bRelease && (item.ExportData && !item.ExportData.ExportRelease.Checked) || !item.ExportData) {
  288. bRelease = false;
  289. }
  290. }
  291. sSuppliers += item.SupplierName + '|';
  292. });
  293. data.Suppliers = sSuppliers;
  294. data.Release = saGridData.length > 0 ? (bRelease ? 'Y' : 'N') : 'N';
  295. data.IsVoid = oCurData.IsVoid;
  296. data.Flow_Status = oCurData.Flow_Status || '';
  297. data.Quote = oCurData.Quote || {};
  298. data.Quote.AuditVal = oCurData.Quote.AuditVal || '0';
  299. data.Quote.FeeItems = oCurData.Quote.FeeItems || [];
  300. data.EstimatedCost = oCurData.EstimatedCost || {};
  301. data.EstimatedCost.AuditVal = oCurData.EstimatedCost.AuditVal || '0';
  302. data.EstimatedCost.FeeItems = oCurData.EstimatedCost.FeeItems || [];
  303. data.ActualCost = oCurData.ActualCost || {};
  304. data.ActualCost.AuditVal = oCurData.ActualCost.AuditVal || '0';
  305. data.ActualCost.FeeItems = oCurData.ActualCost.FeeItems || [];
  306. data.Bills = oCurData.Bills || [];
  307. data.ReturnBills = oCurData.ReturnBills || [];
  308. data.Quote = JSON.stringify(data.Quote);
  309. data.EstimatedCost = JSON.stringify(data.EstimatedCost);
  310. data.ActualCost = JSON.stringify(data.ActualCost);
  311. data.Bills = JSON.stringify(data.Bills);
  312. data.ReturnBills = JSON.stringify(data.ReturnBills);
  313. data.Exhibitors = JSON.stringify(saGridData);
  314. if (data.AgentContactor) {
  315. data.AgentContactorName = $('#AgentContactor option:selected').text();
  316. }
  317. else {
  318. data.AgentContactorName = '';
  319. }
  320. if (data.ExhibitionNO) {
  321. data.ExportBillName = $('#ExhibitionNO option:selected').text();
  322. }
  323. else {
  324. data.ExhibitionName = '';
  325. }
  326. delete data.ExportBillNO;
  327. if (!data.DocumentDeadline) delete data.DocumentDeadline;
  328. if (!data.ClosingDate) delete data.ClosingDate;
  329. if (!data.ETC) delete data.ETC;
  330. if (!data.ETD) delete data.ETD;
  331. if (!data.ETA) delete data.ETA;
  332. if (!data.ReminderAgentExecutionDate) delete data.ReminderAgentExecutionDate;
  333. if (!data.PreExhibitionDate) delete data.PreExhibitionDate;
  334. if (!data.ExitDate) delete data.ExitDate;
  335. if (!data.ExhibitionDateStart) delete data.ExhibitionDateStart;
  336. if (!data.ExhibitionDateEnd) delete data.ExhibitionDateEnd;
  337. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  338. Params: {
  339. exportexhibition: {
  340. values: data,
  341. keys: { ExportBillNO: sDataId }
  342. }
  343. }
  344. }, function (res) {
  345. if (res.d > 0) {
  346. bRequestStorage = false;
  347. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  348. if (window.bLeavePage) {
  349. setTimeout(function () {
  350. pageLeave();
  351. }, 1000);
  352. }
  353. fnUpdateBillInfo(sProgramId, sDataId);
  354. oCurData.ResponsiblePerson = data.ResponsiblePerson;
  355. }
  356. else {
  357. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  358. nowResponsiblePerson = oCurData.ResponsiblePerson;
  359. }
  360. }, function () {
  361. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  362. nowResponsiblePerson = oCurData.ResponsiblePerson;
  363. });
  364. },
  365. /**
  366. * 資料刪除
  367. */
  368. fnDel = function () {
  369. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  370. Params: {
  371. exportexhibition: {
  372. ExportBillNO: sDataId
  373. }
  374. }
  375. }, function (res) {
  376. if (res.d > 0) {
  377. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  378. }
  379. else {
  380. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  381. }
  382. }, function () {
  383. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  384. });
  385. },
  386. /**
  387. * 資料作廢
  388. */
  389. fnVoid = function () {
  390. layer.open({
  391. type: 1,
  392. title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣
  393. shade: 0.75,
  394. maxmin: true, //开启最大化最小化按钮
  395. area: ['500px', '250px'],
  396. content: '<div class="pop-box">\
  397. <textarea name="VoidContent" id="VoidContent" style="min-width:300px;" class="form-control" rows="5" cols="20"></textarea>\
  398. </div>',
  399. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  400. success: function (layero, index) {
  401. },
  402. yes: function (index, layero) {
  403. var data = {
  404. IsVoid: 'Y',
  405. VoidReason: $('#VoidContent').val()
  406. };
  407. if (!$('#VoidContent').val()) {
  408. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  409. return false;
  410. }
  411. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  412. Params: {
  413. exportexhibition: {
  414. values: data,
  415. keys: { ExportBillNO: sDataId }
  416. }
  417. }
  418. }, function (res) {
  419. if (res.d > 0) {
  420. oCurData.IsVoid = 'Y';
  421. showMsg(i18next.t("message.Void_Success"), 'success'); // ╠message.Void_Success⇒作廢成功╣
  422. fnReSet();
  423. }
  424. else {
  425. showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  426. }
  427. });
  428. layer.close(index);
  429. }
  430. });
  431. },
  432. /**
  433. * 資料啟用
  434. */
  435. fnOpenVoid = function () {
  436. var data = {
  437. IsVoid: 'N',
  438. VoidReason: ''
  439. };
  440. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  441. Params: {
  442. exportexhibition: {
  443. values: data,
  444. keys: { ExportBillNO: sDataId }
  445. }
  446. }
  447. }, function (res) {
  448. if (res.d > 0) {
  449. oCurData.IsVoid = 'N';
  450. showMsg(i18next.t("message.OpenVoid_Success"), 'success'); // ╠message.OpenVoid_Success⇒啟用成功╣
  451. fnReSet();
  452. }
  453. else {
  454. showMsg(i18next.t("message.OpenVoid_Failed"), 'error'); // ╠message.OpenVoid_Failed⇒啟用失敗╣
  455. }
  456. }, function () {
  457. showMsg(i18next.t("message.OpenVoid_Failed"), 'error'); // ╠message.OpenVoid_Failed⇒啟用失敗╣
  458. });
  459. },
  460. /**
  461. * 打開要匯出的pop選擇匯出類別
  462. */
  463. fnOpenPopToExcel = function () {
  464. layer.open({
  465. type: 1,
  466. title: i18next.t('common.DownLoadDocuments'),// ╠common.DownLoadDocuments⇒下載文檔╣
  467. area: ['200px', '160px'],//寬度
  468. shade: 0.75,//遮罩
  469. shadeClose: true,
  470. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  471. content: '<div class="pop-box">\
  472. <button type="button" data-i18n="ExhibitionImport_Upd.BusinessTrackingSchedule" id="Export_BusinessTrackingScheduleOne" class="btn-custom green">業務追蹤進度表</button>\
  473. </div>',// common.BusinessTrackingSchedule請立即安排付款
  474. success: function (layero, idx) {
  475. $('.pop-box :button').click(function () {
  476. var sToExcelType = this.id;
  477. fnExcel({
  478. pageIndex: 1,
  479. pageSize: 100000,
  480. ToExcelType: sToExcelType
  481. }, idx);
  482. });
  483. transLang(layero);
  484. }
  485. });
  486. },
  487. /**
  488. * 匯入資料
  489. */
  490. fnImport = function () {
  491. var oConfig = {
  492. Get: fnGetPopData_ImportData,
  493. SearchFields: [
  494. { id: "Pop_RefNumber", type: 'text', i18nkey: 'ExhibitionExport_Upd.RefNumber' },
  495. { id: "Pop_ExportBillName", type: 'text', i18nkey: 'ExhibitionExport_Upd.ExportBillName' },
  496. { id: "Pop_ExportBillEName", type: 'text', i18nkey: 'ExhibitionExport_Upd.ExportBillEName' },
  497. { id: "Pop_Agent", type: 'text', i18nkey: 'ExhibitionExport_Upd.Agent' }
  498. ],
  499. Fields: [
  500. { name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 50 },
  501. { name: "RefNumber", title: 'ExhibitionExport_Upd.RefNumber', width: 100 },
  502. { name: "ExportBillName", title: 'ExhibitionExport_Upd.ExportBillName', width: 200 },
  503. { name: "ExportBillEName", title: 'ExhibitionExport_Upd.ExportBillEName', width: 200 },
  504. { name: "AgentName", title: 'ExhibitionExport_Upd.Agent', width: 200 }
  505. ],
  506. Callback: function (item) {
  507. var oData = {};
  508. oData.ResponsiblePerson = item.ResponsiblePerson;
  509. oData.ExhibitionNO = item.ExhibitionNO;
  510. oData.ExportBillName = item.ExportBillName;
  511. oData.ExportBillEName = item.ExportBillEName;
  512. oData.ExhibitionDateStart = item.ExhibitionDateStart;
  513. oData.ExhibitionDateEnd = item.ExhibitionDateEnd;
  514. oData.Organizer = item.Organizer;
  515. oData.Agent = item.Agent;
  516. oData.AgentContactor = item.AgentContactor;
  517. oData.AgentTelephone = item.AgentTelephone;
  518. oData.AgentEamil = item.AgentEamil;
  519. setFormVal(oForm, oData);
  520. if (oData.Agent) {
  521. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === oData.Agent; }).First(),
  522. saContactors = JSON.parse(oCur.Contactors || '[]');
  523. $('#AgentContactor').html(createOptions(saContactors, 'guid', 'FullName')).val(oData.AgentContactor);
  524. }
  525. else {
  526. $('#AgentContactor').html(createOptions([]));
  527. }
  528. $('#ExhibitionDateStart').val(newDate(oData.ExhibitionDateStart, 'date', true));
  529. $('#ExhibitionDateEnd').val(newDate(oData.ExhibitionDateEnd, 'date', true));
  530. }
  531. };
  532. oPenPops(oConfig);
  533. },
  534. /**
  535. * 獲取展覽名稱資料
  536. * @param {Object} args 查詢參數
  537. * @return {Object} ajax
  538. */
  539. fnGetPopData_ImportData = function (args) {
  540. args = args || {};
  541. args.sortField = args.sortField || 'RefNumber';
  542. args.sortOrder = args.sortOrder || 'desc';
  543. args.pageIndex = args.pageIndex || 1;
  544. args.pageSize = args.pageSize || 10;
  545. args.RefNumber = $('#Pop_RefNumber').val();
  546. args.ExportBillName = $('#Pop_ExportBillName').val();
  547. args.ExportBillEName = $('#Pop_ExportBillEName').val();
  548. args.Agent = $('#Pop_Agent').val();
  549. return g_api.ConnectLite(sQueryPrgId, 'GetExcel', args);
  550. },
  551. /**
  552. * 流程修改發送郵件
  553. * @param {String} itemname 第幾個流程
  554. * @param {Function} callback 回調函數
  555. * @return {Boolean} 是否停止
  556. */
  557. fnSendEmail = function (itemname, callback) {
  558. if (parent.SysSet.IsOpenMail !== 'Y') {
  559. layer.alert(i18next.t('message.NotOpenMail'), { icon: 0 }, function () {// ╠message.NotOpenMail⇒系統沒有開放郵件發送功能,請聯絡管理員!╣
  560. callback();
  561. });
  562. return false;
  563. }
  564. CallAjax(ComFn.W_Com, ComFn.SendMail, {
  565. Params: {
  566. FromOrgID: parent.OrgID,
  567. FromUserID: parent.UserID,
  568. EmailTo: [{
  569. ToUserID: $('#ResponsiblePerson').val(),
  570. Type: 'to'
  571. }],
  572. MailTempId: 'FlowChange',
  573. MailData: {
  574. RefNumber: $('#RefNumber').val(),
  575. ExhibitionType: '出口',
  576. DataDources: '出口管理',
  577. ChangeItem: itemname,
  578. SupplierName: oCurSupplierData.SupplierName,
  579. ModifyUser: parent.UserInfo.MemberName,
  580. ModifyDate: newDate(null, 'date')
  581. }
  582. }
  583. }, function (res) {
  584. if (res.d === '1') {
  585. callback();
  586. showMsg(i18next.t("message.SendEmail_Success"), 'success'); // ╠message.SendEmail_Success⇒郵件寄送成功╣
  587. }
  588. else {
  589. showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
  590. }
  591. }, function () {
  592. showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
  593. });
  594. },
  595. /**
  596. * 發送Tracking number給客戶格式
  597. * @param {Object} data 單筆廠商資料
  598. * @return {Boolean} 是否停止
  599. */
  600. fnSendTrackingNumberEmail = function (data) {
  601. var sMsg = '';
  602. if (parent.SysSet.IsOpenMail !== 'Y') {
  603. showMsg(i18next.t("message.NotOpenMail"));// ╠message.NotOpenMail⇒系統沒有開放郵件發送功能,請聯絡管理員!╣
  604. return false;
  605. }
  606. if (!data.Email) {
  607. sMsg += i18next.t("ExhibitionImport_Upd.SupplierEamil_required") + '<br/>'; // ╠ExhibitionImport_Upd.SupplierEamil_required⇒請輸入付款人╣
  608. }
  609. if (!$('#ShipmentPort').val()) {
  610. sMsg += i18next.t("common.ShipmentPort_required") + '<br/>'; // ╠common.ShipmentPort_required⇒請輸入起運地╣
  611. }
  612. if (!$('#Destination').val()) {
  613. sMsg += i18next.t("common.DestinationPort_required") + '<br/>'; // ╠common.DestinationPort_required⇒請輸入目的地╣
  614. }
  615. if (!(data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? data.ExportData.Intowarehouse.Number : '')) {
  616. sMsg += i18next.t("message.Number_required") + '<br/>'; // ╠message.Number_required⇒請輸入件數╣
  617. }
  618. if (!(data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? data.ExportData.Intowarehouse.Unit : '')) {
  619. sMsg += i18next.t("message.Unit_required"); // ╠message.Unit_required⇒ 請輸入(件數)單位╣
  620. }
  621. if (sMsg) {
  622. showMsg(sMsg);
  623. return false;
  624. }
  625. var toSendMail = function (flag) {
  626. CallAjax(ComFn.W_Com, ComFn.SendMail, {
  627. Params: {
  628. FromOrgID: parent.OrgID,
  629. FromUserName: parent.SysSet.FromName || '系統郵件',
  630. EmailTo: [{
  631. ToUserName: data.SupplierName,
  632. ToEmail: data.Email,
  633. Type: 'to'
  634. }],
  635. MailTempId: 'TrackingNumberNotice',
  636. MailData: {
  637. RefNumber: data.RefSupplierNo,
  638. BillLadNOType: 'none',
  639. ExhibitionName: oCurData.Exhibitioname_TW || '',
  640. ExhibitionEName: oCurData.Exhibitioname_EN || '',
  641. Shipment: $('#ShipmentPortCode').val(),
  642. Destination: $('#DestinationCode').val(),
  643. Number: data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? (data.ExportData.Intowarehouse.Number + ' ' + data.ExportData.Intowarehouse.Unit) : ''
  644. }
  645. }
  646. }, function (res) {
  647. if (res.d === '1') {
  648. showMsg(i18next.t("message.SendEmail_Success"), 'success'); // ╠message.SendEmail_Success⇒郵件寄送成功╣
  649. if (flag) {
  650. var sIsSendMail = oCurData.IsSendMail + ',' + data.guid;
  651. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  652. Params: {
  653. exportexhibition: {
  654. values: { IsSendMail: sIsSendMail },
  655. keys: { ExportBillNO: sDataId }
  656. }
  657. }
  658. }, function (res1) {
  659. if (res1.d > 0) {
  660. oCurData.IsSendMail = sIsSendMail;
  661. $('.' + data.guid).removeClass('a-url').addClass('a-mailurl');
  662. }
  663. });
  664. }
  665. }
  666. else {
  667. showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
  668. }
  669. }, function () {
  670. showMsg(i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
  671. });
  672. };
  673. if (isEmail(data.Email)) {
  674. if ((oCurData.IsSendMail || '').indexOf(data.guid) === -1) {
  675. toSendMail(true);
  676. }
  677. else {
  678. // ╠message.IsSendTrackingNumberEmail⇒已寄送过,是否再次寄送?╣ ╠common.Tips⇒提示╣
  679. layer.confirm(i18next.t('message.IsSendTrackingNumberEmail'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  680. toSendMail(false);
  681. layer.close(index);
  682. });
  683. }
  684. }
  685. else {
  686. showMsg(i18next.t("message.IncorrectEmail"), 'error'); // ╠message.IncorrectEmail⇒郵箱格式不正確╣
  687. }
  688. },
  689. /**
  690. * 批次發送Tracking number給客戶格式
  691. */
  692. fnBatchMail = function () {
  693. var toSendMail = function (data, name) {
  694. return CallAjax(ComFn.W_Com, ComFn.SendMail, {
  695. Params: {
  696. FromOrgID: parent.OrgID,
  697. FromUserName: parent.SysSet.FromName || '系統郵件',
  698. EmailTo: [{
  699. ToUserName: data.SupplierName,
  700. ToEmail: data.Email,
  701. Type: 'to'
  702. }],
  703. MailTempId: 'TrackingNumberNotice',
  704. MailData: {
  705. RefNumber: data.RefSupplierNo,
  706. BillLadNOType: 'none',
  707. ExhibitionName: oCurData.Exhibitioname_TW || '',
  708. ExhibitionEName: oCurData.Exhibitioname_EN || '',
  709. Shipment: $('#ShipmentPortCode').val(),
  710. Destination: $('#DestinationCode').val(),
  711. Number: data.ExportData !== undefined && data.ExportData.Intowarehouse !== undefined ? (data.ExportData.Intowarehouse.Number + ' ' + data.ExportData.Intowarehouse.Unit) : ''
  712. }
  713. }
  714. }, function (res) {
  715. if (res.d === '1') {
  716. $('.' + data.guid).removeClass('a-url').addClass('a-mailurl');
  717. showMsg(name + i18next.t("message.SendEmail_Success"), 'success'); // ╠message.SendEmail_Success⇒郵件寄送成功╣
  718. }
  719. else {
  720. showMsg(name + i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
  721. }
  722. }, function () {
  723. showMsg(name + i18next.t("message.SendEmail_Failed"), 'error'); // ╠message.SendEmail_Failed⇒郵件寄送失敗╣
  724. });
  725. },
  726. fnGetData = function () {
  727. var d = $.Deferred(),
  728. saList = [],
  729. iIndex = 1,
  730. sName = $('#Pop_SupplierName').val(),
  731. sEName = $('#Pop_SupplierEName').val();
  732. $.each(saGridData, function (idx, item) {
  733. if ((((item.SupplierName || '').indexOf(sName) > -1 || sName === '')
  734. && ((item.SupplierEName || '').indexOf(sEName) > -1 || sEName === ''))) {
  735. saList.push({
  736. RowIndex: iIndex,
  737. guid: item.guid,
  738. SupplierID: item.SupplierID,
  739. CustomerNO: item.CustomerNO,
  740. UniCode: item.UniCode,
  741. Email: item.Email,
  742. RefSupplierNo: item.RefSupplierNo,
  743. ExportData: item.ExportData,
  744. SupplierName: item.SupplierName || '',
  745. SupplierEName: item.SupplierEName || ''
  746. });
  747. iIndex++;
  748. }
  749. });
  750. d.resolve({
  751. data: saList,
  752. itemsCount: saList.length
  753. });
  754. return d.promise();
  755. },
  756. oConfig = {
  757. Id: 'PopIsBatch',
  758. Title: i18next.t('common.SelectBatchList'),// ╠common.SelectBatchList⇒請選擇要批次操作的資料╣
  759. PageSize: 10000,
  760. Get: fnGetData,
  761. SearchFields: [
  762. { id: "Pop_SupplierName", type: 'text', i18nkey: 'common.SupplierCName' },
  763. { id: "Pop_SupplierEName", type: 'text', i18nkey: 'common.SupplierEName' }
  764. ],
  765. Fields: [
  766. { name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 50 },// ╠common.RowNumber⇒項次╣
  767. { name: "CustomerNO", title: 'Customers_Upd.CustomerNO', width: 80 },
  768. { name: "SupplierName", title: 'common.SupplierCName', width: 150 },
  769. { name: "SupplierEName", title: 'common.SupplierEName', width: 150 }
  770. ],
  771. Callback: function (items) {
  772. var sMsg = '',
  773. bEmail = true,
  774. oPost = [],
  775. sIsSendMail = '';
  776. $.each(items, function (idx, item) {
  777. if (!item.Email || !isEmail(item.Email)) {
  778. sMsg = item.SupplierName === '' ? item.SupplierEName : item.SupplierName;
  779. bEmail = false;
  780. return false;
  781. }
  782. });
  783. if (!bEmail) {
  784. showMsg(sMsg + i18next.t("message.IncorrectEmail"), 'error'); // ╠message.IncorrectEmail⇒郵箱格式不正確╣
  785. return false;
  786. }
  787. $.each(items, function (idx, item) {
  788. var sSupplierName = item.SupplierName === '' ? item.SupplierEName : item.SupplierName;
  789. if ((oCurData.IsSendMail || '').indexOf(item.guid) === -1) {
  790. sIsSendMail += item.guid + ',';
  791. oPost.push(toSendMail(item, sSupplierName));
  792. }
  793. else {
  794. toSendMail(item, sSupplierName);
  795. }
  796. });
  797. $.whenArray(oPost).done(function () {
  798. sIsSendMail = oCurData.IsSendMail + ',' + sIsSendMail;
  799. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  800. Params: {
  801. exportexhibition: {
  802. values: { IsSendMail: sIsSendMail },
  803. keys: { ExportBillNO: sDataId }
  804. }
  805. }
  806. }, function (res) {
  807. if (res.d > 0) {
  808. oCurData.IsSendMail = sIsSendMail;
  809. }
  810. });
  811. });
  812. }
  813. };
  814. oPenPopm(oConfig);
  815. },
  816. /**
  817. * 批次匯入廠商列表
  818. */
  819. fnBatchImport = function () {
  820. var fnGetData = function () {
  821. var sId = $('#Pop_ExhibitionName').val(),
  822. d = $.Deferred();
  823. if (!sId) {
  824. return;
  825. }
  826. g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  827. {
  828. Guid: sId
  829. },
  830. function (res) {
  831. if (res.RESULT) {
  832. var oRes = res.DATA.rel;
  833. if (oRes.ExportBillNO) {
  834. var saExhibitors = $.parseJSON(oRes.Exhibitors),
  835. saNewExhibitors = [];
  836. $.each(saExhibitors, function (idx, supplier) {
  837. var oNewExhibitor = {},
  838. sRefSupplierNo = $('#RefNumber').val() + rndnum(3);
  839. oNewExhibitor.RowIndex = idx + 1;
  840. oNewExhibitor.guid = guid();
  841. oNewExhibitor.SupplierID = supplier.SupplierID;
  842. oNewExhibitor.CustomerNO = supplier.CustomerNO || '';
  843. oNewExhibitor.UniCode = supplier.UniCode;
  844. oNewExhibitor.SupplierName = supplier.SupplierName;
  845. oNewExhibitor.SupplierEName = supplier.SupplierEName || '';
  846. oNewExhibitor.RefSupplierNo = sRefSupplierNo;
  847. oNewExhibitor.Contactor = supplier.Contactor || '';
  848. oNewExhibitor.Telephone = supplier.Telephone || '';
  849. oNewExhibitor.Email = supplier.Email || '';
  850. oNewExhibitor.ContactorName = supplier.ContactorName || '';
  851. oNewExhibitor.CreateUser = parent.UserID;
  852. oNewExhibitor.CreateDate = new Date().formate("yyyy/MM/dd HH:mm:ss");
  853. saNewExhibitors.push(oNewExhibitor);
  854. });
  855. d.resolve({
  856. data: saNewExhibitors,
  857. itemsCount: saNewExhibitors.length
  858. });
  859. }
  860. }
  861. });
  862. return d.promise();
  863. },
  864. oConfig = {
  865. Id: 'PopIsBatch',
  866. Title: i18next.t('ExhibitionExport_Upd.SupplierBatchList'),// ╠ExhibitionExport_Upd.SupplierBatchList⇒批次匯入廠商╣
  867. Width: '1000px',
  868. PageSize: 10000,
  869. Get: fnGetData,
  870. SearchFields: [
  871. { id: "Pop_ExhibitionName", type: 'select', i18nkey: 'ExhibitionExport_Upd.ExportBillName' }
  872. ],
  873. Fields: [
  874. { name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 50 },
  875. { name: "SupplierName", title: 'common.SupplierName', width: 200 },
  876. { name: "SupplierEName", title: 'common.SupplierEName', width: 200 },
  877. { name: "ContactorName", title: 'common.Contactor', width: 100 },
  878. { name: "Telephone", title: 'common.Telephone', width: 100 },
  879. { name: "Email", title: 'common.Email', width: 150 }
  880. ],
  881. Callback: function (items) {
  882. saGridData = clone(items);
  883. oGrid.loadData();
  884. }
  885. };
  886. CallAjax(ComFn.W_Com, ComFn.GetList, {
  887. Type: '', Params: {
  888. exportexhibition: {
  889. IsVoid: 'N',
  890. OrgID: parent.OrgID
  891. }
  892. }
  893. }, function (res) {
  894. var saList = $.parseJSON(res.d);
  895. oConfig.SearchFields[0].html = createOptions(saList, 'ExportBillNO', 'ExportBillName');
  896. oConfig.ContentPlush = '<style>.select2-container--open {z-index: 1000000001; }</style>';
  897. oConfig.PopSuccessCallback = function (layero) {
  898. setTimeout(function () {
  899. $('#Pop_ExhibitionName').select2({ width: '240px' });
  900. }, 100);
  901. };
  902. oPenPopm(oConfig);
  903. });
  904. },
  905. /**
  906. * 設定完成按鈕
  907. * @param {Object} flow 父層dom對象
  908. * @param {Boolean} bcomplete 是否完成
  909. */
  910. setSuccessBtn = function (flow, bcomplete) {
  911. var iCheckBox = flow.find(':input[type=checkbox]').length,
  912. iChecked = flow.find(':input[type=checkbox]').not("input:checked").length;
  913. if (iChecked === 0 && (iCheckBox !== iChecked || !bcomplete)) {
  914. flow.find(':input.complete').removeAttr('disabled');
  915. }
  916. else {
  917. flow.find(':input.complete').attr('disabled', true);
  918. }
  919. },
  920. /**
  921. * 設定完成按鈕
  922. * @param {Object}that 父層dom對象
  923. */
  924. setTime = function (that) {
  925. if (that.checked) {
  926. $(that).parent().next().find('.date-picker').val(newDate(null, true));
  927. }
  928. else {
  929. $(that).parent().next().find('.date-picker').val('');
  930. }
  931. },
  932. /**
  933. * 設定流程頁簽
  934. * @param {Object}form 表單
  935. * @param {Object} oData 資料json
  936. */
  937. setFlowBox = function (form, oData) {
  938. if (oData.ExportData) {
  939. if (oData.ExportData.complete) {
  940. form.find('#ExportData').find('[name]').attr('disabled', true);
  941. form.find('#ExportData').find(':input.complete').attr('disabled', true);
  942. }
  943. else {
  944. setSuccessBtn(form.find('#ExportData'), false);
  945. }
  946. if (oData.ReturnType === 'H') {
  947. form.find('#ReImport').show();
  948. form.find('.addreturns').attr('disabled', true);
  949. }
  950. else if (oData.ReturnType === 'T') {
  951. form.find('#TranserThird').show();
  952. form.find('.addreturns').attr('disabled', true);
  953. }
  954. else if (oData.ReturnType === 'P') {
  955. form.find('#PartThirdAndReImport').show();
  956. form.find('.addreturns').attr('disabled', true);
  957. }
  958. form.find('#ExportData').find(':input.undo').removeAttr('disabled').click(function () {
  959. var fnCallBack = function () {
  960. //form.find('#ExportData').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
  961. form.find('#ExportData').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  962. form.find('#ExportData').find(':input.undo').attr('disabled', true);
  963. form.find('#ExportData').find(':input[type=hidden]').val('');
  964. };
  965. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  966. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  967. fnSendEmail(i18next.t("ExhibitionExport_Upd.ExportData"), fnCallBack);
  968. layer.close(index);
  969. }, function () {
  970. fnCallBack();
  971. });
  972. });
  973. } else {
  974. setSuccessBtn(form.find('#ExportData'));
  975. }
  976. if (oData.ReImport) {
  977. if (oData.ReImport.complete) {
  978. form.find('#ReImport').find('[name]').attr('disabled', true);
  979. form.find('#ReImport').find(':input.complete').attr('disabled', true);
  980. }
  981. else {
  982. setSuccessBtn(form.find('#ReImport'), false);
  983. }
  984. form.find('#ReImport').find(':input.undo').removeAttr('disabled').click(function () {
  985. var fnCallBack = function () {
  986. //form.find('#ReImport').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
  987. form.find('#ReImport').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  988. form.find('#ReImport').find(':input.undo').attr('disabled', true);
  989. form.find('#ReImport').find(':input[type=hidden]').val('');
  990. };
  991. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  992. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  993. fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
  994. layer.close(index);
  995. }, function () {
  996. fnCallBack();
  997. });
  998. });
  999. } else {
  1000. setSuccessBtn(form.find('#ReImport'));
  1001. }
  1002. if (oData.TranserThird) {
  1003. if (oData.TranserThird.complete) {
  1004. form.find('#TranserThird').find('[name]').attr('disabled', true);
  1005. form.find('#TranserThird').find(':input.complete').attr('disabled', true);
  1006. }
  1007. else {
  1008. setSuccessBtn(form.find('#TranserThird'), false);
  1009. }
  1010. if (oData.LastReturnType === 'F') {
  1011. form.find('#TransferFour').show();
  1012. form.find('#TranserThird').find('.addnextreturn').attr('disabled', true);
  1013. }
  1014. else if (oData.LastReturnType === 'H') {
  1015. form.find('#ReImportFour').show();
  1016. form.find('.addnextreturn').attr('disabled', true);
  1017. }
  1018. form.find('#TranserThird').find(':input.undo').removeAttr('disabled').click(function () {
  1019. var fnCallBack = function () {
  1020. //form.find('#TranserThird').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
  1021. form.find('#TranserThird').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1022. form.find('#TranserThird').find(':input.undo').attr('disabled', true);
  1023. form.find('#TranserThird').find(':input[type=hidden]').val('');
  1024. };
  1025. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1026. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1027. fnSendEmail(i18next.t("ExhibitionExport_Upd.TranserThird"), fnCallBack);
  1028. layer.close(index);
  1029. }, function () {
  1030. fnCallBack();
  1031. });
  1032. });
  1033. if (oData.TransferFour) {
  1034. if (oData.TransferFour.complete) {
  1035. form.find('#TransferFour').find('[name]').attr('disabled', true);
  1036. form.find('#TransferFour').find(':input.complete').attr('disabled', true);
  1037. }
  1038. else {
  1039. setSuccessBtn(form.find('#TransferFour'), false);
  1040. }
  1041. if (oData.ReturnType_4 === 'F') {
  1042. form.find('#TransferFive').show();
  1043. form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
  1044. }
  1045. else if (oData.ReturnType_4 === 'H') {
  1046. form.find('#ReImportFive').show();
  1047. form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
  1048. }
  1049. form.find('#TransferFour').find(':input.undo').removeAttr('disabled').click(function () {
  1050. var fnCallBack = function () {
  1051. //form.find('#TransferFour').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
  1052. form.find('#TransferFour').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1053. form.find('#TransferFour').find(':input.undo').attr('disabled', true);
  1054. form.find('#TransferFour').find(':input[type=hidden]').val('');
  1055. };
  1056. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1057. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1058. fnSendEmail(i18next.t("ExhibitionExport_Upd.TransferFourPlace"), fnCallBack);
  1059. layer.close(index);
  1060. }, function () {
  1061. fnCallBack();
  1062. });
  1063. });
  1064. } else {
  1065. setSuccessBtn(form.find('#TransferFour'));
  1066. }
  1067. if (oData.ReImportFour) {
  1068. if (oData.ReImportFour.complete) {
  1069. form.find('#ReImportFour').find('[name]').attr('disabled', true);
  1070. form.find('#ReImportFour').find(':input.complete').attr('disabled', true);
  1071. }
  1072. else {
  1073. setSuccessBtn(form.find('#ReImportFour'), false);
  1074. }
  1075. form.find('#ReImportFour').find(':input.undo').removeAttr('disabled').click(function () {
  1076. var fnCallBack = function () {
  1077. //form.find('#ReImportFour').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
  1078. form.find('#ReImportFour').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1079. form.find('#ReImportFour').find(':input.undo').attr('disabled', true);
  1080. form.find('#ReImportFour').find(':input[type=hidden]').val('');
  1081. };
  1082. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1083. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1084. fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
  1085. layer.close(index);
  1086. }, function () {
  1087. fnCallBack();
  1088. });
  1089. });
  1090. } else {
  1091. setSuccessBtn(form.find('#ReImportFour'));
  1092. }
  1093. if (oData.TransferFive) {
  1094. if (oData.TransferFive.complete) {
  1095. form.find('#TransferFive').find('[name]').attr('disabled', true);
  1096. form.find('#TransferFive').find(':input.complete').attr('disabled', true);
  1097. }
  1098. else {
  1099. setSuccessBtn(form.find('#TransferFive'), false);
  1100. }
  1101. if (oData.ReturnType_5 === 'F') {
  1102. form.find('#TransferSix').show();
  1103. form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
  1104. }
  1105. else if (oData.ReturnType_5 === 'H') {
  1106. form.find('#ReImportSix').show();
  1107. form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
  1108. }
  1109. form.find('#TransferFive').find(':input.undo').removeAttr('disabled').click(function () {
  1110. var fnCallBack = function () {
  1111. form.find('#TransferFive').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1112. form.find('#TransferFive').find(':input.undo').attr('disabled', true);
  1113. form.find('#TransferFive').find(':input[type=hidden]').val('');
  1114. };
  1115. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1116. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1117. fnSendEmail(i18next.t("ExhibitionExport_Upd.TransferFivePlace"), fnCallBack);
  1118. layer.close(index);
  1119. }, function () {
  1120. fnCallBack();
  1121. });
  1122. });
  1123. } else {
  1124. setSuccessBtn(form.find('#TransferFive'));
  1125. }
  1126. if (oData.ReImportFive) {
  1127. if (oData.ReImportFive.complete) {
  1128. form.find('#ReImportFive').find('[name]').attr('disabled', true);
  1129. form.find('#ReImportFive').find(':input.complete').attr('disabled', true);
  1130. }
  1131. else {
  1132. setSuccessBtn(form.find('#ReImportFive'), false);
  1133. }
  1134. form.find('#ReImportFive').find(':input.undo').removeAttr('disabled').click(function () {
  1135. var fnCallBack = function () {
  1136. form.find('#ReImportFive').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1137. form.find('#ReImportFive').find(':input.undo').attr('disabled', true);
  1138. form.find('#ReImportFive').find(':input[type=hidden]').val('');
  1139. };
  1140. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1141. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1142. fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
  1143. layer.close(index);
  1144. }, function () {
  1145. fnCallBack();
  1146. });
  1147. });
  1148. } else {
  1149. setSuccessBtn(form.find('#ReImportFive'));
  1150. }
  1151. if (oData.TransferSix) {
  1152. if (oData.TransferSix.complete) {
  1153. form.find('#TransferSix').find('[name]').attr('disabled', true);
  1154. form.find('#TransferSix').find(':input.complete').attr('disabled', true);
  1155. }
  1156. else {
  1157. setSuccessBtn(form.find('#TransferSix'), false);
  1158. }
  1159. form.find('#TransferSix').find(':input.undo').removeAttr('disabled').click(function () {
  1160. var fnCallBack = function () {
  1161. form.find('#TransferSix').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1162. form.find('#TransferSix').find(':input.undo').attr('disabled', true);
  1163. form.find('#TransferSix').find(':input[type=hidden]').val('');
  1164. };
  1165. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1166. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1167. fnSendEmail(i18next.t("ExhibitionExport_Upd.TransferSixPlace"), fnCallBack);
  1168. layer.close(index);
  1169. }, function () {
  1170. fnCallBack();
  1171. });
  1172. });
  1173. } else {
  1174. setSuccessBtn(form.find('#TransferSix'));
  1175. }
  1176. if (oData.ReImportSix) {
  1177. if (oData.ReImportSix.complete) {
  1178. form.find('#ReImportSix').find('[name]').attr('disabled', true);
  1179. form.find('#ReImportSix').find(':input.complete').attr('disabled', true);
  1180. }
  1181. else {
  1182. setSuccessBtn(form.find('#ReImportSix'), false);
  1183. }
  1184. form.find('#ReImportSix').find(':input.undo').removeAttr('disabled').click(function () {
  1185. var fnCallBack = function () {
  1186. form.find('#ReImportSix').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1187. form.find('#ReImportSix').find(':input.undo').attr('disabled', true);
  1188. form.find('#ReImportSix').find(':input[type=hidden]').val('');
  1189. };
  1190. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1191. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1192. fnSendEmail(i18next.t("ExhibitionExport_Upd.ReImport"), fnCallBack);
  1193. layer.close(index);
  1194. }, function () {
  1195. fnCallBack();
  1196. });
  1197. });
  1198. } else {
  1199. setSuccessBtn(form.find('#ReImportSix'));
  1200. }
  1201. } else {
  1202. setSuccessBtn(form.find('#TranserThird'));
  1203. }
  1204. if (oData.PartThird) {
  1205. if (oData.PartThird.complete) {
  1206. form.find('#PartThird').find('[name]').attr('disabled', true);
  1207. form.find('#PartThird').find(':input.complete').attr('disabled', true);
  1208. }
  1209. else {
  1210. setSuccessBtn(form.find('#PartThird'), false);
  1211. }
  1212. form.find('#PartThird').find(':input.undo').removeAttr('disabled').click(function () {
  1213. var fnCallBack = function () {
  1214. //form.find('#PartThird').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
  1215. form.find('#PartThird').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1216. form.find('#PartThird').find(':input.undo').attr('disabled', true);
  1217. form.find('#PartThird').find(':input[type=hidden]').val('');
  1218. };
  1219. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1220. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1221. fnSendEmail(i18next.t("ExhibitionExport_Upd.ReturnedHomeAndThirdPlace"), fnCallBack);// ╠ExhibitionExport_Upd.ReturnedHomeAndThirdPlace⇒部份轉運其他地區;部份退運回台╣
  1222. layer.close(index);
  1223. }, function () {
  1224. fnCallBack();
  1225. });
  1226. });
  1227. } else {
  1228. setSuccessBtn(form.find('#PartThird'));
  1229. }
  1230. if (oData.PartReImport) {
  1231. if (oData.PartReImport.complete) {
  1232. form.find('#PartReImport').find('[name]').attr('disabled', true);
  1233. form.find('#PartReImport').find(':input.complete').attr('disabled', true);
  1234. }
  1235. else {
  1236. setSuccessBtn(form.find('#PartReImport'), false);
  1237. }
  1238. form.find('#PartReImport').find(':input.undo').removeAttr('disabled').click(function () {
  1239. var fnCallBack = function () {
  1240. //form.find('#PartReImport').find(':input[type=checkbox]:last').parents('.form-group').find(':input').removeAttr('disabled');
  1241. form.find('#PartReImport').find(':input[type=checkbox],:input[type=text],.complete,select').removeAttr('disabled');
  1242. form.find('#PartReImport').find(':input.undo').attr('disabled', true);
  1243. form.find('#PartReImport').find(':input[type=hidden]').val('');
  1244. };
  1245. // ╠message.IsSendEmailToCharGer⇒是否要寄送郵件通知負責業務人員?╣ ╠common.Tips⇒提示╣
  1246. layer.confirm(i18next.t('message.IsSendEmailToCharGer'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  1247. fnSendEmail(i18next.t("ExhibitionExport_Upd.ReturnedHomeAndThirdPlace"), fnCallBack);// ╠ExhibitionExport_Upd.ReturnedHomeAndThirdPlace⇒部份轉運其他地區;部份退運回台╣
  1248. layer.close(index);
  1249. }, function () {
  1250. fnCallBack();
  1251. });
  1252. });
  1253. } else {
  1254. setSuccessBtn(form.find('#PartReImport'));
  1255. }
  1256. form.find('.complete').click(function () {
  1257. var oBtn = this,
  1258. sId = $(oBtn).parents('.flow').attr('id'),
  1259. data = getFormSerialize(form);
  1260. data[sId].complete = 'Y';
  1261. form.find('#' + sId + '_complete').val('Y');
  1262. form.find(oBtn).attr('disabled', true);
  1263. form.find('#' + sId).find('[name]').attr('disabled', true);
  1264. if ($(oBtn).parents('.flow').next('.flow').length > 0) {
  1265. $(oBtn).parents('.flow').find('.addreturns,.addnextreturn').removeAttr('disabled');
  1266. }
  1267. });
  1268. form.find('.addreturns').click(function () {
  1269. layer.open({
  1270. type: 1,
  1271. title: i18next.t('common.ReturnType'),// ╠common.ReturnType⇒請選擇運送類型╣
  1272. area: ['500px', '120px'],//寬度
  1273. shade: 0.75,//遮罩
  1274. shadeClose: true,// ╠ExhibitionExport_Upd.ReturnedHome⇒退運回國╣ ╠ExhibitionExport_Upd.TransferThirdPlace⇒出貨至第三地╣ ╠ExhibitionExport_Upd.ReturnedHomeAndThirdPlace⇒部分運至第三地部分退運回國╣
  1275. content: '<div class="pop-box">\
  1276. <button type="button" data-i18n="ExhibitionExport_Upd.ReturnedHome" id="btn_ReturnedHome" class="btn-custom green">退運回國</button>\
  1277. <button type="button" data-i18n="ExhibitionExport_Upd.TransferThirdPlace" id="btn_TransferThirdPlace" class="btn-custom green">出貨至第三地</button>\
  1278. <button type="button" data-i18n="ExhibitionExport_Upd.ReturnedHomeAndThirdPlace" id="btn_ReturnedHomeAndThirdPlace" class="btn-custom green">部分運至第三地部分退運回國</button>\
  1279. </div>',
  1280. success: function (layero, idx) {
  1281. layero.find('#btn_ReturnedHome').click(function () {
  1282. form.find('#ReImport').show();
  1283. form.find('#TranserThird,#PartThirdAndReImport,#TransferFour,#ReImportFour').hide();
  1284. form.find('.addreturns').attr('disabled', true);
  1285. form.find('#ReturnType').val('H');
  1286. layer.close(idx);
  1287. });
  1288. layero.find('#btn_TransferThirdPlace').click(function () {
  1289. form.find('#TranserThird').show();
  1290. form.find('#ReImport,#PartThirdAndReImport,#TransferFour,#ReImportFour').hide();
  1291. form.find('.addreturns').attr('disabled', true);
  1292. form.find('#ReturnType').val('T');
  1293. layer.close(idx);
  1294. });
  1295. layero.find('#btn_ReturnedHomeAndThirdPlace').click(function () {
  1296. form.find('#PartThirdAndReImport').show();
  1297. form.find('#ReImport,#TranserThird,#TransferFour,#ReImportFour').hide();
  1298. form.find('.addreturns').attr('disabled', true);
  1299. form.find('#ReturnType').val('P');
  1300. layer.close(idx);
  1301. });
  1302. transLang(layero);
  1303. }
  1304. });
  1305. });
  1306. form.find('.addnextreturn').click(function () {
  1307. var iIndex = $(this).attr('data-index');
  1308. layer.open({
  1309. type: 1,
  1310. title: i18next.t('common.AddReimport'),// ╠common.AddReimport⇒增加退運╣
  1311. area: ['300px', '120px'],//寬度
  1312. shade: 0.75,//遮罩
  1313. shadeClose: true,// ╠common.ReturnedHome⇒退運回國╣ ╠common.TransferFourPlace⇒出貨至第四地╣ ╠common.TransferFivePlace⇒出貨至第五地╣ ╠common.TransferSixPlace⇒出貨至第六地╣
  1314. content: '<div class="pop-box">\
  1315. <button type="button" data-i18n="ExhibitionExport_Upd.ReturnedHome" id="btn_ReturnedHome" class="btn-custom green">退運回國</button>\
  1316. <button type="button" data-i18n="ExhibitionExport_Upd.' + (iIndex === '3' ? 'TransferFourPlace' : iIndex === '4' ? 'TransferFivePlace' : 'TransferSixPlace') + '" id="btn_Transfer" class="btn-custom green">出貨至第n地</button>\
  1317. </div>',
  1318. success: function (layero, idx) {
  1319. layero.find('#btn_ReturnedHome').click(function () {
  1320. switch (iIndex) {
  1321. case '3':
  1322. form.find('#TransferFour').hide();
  1323. form.find('#ReImportFour').show();
  1324. form.find('#TranserThird').find('.addnextreturn').attr('disabled', true);
  1325. form.find('#LastReturnType').val('H');
  1326. break;
  1327. case '4':
  1328. form.find('#TransferFive').hide();
  1329. form.find('#ReImportFive').show();
  1330. form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
  1331. form.find('#ReturnType_4').val('H');
  1332. break;
  1333. case '5':
  1334. form.find('#TransferSix').hide();
  1335. form.find('#ReImportSix').show();
  1336. form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
  1337. form.find('#ReturnType_5').val('H');
  1338. break;
  1339. }
  1340. layer.close(idx);
  1341. });
  1342. layero.find('#btn_Transfer').click(function () {
  1343. switch (iIndex) {
  1344. case '3':
  1345. form.find('#TransferFour').show();
  1346. form.find('#ReImportFour').hide();
  1347. form.find('#TranserThird').find('.addnextreturn').attr('disabled', true);
  1348. form.find('#LastReturnType').val('F');
  1349. break;
  1350. case '4':
  1351. form.find('#TransferFive').show();
  1352. form.find('#ReImportFive').hide();
  1353. form.find('#TransferFour').find('.addnextreturn').attr('disabled', true);
  1354. form.find('#ReturnType_4').val('F');
  1355. break;
  1356. case '5':
  1357. form.find('#TransferSix').show();
  1358. form.find('#ReImportSix').hide();
  1359. form.find('#TransferFive').find('.addnextreturn').attr('disabled', true);
  1360. form.find('#ReturnType_5').val('F');
  1361. break;
  1362. }
  1363. layer.close(idx);
  1364. });
  1365. transLang(layero);
  1366. }
  1367. });
  1368. });
  1369. form.find(':input[type=checkbox]').not('#IsBatch').on('click', function (e) {
  1370. setTime(this);
  1371. setSuccessBtn($(this).parents('.flow'));
  1372. });
  1373. form.find(':input,select').on('change', function () {
  1374. bRequestStorage = true;
  1375. });
  1376. form.find('.ui-icon-close').on('click', function (e) {
  1377. var sFlowId = $(this).parents('.flow')[0].id;
  1378. switch (sFlowId) {
  1379. case 'ExportData':
  1380. $(this).parents('.form-group').remove();
  1381. break;
  1382. case 'PartThird':
  1383. form.find('#PartThirdAndReImport').hide();
  1384. form.find('.addreturns').removeAttr('disabled');
  1385. form.find('#ReturnType').val('');
  1386. break;
  1387. case 'TranserThird':
  1388. form.find('#TranserThird,#ReImportFour,#TransferFour,#ReImportFive,#TransferFive,#ReImportSix,#TransferSix').hide();
  1389. form.find('.addreturns').removeAttr('disabled');
  1390. form.find('#ReturnType').val('');
  1391. form.find('#LastReturnType').val('');
  1392. form.find('#ReturnType_4').val('');
  1393. form.find('#ReturnType_5').val('');
  1394. break;
  1395. case 'ReImport':
  1396. form.find('#ReImport').hide();
  1397. form.find('.addreturns').removeAttr('disabled');
  1398. form.find('#ReturnType').val('');
  1399. break;
  1400. case 'TransferFour':
  1401. form.find('#TransferFour,#ReImportFive,#TransferFive,#ReImportSix,#TransferSix').hide();
  1402. form.find('#TranserThird').find('.addnextreturn').removeAttr('disabled');
  1403. form.find('#LastReturnType').val('');
  1404. form.find('#ReturnType_4').val('');
  1405. form.find('#ReturnType_5').val('');
  1406. break;
  1407. case 'ReImportFour':
  1408. form.find('#ReImportFour').hide();
  1409. form.find('#TranserThird').find('.addnextreturn').removeAttr('disabled');
  1410. form.find('#LastReturnType').val('');
  1411. break;
  1412. case 'TransferFive':
  1413. form.find('#TransferFive,#ReImportSix,#TransferSix').hide();
  1414. form.find('#TransferFour').find('.addnextreturn').removeAttr('disabled');
  1415. form.find('#ReturnType_4').val('');
  1416. form.find('#ReturnType_5').val('');
  1417. break;
  1418. case 'ReImportFive':
  1419. form.find('#ReImportFive').hide();
  1420. form.find('#TransferFour').find('.addnextreturn').removeAttr('disabled');
  1421. form.find('#ReturnType_4').val('');
  1422. break;
  1423. case 'TransferSix':
  1424. form.find('#TransferSix').hide();
  1425. form.find('#TransferFive').find('.addnextreturn').removeAttr('disabled');
  1426. form.find('#ReturnType_5').val('');
  1427. break;
  1428. case 'ReImportSix':
  1429. form.find('#ReImportSix').hide();
  1430. form.find('#TransferFive').find('.addnextreturn').removeAttr('disabled');
  1431. form.find('#ReturnType_5').val('');
  1432. break;
  1433. }
  1434. });
  1435. },
  1436. /**
  1437. * 取得帳單log資料
  1438. * @return {Object}
  1439. */
  1440. fnGetBillLogData = function (Bill) {
  1441. var LogData = {};
  1442. LogData.OrgID = parent.OrgID;
  1443. LogData.BillNO = Bill.BillNO;
  1444. LogData.ExhibitioName = oCurData.Exhibitioname_TW; //ExhibitioName
  1445. LogData.PayerName = '';
  1446. if (Bill.Payer) {
  1447. var PayerData = Enumerable.From(saCustomers).Where(function (e) { return e.id === Bill.Payer; }).First();
  1448. LogData.PayerName = PayerData.text;
  1449. }
  1450. LogData.ResponsiblePersonName = oCurData.ResponsiblePerson;
  1451. LogData.Currency = Bill.Currency;
  1452. LogData.ExchangeRate = Bill.ExchangeRate;
  1453. LogData.Advance = Bill.Advance;
  1454. LogData.AmountSum = Bill.AmountSum;
  1455. LogData.TaxSum = Bill.TaxSum;
  1456. LogData.AmountTaxSum = Bill.AmountTaxSum;
  1457. LogData.TotalReceivable = Bill.TotalReceivable;
  1458. LogData.OpmBillCreateUserName = oCurData.CreateUser;
  1459. LogData.ModifyUser = parent.UserID;
  1460. return LogData;
  1461. },
  1462. /**
  1463. * 設定客戶下拉選單
  1464. * @return {Object} ajax物件
  1465. */
  1466. fnSetCustomersDrop = function () {
  1467. return g_api.ConnectLite(Service.sys, 'GetCustomerlist', {}, function (res) {
  1468. if (res.RESULT) {
  1469. saCustomers = res.DATA.rel;
  1470. var saContactors = []
  1471. if (saCustomers.length > 0) {
  1472. sCustomersOptionsHtml = createOptions(saCustomers, 'id', 'text');
  1473. $('#Agent').html(sCustomersOptionsHtml).on('change', function () {
  1474. var sAgent = this.value;
  1475. if (sAgent) {
  1476. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === sAgent; }).First();
  1477. saContactors = JSON.parse(oCur.Contactors || '[]');
  1478. $('#AgentContactor').html(createOptions(saContactors, 'guid', 'FullName')).off('change').on('change', function () {
  1479. var sContactor = this.value;
  1480. if (sContactor) {
  1481. var oContactor = Enumerable.From(saContactors).Where(function (e) { return e.guid === sContactor; }).First();
  1482. $('#AgentEamil').val(oContactor.Email);
  1483. $('#AgentTelephone').val(oContactor.TEL1);
  1484. }
  1485. else {
  1486. $('#AgentEamil').val('');
  1487. $('#AgentTelephone').val('');
  1488. }
  1489. bRequestStorage = true;
  1490. });
  1491. }
  1492. else {
  1493. $('#AgentContactor').html(createOptions([]));
  1494. }
  1495. });
  1496. $('#Organizer1,#Organizer2,#Organizer3,#Organizer4').html(sCustomersOptionsHtml);
  1497. var saNotAuditCurs = Enumerable.From(saCustomers).Where(function (e) { return e.IsAudit === 'Y'; }).ToArray();
  1498. sCustomersNotAuditOptionsHtml = createOptions(saNotAuditCurs, 'id', 'text');
  1499. }
  1500. select2Init();
  1501. $("#Organizer1,#Organizer2,#Organizer3,#Organizer4").select2();
  1502. $.each($("#Organizer1,#Organizer2,#Organizer3,#Organizer4"), function (idx, item) {
  1503. //組團單位-動態產生
  1504. let OrganizerIdex = idx + 1;
  1505. $("#Organizer" + OrganizerIdex).on('select2:select', function (e) {
  1506. var data = e.params.data;
  1507. sSelectedOrganizers[OrganizerIdex] = { id: data.id, text: data.text, title: data.title };
  1508. $('[data-id="BillOrganizer"]').html(createOptions(sSelectedOrganizers.filter(e => e != null), 'id', 'text'));
  1509. //加入到儲存資料內
  1510. sOrganizers = [];
  1511. $.each(sSelectedOrganizers, function (idx, e) {
  1512. if (e && e.id.length === 36)
  1513. sOrganizers.push(e.id);
  1514. })
  1515. });
  1516. })
  1517. //後端對應也要改
  1518. sSelectedOrganizers[MaxOrganizerCount] = { id: "SelfCome", text: "自來", title: "自來" };
  1519. }
  1520. });
  1521. },
  1522. /**
  1523. * 批次操作獲取廠商資料
  1524. * @return {Object} promise物件
  1525. */
  1526. fnGetPop_CusSupplier = function () {
  1527. var saList = [],
  1528. iIndex = 1,
  1529. sSupplierName = $('#Pop_SupplierName').val(),
  1530. sSupplierEName = $('#Pop_SupplierEName').val(),
  1531. fnCheck = function (itemMatch) {
  1532. var bMatch = true;
  1533. if (!((itemMatch.LastReturnType || '') === (oCurSupplierData.LastReturnType || '') && (itemMatch.ReturnType || '') === (oCurSupplierData.ReturnType || ''))) {
  1534. bMatch = false;
  1535. }
  1536. return bMatch;
  1537. },
  1538. d = $.Deferred();
  1539. $.each(saGridData, function (idx, item) {
  1540. if ((((item.SupplierName || '').indexOf(sSupplierName) > -1 || sSupplierName === '')
  1541. && ((item.SupplierEName || '').indexOf(sSupplierEName) > -1 || sSupplierEName === '') && fnCheck(item))) {
  1542. saList.push({
  1543. RowIndex: iIndex,
  1544. guid: item.guid,
  1545. SupplierID: item.SupplierID,
  1546. CustomerNO: item.CustomerNO,
  1547. UniCode: item.UniCode,
  1548. SupplierName: item.SupplierName || '',
  1549. SupplierEName: item.SupplierEName || ''
  1550. });
  1551. iIndex++;
  1552. }
  1553. });
  1554. d.resolve({
  1555. data: saList,
  1556. itemsCount: saList.length
  1557. });
  1558. return d.promise();
  1559. },
  1560. /*
  1561. * 取得當年度幣值設定
  1562. */
  1563. fnGetCurrencyThisYear = function (BillCreateTime) {
  1564. return fnGetCurrencyByYear({
  1565. Year: BillCreateTime, CallBack: function (data) {
  1566. saAccountingCurrency = data;
  1567. sAccountingCurrencyOptionsHtml = createOptions(saAccountingCurrency, 'ArgumentID', 'ArgumentValue', false, 'Correlation');
  1568. }
  1569. });
  1570. },
  1571. /**------------------------帳單部分---------------------------Start*/
  1572. /**
  1573. * 審核通過後禁用頁面欄位
  1574. * @param {Object}dom 當前區塊
  1575. * @param {Object}data 當前資料
  1576. */
  1577. fnSetDisabled = function (dom, data) {
  1578. if (data) {
  1579. if (data.BillNO) {
  1580. switch (data.AuditVal) {
  1581. case '0':// ╠common.NotAudit⇒未提交審核╣
  1582. dom.find('.status-font').text(i18next.t("common.NotAudit")).css('color', 'red');
  1583. break;
  1584. case '1':// ╠common.InAudit⇒提交審核中╣
  1585. dom.find('.status-font').text(i18next.t("common.InAudit")).css('color', 'blue');
  1586. break;
  1587. case '2':// ╠common.Audited⇒已審核╣
  1588. dom.find('.status-font').text(i18next.t("common.Audited")).css('color', 'green');
  1589. break;
  1590. case '3':// ╠common.NotPass⇒不通過╣
  1591. dom.find('.status-font').text(i18next.t("common.NotPass")).css('color', 'red');
  1592. break;
  1593. case '4':// ╠common.NotPass⇒已銷帳╣
  1594. dom.find('.status-font').text(i18next.t("common.HasBeenRealized")).css('color', 'red');
  1595. break;
  1596. case '5':// ╠common.HasBeenPost⇒已過帳╣
  1597. dom.find('.status-font').text(i18next.t("common.HasBeenPost")).css('color', 'green');
  1598. break;
  1599. case '6':// ╠common.HasVoid⇒已作廢╣
  1600. dom.find('.status-font').text(i18next.t("common.HasVoid")).css('color', '#b2b1b1');
  1601. break;
  1602. case '7':// ╠common.HasReEdit⇒抽單中╣
  1603. dom.find('.status-font').text(i18next.t("common.HasReEdit")).css('color', 'blue');
  1604. break;
  1605. }
  1606. }
  1607. dom.find('.bill-status-box').show();
  1608. dom.find('.notpass-reason-box').hide();
  1609. let DraftRecipt = false;
  1610. switch (data.AuditVal) {
  1611. case '0':// ╠common.NotAudit⇒未提交審核╣
  1612. dom.find('.bill-status').text(i18next.t("common.NotAudit")).css('color', 'red');
  1613. dom.find('.billpost,.cancelpost,.writeoff,.canceloff,.reedit,.cancelreedit').hide();
  1614. dom.find('.submittoaudit,.synquote,.alreadyaudit').show();
  1615. dom.find('.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
  1616. if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
  1617. if (data.FeeItems.length > 0) {
  1618. dom.find('.submittoaudit').removeAttr('disabled');
  1619. dom.parent().next().find('.synquote').removeAttr('disabled');
  1620. }
  1621. else {
  1622. dom.find('.submittoaudit').prop('disabled', true);
  1623. dom.parent().next().find('.synquote').prop('disabled', true);
  1624. }
  1625. }
  1626. else {
  1627. if (data.KeyName === 'Bill') {
  1628. dom.find(':input,textarea,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
  1629. dom.find('.icon-p').addClass('disabled');
  1630. }
  1631. }
  1632. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1633. dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
  1634. }
  1635. else {
  1636. dom.find('.billvoid').hide();
  1637. }
  1638. if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
  1639. dom.find('.billdelete').removeAttr('disabled');
  1640. }
  1641. else {
  1642. dom.find('.billdelete').hide();
  1643. }
  1644. dom.find('.bills-print').removeAttr('disabled');//新增列印草稿
  1645. DraftRecipt = true;
  1646. break;
  1647. case '1':// ╠common.InAudit⇒提交審核中╣
  1648. dom.find('.bill-status').text(i18next.t("common.InAudit")).css('color', 'blue');
  1649. dom.find('.billpost,.cancelpost,.writeoff,.canceloff,.cancelaudi').hide();
  1650. dom.find('.submittoaudit,.synquote,.alreadyaudit,.reedit,.cancelreedit').show();
  1651. dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.submittoaudit,.synquote,.billpost,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
  1652. dom.find('.icon-p').addClass('disabled');
  1653. if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
  1654. dom.find('.reedit').removeAttr('disabled');
  1655. }
  1656. if (parent.UserInfo.UsersDown.indexOf(oCurData.ResponsiblePerson) > -1 || parent.UserInfo.UsersBranch.indexOf(oCurData.ResponsiblePerson) > -1 || parent.SysSet.BillAuditor.indexOf(parent.UserInfo.MemberID) > -1) {
  1657. dom.find('.alreadyaudit').removeAttr('disabled');
  1658. }
  1659. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1660. dom.find('.reedit,.cancelreedit').hide();
  1661. dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
  1662. }
  1663. else {
  1664. dom.find('.billvoid').hide();
  1665. }
  1666. if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
  1667. dom.find('.billdelete').removeAttr('disabled');
  1668. }
  1669. else {
  1670. dom.find('.billdelete').hide();
  1671. }
  1672. dom.find('.bills-print').removeAttr('disabled');//新增列印草稿
  1673. break;
  1674. case '2':// ╠common.Audited⇒已審核╣
  1675. dom.find('.bill-status').text(i18next.t("common.Audited")).css('color', 'green');
  1676. dom.find('.submittoaudit,.synquote,.alreadyaudit,.writeoff,.canceloff,.reedit,.cancelreedit').hide();
  1677. dom.find('.billpost,.cancelpost,.cancelaudi,.writeoff').show();
  1678. dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.submittoaudit,.synquote,.billpost,.alreadyaudit,.cancelpost,.writeoff,[data-id="Payer"]').attr('disabled', 'disabled');
  1679. dom.find('.icon-p').addClass('disabled');
  1680. dom.find('.bills-print').removeAttr('disabled');
  1681. if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
  1682. dom.find('.billpost,.receiptnumberbtn,.checkauditdate').removeAttr('disabled');
  1683. }
  1684. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1685. dom.find('.prepay,.mprepay,.cancelaudi,.billvoid,.writeoff').removeAttr('disabled');
  1686. }
  1687. else {
  1688. dom.find('.billvoid').hide();
  1689. }
  1690. if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
  1691. dom.find('.billdelete').removeAttr('disabled');
  1692. dom.find('.billpost,.cancelpost').hide();
  1693. }
  1694. else {
  1695. dom.find('.billdelete').hide();
  1696. }
  1697. break;
  1698. case '3':// ╠common.NotPass⇒不通過╣
  1699. dom.find('.notpass-reason-text').text(data.NotPassReason || '');
  1700. dom.find('.bill-status').text(i18next.t("common.NotPass")).css('color', 'red');
  1701. dom.find('.billpost,.cancelpost,.writeoff,.canceloff,.reedit,.cancelreedit').hide();
  1702. dom.find('.submittoaudit,.synquote,.alreadyaudit,.notpass-reason-box').show();
  1703. if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
  1704. if (data.FeeItems.length > 0) {
  1705. dom.find('.submittoaudit').removeAttr('disabled');
  1706. dom.parent().next().find('.synquote').removeAttr('disabled');
  1707. }
  1708. else {
  1709. dom.find('.submittoaudit').prop('disabled', true);
  1710. dom.parent().next().find('.synquote').prop('disabled', true);
  1711. }
  1712. }
  1713. else {
  1714. dom.find(':input,textarea,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
  1715. dom.find('.icon-p').addClass('disabled');
  1716. }
  1717. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1718. dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
  1719. }
  1720. else {
  1721. dom.find('.billvoid').hide();
  1722. }
  1723. if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
  1724. dom.find('.billdelete').removeAttr('disabled');
  1725. }
  1726. else {
  1727. dom.find('.billdelete').hide();
  1728. }
  1729. break;
  1730. case '4':// ╠common.NotPass⇒已銷帳╣
  1731. dom.find('.bill-status').text(i18next.t("common.HasBeenRealized")).css('color', 'red');
  1732. dom.find('.submittoaudit,.synquote,.alreadyaudit,.cancelaudi,.billpost,.cancelpost,.writeoff,.reedit,.cancelreedit').hide();
  1733. dom.find('.canceloff').show();
  1734. dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff,.submittoaudit,.synquote,.billpost').attr('disabled', 'disabled');
  1735. dom.find('.icon-p').addClass('disabled');
  1736. dom.find('.bills-print').removeAttr('disabled');
  1737. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1738. dom.find('.canceloff,.billvoid').removeAttr('disabled');
  1739. }
  1740. else {
  1741. dom.find('.billvoid').hide();
  1742. }
  1743. if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
  1744. dom.find('.billdelete').removeAttr('disabled');
  1745. }
  1746. else {
  1747. dom.find('.billdelete').hide();
  1748. }
  1749. break;
  1750. case '5':// ╠common.HasBeenPost⇒已過帳╣
  1751. dom.find('.bill-status').text(i18next.t("common.HasBeenPost")).css('color', 'green');
  1752. dom.find('.billpost,.submittoaudit,.synquote,.alreadyaudit,.cancelaudi,.reedit,.cancelreedit').hide();
  1753. dom.find('.cancelpost,.writeoff,.canceloff').show();
  1754. dom.find(':input,textarea,.plusfeeitem,.importfeeitem,.copyfeeitem,.plusfeeitemstar,select,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff,.bills-print,.submittoaudit,.synquote,.billpost').attr('disabled', 'disabled');
  1755. dom.find('.icon-p').addClass('disabled');
  1756. dom.find('.bills-print').removeAttr('disabled');
  1757. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1758. dom.find('.cancelpost,.writeoff,.billvoid').removeAttr('disabled');
  1759. }
  1760. else {
  1761. dom.find('.billvoid').hide();
  1762. }
  1763. if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
  1764. dom.find('.billdelete').removeAttr('disabled');
  1765. }
  1766. else {
  1767. dom.find('.billdelete').hide();
  1768. }
  1769. break;
  1770. case '6':// ╠common.HasVoid⇒已作廢╣
  1771. dom.find('.notpass-reason-text').text(data.VoidReason || '');
  1772. dom.find('.bill-status').text(i18next.t("common.HasVoid")).css('color', '#b2b1b1');
  1773. dom.find('button').not('.plusfeeitem').hide();
  1774. dom.find('.notpass-reason-box').show();
  1775. dom.find(':input,textarea').attr('disabled', 'disabled');
  1776. dom.find('.icon-p').addClass('disabled');
  1777. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1778. dom.find('.billvoid').removeAttr('disabled');
  1779. }
  1780. break;
  1781. case '7':// ╠common.HasReEdit⇒抽單中╣
  1782. dom.find(':input,textarea').removeAttr('disabled');
  1783. dom.find('.icon-p').removeClass('disabled');
  1784. dom.find('.bill-status').text(i18next.t("common.HasReEdit")).css('color', 'blue');
  1785. dom.find('.submittoaudit,.synquote,.alreadyaudit').show();
  1786. dom.find('.billpost,.cancelpost,.writeoff,.canceloff').hide();
  1787. dom.find('.alreadyaudit,.cancelaudi,.cancelpost,.writeoff,.bills-print,.submittoaudit,.synquote,.reedit').attr('disabled', 'disabled');
  1788. if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {//如果有資料且是null或者N
  1789. dom.find('.cancelreedit').removeAttr('disabled');
  1790. }
  1791. else {
  1792. if (data.KeyName === 'Bill') {
  1793. dom.find(':input,textarea,.alreadyaudit,.cancelaudi,.cancelpost,.writeoff').attr('disabled', 'disabled');
  1794. dom.find('.icon-p').addClass('disabled');
  1795. }
  1796. }
  1797. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  1798. dom.find('.prepay,.mprepay,.billvoid').removeAttr('disabled');
  1799. }
  1800. else {
  1801. dom.find('.billvoid').hide();
  1802. }
  1803. if (parent.UserInfo.roles.indexOf('Admin') > -1) {//超級管理員
  1804. dom.find('.billdelete').removeAttr('disabled');
  1805. }
  1806. else {
  1807. dom.find('.billdelete').hide();
  1808. }
  1809. dom.find('.bills-print').removeAttr('disabled');//新增列印草稿
  1810. break;
  1811. }
  1812. if (DraftRecipt) {
  1813. dom.find("[data-action='Print_Receipt']").hide();
  1814. dom.find("[data-action='Download_Receipt']").hide();
  1815. }
  1816. else {
  1817. dom.find("[data-action='Print_Receipt']").show();
  1818. dom.find("[data-action='Download_Receipt']").show();
  1819. }
  1820. if (parent.UserInfo.roles.indexOf('Business') > -1) {
  1821. dom.find('[data-id="ExchangeRate"]').attr('disabled', 'disabled');
  1822. }
  1823. fnOpenAccountingArea(dom.find('.OnlyForAccounting'), parent.UserInfo.roles);
  1824. fnOpenAccountingArea(dom.find('.BillOrganizers'), parent.UserInfo.roles);
  1825. }
  1826. },
  1827. /**
  1828. * 綁定費用項目
  1829. * @param {HTMLELment} dom 當前標籤
  1830. * @param {HTMLELment} parentdata 父層標籤
  1831. * @param {Object} data 當前資料
  1832. * @param {String} flag 綁定狀態
  1833. */
  1834. fnBindFeeItem = function (dom, parentdata, data, flag) {
  1835. oGlobalItem.data = data;
  1836. oGlobalItem.dom = dom;
  1837. oGlobalItem.parentdata = parentdata;
  1838. var iMathDot = 0;
  1839. if (parentdata.Quote.QuotationOrBillingCurrency == "NTD") {
  1840. iMathDot = 0;
  1841. } else {
  1842. iMathDot = 2;
  1843. }
  1844. $.each(data.FeeItems, function (idx, item) {
  1845. item.OrderBy = idx + 1;
  1846. item.FinancialUnitPrice = parseFloat((item.FinancialUnitPrice || '0').toString().replaceAll(',', ''));
  1847. item.FinancialAmount = parseFloat((item.FinancialAmount || '0').toString().replaceAll(',', ''));
  1848. item.FinancialTWAmount = parseFloat((item.FinancialTWAmount || '0').toString().replaceAll(',', ''));
  1849. item.FinancialTax = parseFloat((item.FinancialTax || '0').toString().replaceAll(',', ''));
  1850. });
  1851. data.FeeItems = Enumerable.From(data.FeeItems).OrderBy("x=>x.OrderBy").ToArray();
  1852. var sFeeItemsHtml = '',
  1853. iSubtotal = 0,
  1854. iSubtotal_Tax = 0,
  1855. iSubtotal_NoTax = 0,
  1856. iTaxtotal = 0,
  1857. iTaxSubtotal = 0,
  1858. oFinancial = dom.parents('.financial'),
  1859. sDomId = dom.attr('data-id'),
  1860. bForn = (data.Currency === undefined || data.Currency === 'NTD'),
  1861. iOldBoxTotal = parseFloat((oFinancial.find('.subtotal').val() || '0').replaceAll(',', '')),
  1862. oTab = dom.parents('.tab-pane');
  1863. $.each(data.FeeItems, function (idx, item) {
  1864. sFeeItemsHtml += '<tr>'
  1865. + '<td class="wcenter">' + (idx + 1) + '</td>'
  1866. + '<td class="wcenter">' + item.FinancialCode + '</td>'
  1867. + '<td>' + (!item.FinancialCostStatement ? item.Memo : item.FinancialCostStatement + (!item.Memo ? '' : '(' + item.Memo + ')')) + '</td>'
  1868. + '<td class="wcenter">' + item.FinancialCurrency + '</td>'
  1869. + '<td class="wright">' + item.FinancialUnitPrice + '</td>'
  1870. + '<td class="wcenter">' + item.FinancialNumber + '</td>'
  1871. + '<td>' + item.FinancialUnit + '</td>'
  1872. + '<td class="wright">' + fMoney(item.FinancialAmount, 2) + '</td>'
  1873. + '<td class="wcenter">' + item.FinancialExchangeRate + '</td>'
  1874. + '<td class="wright">' + fMoney(item.FinancialTWAmount, iMathDot) + '</td>'
  1875. + '<td class="wcenter">' + item.FinancialTaxRate + '</td>'
  1876. + '<td class="wright">' + fMoney(item.FinancialTax, 2) + '</td>'
  1877. + (data.KeyName === 'ActualCost' ? '<td class="wcenter billpayer w15p " data-billno="' + (item.BillNO || '') + '" data-value="' + item.guid + '"></td>' : '')
  1878. + (!flag ? '<td class="wcenter">'
  1879. + '<div class="fa-item col-sm-3"><i class="glyphicon glyphicon-pencil icon-p" data-value="' + item.guid + '" title="編輯"></i></div>'
  1880. + '<div class="fa-item col-sm-3"><i class="glyphicon glyphicon-trash icon-p" data-value="' + item.guid + '" title="刪除"></i></div>'
  1881. + ((data.FeeItems.length !== idx + 1) ? '<div class="fa-item col-sm-3"><i class="glyphicon glyphicon-arrow-down icon-p" data-value="' + item.guid + '" title="下移"></i></div>' : '<div class="fa-item col-sm-3"><i class="icon-p"></i></div>')
  1882. + ((idx !== 0) ? '<div class="fa-item col-sm-3"><i class="glyphicon glyphicon-arrow-up icon-p" data-value="' + item.guid + '" title="上移"></i></div>' : '<div class="fa-item col-sm-3"><i class="icon-p"></i></div>')
  1883. + '</td>' : '') +
  1884. +'</tr>';
  1885. if (item.FinancialTaxRate.toString().replace('%', '') !== '0') {
  1886. iSubtotal_Tax += parseFloat(item.FinancialTWAmount);
  1887. }
  1888. else {
  1889. iSubtotal_NoTax += parseFloat(item.FinancialTWAmount);
  1890. }
  1891. });
  1892. //計算總計(total)依序:1.參數的幣值 2.抓到財務的Currency設定 3.再來設定台幣。
  1893. var CurrencyType = (data.Currency || oFinancial.find('[data-id="Currency"]').val()) || FeeItemCurrency;
  1894. dom.html(sFeeItemsHtml);
  1895. iSubtotal_Tax = fnRound(iSubtotal_Tax, data.Currency);
  1896. iSubtotal_NoTax = fnRound(iSubtotal_NoTax, data.Currency);
  1897. if(data.KeyName == "Quote"){
  1898. CurrencyType = (data.QuotationOrBillingCurrency || oFinancial.find('[data-id="Currency"]').val()) || FeeItemCurrency;
  1899. iSubtotal_Tax = fnRound(iSubtotal_Tax, data.QuotationOrBillingCurrency);
  1900. iSubtotal_NoTax = fnRound(iSubtotal_NoTax, data.QuotationOrBillingCurrency);
  1901. }
  1902. iSubtotal = fnRound(iSubtotal_Tax + iSubtotal_NoTax, CurrencyType);
  1903. var iTaxRate = parent.SysSet.TaxRate.toPoint();
  1904. iTaxtotal = fnRound(iSubtotal_Tax * (iTaxRate === 0 ? 0.05 : iTaxRate), CurrencyType);
  1905. iTaxSubtotal = iSubtotal + iTaxtotal;
  1906. oFinancial.find('.subtotal').val(fMoney(iSubtotal, 2, CurrencyType));
  1907. oFinancial.find('.taxtotal').val(fMoney(iTaxtotal, 2, CurrencyType));
  1908. oFinancial.find('.boxtotal').val(fMoney(iTaxSubtotal, 2, CurrencyType));
  1909. data.AmountSum = iSubtotal;
  1910. data.TaxSum = iTaxtotal;
  1911. data.AmountTaxSum = iTaxSubtotal;
  1912. switch (data.KeyName) {
  1913. case 'ActualCost':
  1914. if (oTab[0].id === 'tab4') {
  1915. $('#tab4 .topshowsum').show();
  1916. $('#tab4 .actualsum').val(fMoney(iTaxSubtotal, 2, data.Currency));
  1917. if (parentdata.ActualCost.AmountTaxSum > parentdata.EstimatedCost.AmountTaxSum) {
  1918. $('#tab4 #warnning_tips').show();
  1919. }
  1920. else {
  1921. $('#tab4 #warnning_tips').hide();
  1922. }
  1923. }
  1924. else if (oTab[0].id === 'tab6') {
  1925. oFinancial.find('.actualsum').val(fMoney(iTaxSubtotal, 2, data.Currency));
  1926. var iAcount = 0;
  1927. $.each(parentdata.Bills, function (idx, _bill) {
  1928. if (_bill.AuditVal !== '6') {
  1929. iAcount += _bill.AmountTaxSum;
  1930. }
  1931. });
  1932. oFinancial.find('.amountsum').val(fMoney(iAcount, 2, data.Currency));
  1933. if (parentdata.ActualCost.AmountTaxSum > parentdata.EstimatedCost.AmountTaxSum) {
  1934. oFinancial.parent().prev().find('.warnningtips').show();
  1935. }
  1936. else {
  1937. oFinancial.parent().prev().find('.warnningtips').hide();
  1938. }
  1939. }
  1940. break;
  1941. case 'EstimatedCost':
  1942. if (oTab[0].id === 'tab3') {
  1943. $('#tab3 .estimatedcostsum').val(fMoney(iSubtotal, 2, data.Currency));
  1944. }
  1945. else if (oTab[0].id === 'tab5') {
  1946. //增加退運報價/預估成本-預估成本累加
  1947. let Return_Estimatedcostsum = $('#tab5 .return_estimatedcostsum').val();
  1948. let Current_Return_Estimatedcostsum = parseFloat((Return_Estimatedcostsum || '0').toString().replaceAll(',', '')) - iOldBoxTotal;
  1949. $('#tab5 .return_estimatedcostsum').val(fMoney(Current_Return_Estimatedcostsum + iSubtotal, 2, data.Currency));
  1950. }
  1951. break;
  1952. case 'Bill':
  1953. var iAdvance = parseFloat(oFinancial.find('.prepay').val().replaceAll(',', '')),
  1954. iExchangeRate = data.ExchangeRate || 1;
  1955. data.TotalReceivable = iTaxSubtotal - iAdvance;
  1956. oFinancial.find('.subtotal').val(fMoney(iSubtotal, 2, data.Currency));
  1957. oFinancial.find('.taxtotal').val(fMoney(iTaxtotal, 2, data.Currency));
  1958. oFinancial.find('.boxtotal').val(fMoney(iTaxSubtotal, 2, data.Currency));
  1959. oFinancial.find('.paytotal').val(fMoney(iTaxSubtotal - iAdvance, 2, data.Currency));
  1960. let TabTipExchangeRate = (bForn ? 1 : iExchangeRate);
  1961. let TabTipTaxtotal = fnRound(iTaxtotal * TabTipExchangeRate, FeeItemCurrency);
  1962. let TabTipUntaxtotal = fnRound(iSubtotal * TabTipExchangeRate, FeeItemCurrency);
  1963. iOldBoxTotal = iOldBoxTotal * (bForn ? 1 : iExchangeRate);
  1964. //加總
  1965. if (oTab[0].id === 'tab3') {
  1966. if (data.AuditVal !== '6') {
  1967. let LastRowActualsum = parseFloat($('#tab3 .amountsum').val().replaceAll(',', '')) - iOldBoxTotal
  1968. if (LastRowActualsum < 0) {
  1969. LastRowActualsum = 0;
  1970. }
  1971. $('#tab3 .amountsum').val(fMoney(LastRowActualsum + TabTipUntaxtotal, 2, FeeItemCurrency));
  1972. $('#tab4 .amountsum').val($('#tab3 .amountsum').val());
  1973. }
  1974. }
  1975. else if (oTab[0].id === 'tab5') {
  1976. oFinancial.find('.topshowsum').show();
  1977. oFinancial.find('.estimatedcostsum').val(fMoney(parentdata.EstimatedCost.AmountTaxSum, 2, data.Currency));
  1978. if (data.AuditVal !== '6') {
  1979. let LastRowActualsum = parseFloat(oFinancial.find('.amountsum').val().replaceAll(',', '')) - iOldBoxTotal;
  1980. oFinancial.find('.amountsum').val(fMoney(LastRowActualsum + TabTipUntaxtotal, 2, FeeItemCurrency));
  1981. $('.bill-box-' + data.BillNO).find('.amountsum').val(oFinancial.find('.amountsum').val());
  1982. //增加退運報價/預估成本-帳單金額累加(有先後順序,無法對調)
  1983. let LastRow_Return_Amountsum = parseFloat($('#tab5 .return_amountsum').val().replaceAll(',', '') - iOldBoxTotal);
  1984. let Current_Return_Amountsum = TabTipUntaxtotal; //TabTipTaxtotal + TabTipUntaxtotal;
  1985. $('#tab5 .return_amountsum').val(fMoney(LastRow_Return_Amountsum + Current_Return_Amountsum, 2, FeeItemCurrency));
  1986. }
  1987. }
  1988. break;
  1989. }
  1990. /*計算$$*/
  1991. if (oTab[0].id === 'tab3') {
  1992. if (data.KeyName === 'Bill')
  1993. fnCalcuBillsFee(oFinancial, '.BillForeignCurrency', '.BillMainCurrency', data.Currency, data.ExchangeRate);
  1994. else
  1995. fnCalcuQuotationFee(oFinancial.find('.QuotationForeignCurrency'), oFinancial.find('.QuotationMainCurrency'),
  1996. parentdata.Quote.QuotationOrBillingCurrency, parentdata.Quote.AccountingExchangeRate);
  1997. }
  1998. else if (oTab[0].id === 'tab5') {
  1999. if (data.KeyName === 'Bill')
  2000. fnCalcuBillsFee(oFinancial, '.ReturnBillForeignCurrency', '.ReturnBillMainCurrency',
  2001. data.Currency, data.ExchangeRate);
  2002. else {
  2003. fnCalcuQuotationFee(oFinancial.find('.ReturnQuotationForeignCurrency'), oFinancial.find('.ReturnQuotationMainCurrency'),
  2004. parentdata.ReturnQuotationOrBillingCurrency, parentdata.ReturnAccountingExchangeRate);
  2005. }
  2006. }
  2007. dom.parents('.financial').find('.plusfeeitem').prop('disabled', false);
  2008. fnSetDisabled(oFinancial, data);
  2009. oFinancial.find('.input-value').on('change', function () {
  2010. var that = this,
  2011. sId = $(that).attr('data-id');
  2012. data[sId] = $(that).val();
  2013. bRequestStorage = true;
  2014. });
  2015. if (data.KeyName === 'ActualCost') {
  2016. var saBillPayers = function () {
  2017. var saRetn = [];
  2018. $.each(parentdata.Bills, function (idx, bill) {
  2019. if (!bill.VoidReason) {
  2020. var sPayer = '',
  2021. oCur = {};
  2022. if (bill.Payer) {
  2023. oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === bill.Payer; }).First();
  2024. }
  2025. saRetn.push({
  2026. id: bill.BillNO,
  2027. text: oCur.text,
  2028. val: bill.BillNO + '-' + (oCur.text || '') + '-' + bill.BillCreateDate
  2029. });
  2030. }
  2031. });
  2032. return saRetn;
  2033. }();
  2034. dom.find('.billpayer').each(function () {
  2035. var sGuid = $(this).attr('data-value'),
  2036. sBillNO = $(this).attr('data-billno'),
  2037. Selector = 'oBillPayers-' + sGuid;
  2038. $(this).append($('<select>', {
  2039. class: 'form-control w100p ' + Selector, 'multiple': 'multiple',
  2040. html: createOptions(saBillPayers, 'id', 'id', false),
  2041. change: function () {
  2042. var sBill = this.value;
  2043. $.each(parentdata.ActualCost.FeeItems, function (idx, item) {
  2044. if (sGuid === item.guid) {
  2045. var SelectedValues = getSelectedValues('.oBillPayers-' + this.guid);
  2046. var MappedPayers = Enumerable.From(saBillPayers).Where(function (e) {
  2047. return SelectedValues.indexOf(e.id) > -1;
  2048. }).ToArray();
  2049. item.BillNO = MappedPayers.map(c => c.id).join(',');
  2050. item.BillPayer = MappedPayers.map(c => c.val).join(',');
  2051. return false;
  2052. }
  2053. });
  2054. }
  2055. }));
  2056. $(this).find('.' + Selector + ' option:first').remove();
  2057. let mySelect = new vanillaSelectBox('.' + Selector, {
  2058. search: true,
  2059. maxHeight: 160,
  2060. maxWidth: 200,
  2061. });
  2062. mySelect.multipleSize = 2;
  2063. mySelect.setValue(sBillNO);
  2064. $('#btn-group-\\.' + Selector).click(function (e) {
  2065. $('.vsb-menu').css('display', 'none');
  2066. $('#btn-group-\\.' + Selector).find('.vsb-menu').css('display', 'block');
  2067. })
  2068. });
  2069. }
  2070. dom.find('.glyphicon-pencil').off('click').on('click', function () {
  2071. var that = this,
  2072. sGuid = $(that).attr('data-value'),
  2073. oCurFee = {},
  2074. sBillNO = dom.attr('data-billno') || '';
  2075. //if ($(that).hasClass('disabled')) { return; }//如果禁用後就不執行
  2076. switch (sDomId) {
  2077. case 'quote-box':
  2078. $.each(parentdata.Quote.FeeItems, function (idx, item) {
  2079. if (sGuid === item.guid) {
  2080. oCurFee = item;
  2081. return false;
  2082. }
  2083. });
  2084. break;
  2085. case 'estimatedcost-box':
  2086. $.each(parentdata.EstimatedCost.FeeItems, function (idx, item) {
  2087. if (sGuid === item.guid) {
  2088. oCurFee = item;
  2089. return false;
  2090. }
  2091. });
  2092. break;
  2093. case 'bill_fees_' + sBillNO:
  2094. $.each(parentdata.Bills, function (idx, bill) {
  2095. if (sBillNO === bill.BillNO) {
  2096. $.each(bill.FeeItems, function (idx, item) {
  2097. if (sGuid === item.guid) {
  2098. oCurFee = item;
  2099. return false;
  2100. }
  2101. });
  2102. return false;
  2103. }
  2104. });
  2105. break;
  2106. case 'actualcost-box':
  2107. $.each(parentdata.ActualCost.FeeItems, function (idx, item) {
  2108. if (sGuid === item.guid) {
  2109. oCurFee = item;
  2110. return false;
  2111. }
  2112. });
  2113. break;
  2114. }
  2115. fnPlusFeeItem(that, parentdata, oCurFee, data.Currency);
  2116. });
  2117. dom.find('.glyphicon-trash').off('click').on('click', function () {
  2118. var that = this,
  2119. sGuid = $(that).attr('data-value'),
  2120. saNewList = [],
  2121. sBillNO = dom.attr('data-billno') || '';
  2122. if ($(that).hasClass('disabled')) { return; }//如果禁用後就不執行
  2123. switch (sDomId) {
  2124. case 'quote-box':
  2125. $.each(parentdata.Quote.FeeItems, function (idx, item) {
  2126. if (sGuid !== item.guid) {
  2127. saNewList.push(item);
  2128. }
  2129. });
  2130. parentdata.Quote.FeeItems = saNewList;
  2131. fnBindFeeItem(dom, parentdata, parentdata.Quote);
  2132. break;
  2133. case 'estimatedcost-box':
  2134. $.each(parentdata.EstimatedCost.FeeItems, function (idx, item) {
  2135. if (sGuid !== item.guid) {
  2136. saNewList.push(item);
  2137. }
  2138. });
  2139. parentdata.EstimatedCost.FeeItems = saNewList;
  2140. fnBindFeeItem(dom, parentdata, parentdata.EstimatedCost);
  2141. break;
  2142. case 'bill_fees_' + sBillNO:
  2143. $.each(parentdata.Bills, function (idx, bill) {
  2144. if (sBillNO === bill.BillNO) {
  2145. $.each(bill.FeeItems, function (idx, item) {
  2146. if (sGuid !== item.guid) {
  2147. saNewList.push(item);
  2148. }
  2149. });
  2150. bill.FeeItems = saNewList;
  2151. fnBindFeeItem(dom, parentdata, bill);
  2152. return false;
  2153. }
  2154. });
  2155. break;
  2156. case 'actualcost-box':
  2157. $.each(parentdata.ActualCost.FeeItems, function (idx, item) {
  2158. if (sGuid !== item.guid) {
  2159. saNewList.push(item);
  2160. }
  2161. });
  2162. parentdata.ActualCost.FeeItems = saNewList;
  2163. fnBindFeeItem(dom, parentdata, parentdata.ActualCost);
  2164. break;
  2165. }
  2166. $(that).parents('tr').remove();
  2167. });
  2168. dom.find('.glyphicon-arrow-down').off('click').on('click', function () {
  2169. var that = this,
  2170. sGuid = $(that).attr('data-value'),
  2171. iOrderBy = 0;
  2172. if ($(that).hasClass('disabled')) { return; }//如果禁用後就不執行
  2173. $.each(data.FeeItems, function (n, item) {
  2174. if (sGuid === item.guid) {
  2175. iOrderBy = item.OrderBy;
  2176. item.OrderBy++;
  2177. }
  2178. if (iOrderBy !== 0 && iOrderBy === n) {
  2179. item.OrderBy--;
  2180. return false;
  2181. }
  2182. });
  2183. data.FeeItems = Enumerable.From(data.FeeItems).OrderBy("x=>x.OrderBy").ToArray();
  2184. fnBindFeeItem(dom, parentdata, data);
  2185. });
  2186. dom.find('.glyphicon-arrow-up').off('click').on('click', function () {
  2187. var that = this,
  2188. sGuid = $(that).attr('data-value'),
  2189. iOrderBy = Enumerable.From(data.FeeItems).Where(function (e) { return e.guid === sGuid; }).First().OrderBy;
  2190. if ($(that).hasClass('disabled')) { return; }//如果禁用後就不執行
  2191. $.each(data.FeeItems, function (n, item) {
  2192. if (iOrderBy - 2 === n) {
  2193. item.OrderBy++;
  2194. }
  2195. if (sGuid === item.guid) {
  2196. item.OrderBy--;
  2197. return false;
  2198. }
  2199. });
  2200. data.FeeItems = Enumerable.From(data.FeeItems).OrderBy("x=>x.OrderBy").ToArray();
  2201. fnBindFeeItem(dom, parentdata, data);
  2202. });
  2203. },
  2204. /**
  2205. * 添加費用項目
  2206. * @paramthat(Object)當前dom對象
  2207. * @returndata(Object)當前費用項目
  2208. */
  2209. fnPlusFeeItem = function (that, parentdata, feeinfo, currency) {
  2210. var oFinancial = $(that).parents('.financial'),
  2211. oTable = oFinancial.find('tbody'),
  2212. sId = oTable.attr('data-id'),
  2213. sBillNO = oTable.attr('data-billno') || '',
  2214. sMainCurrency = oFinancial.find('[data-id="Currency"]').val() || FeeItemCurrency;
  2215. oTable.find('tr').not('.fee-add').find('.jsgrid-cancel-edit-button').click();
  2216. var fnSum = function () {
  2217. var iPrice = oUnitPrice.val() || 0,
  2218. iNumber = oNumber.val().replaceAll(',', ''),
  2219. iExchangeRate = oExchangeRate.val(),
  2220. sFinancialCurrency = oCurrency.val(),
  2221. iAmount = 0,
  2222. bForn = (currency === undefined || currency === 'NTD');
  2223. bForn = true;
  2224. iPrice = iPrice === '' ? 0 : parseFloat(iPrice);
  2225. iExchangeRate = iExchangeRate === '' ? 1 : parseFloat(iExchangeRate);
  2226. iNumber = iNumber === '' ? 0 : parseFloat(iNumber);
  2227. iAmount = iPrice * iNumber;
  2228. oAmount.attr('data-value', iAmount.toFloat(2)).val(fMoney(iAmount, 2));
  2229. oTWAmount.attr('data-value', (iAmount * iExchangeRate).toFloat(2)).val(fMoney(iAmount * iExchangeRate, 2));
  2230. if (oTaxRate.val()) {
  2231. var iTaxRate = oTaxRate.val().toPoint();
  2232. oTax.attr('data-value', (iAmount * iTaxRate * (bForn ? iExchangeRate : 1)).toFloat(2)).val(fMoney(iAmount * iTaxRate * (bForn ? iExchangeRate : 1), 2));
  2233. }
  2234. },
  2235. oTR_Old = null,
  2236. oTR = $('<tr />', { class: 'jsgrid' }),
  2237. oTD = $('<td />', { class: 'wcenter', 'style': 'padding: 2px !important;' }),
  2238. oCode = $('<select />', {
  2239. class: 'form-control w100p', change: function () {
  2240. var sFeeVal = this.value,
  2241. sFeeText = $(this).find("option:selected").text();
  2242. oCostStatement.val(sFeeText.replace(sFeeVal + '-', '').replace('*', ''));
  2243. if ('TE001,TE199,TE299,TG001,TG199,TG299,SG001,SG199,SG299'.indexOf(sFeeVal) > -1) {
  2244. oCostStatement.removeAttr('disabled');
  2245. }
  2246. else {
  2247. oCostStatement.prop('disabled', true);
  2248. }
  2249. }
  2250. }),
  2251. oCostStatement = $('<input />', { class: 'form-control w100p', 'style': 'width:260px !important;' }),
  2252. oMemo = $('<textarea />', { class: 'form-control w100p', rows: '2', cols: '10' }),
  2253. oCurrency = $('<select />', {
  2254. class: 'form-control w100p', html: sCurrencyOptionsHtml, change: function () {
  2255. var sCurrencyId = this.value;
  2256. if (sCurrencyId) {
  2257. var oCurrency = Enumerable.From(saCurrency).Where(function (e) { return e.id === sCurrencyId; }).First();
  2258. oExchangeRate.val(oCurrency.Correlation || '').change();
  2259. }
  2260. }
  2261. }).css('cssText', 'width:80px !important').val(sMainCurrency),
  2262. oUnitPrice = $('<input />', { class: 'form-control w100p', 'data-type': 'float', 'data-name': 'float', keyup: function () { fnSum(); }, change: function () { fnSum(); } }),
  2263. oNumber = $('<input />', { class: 'form-control w100p', 'data-type': 'float', 'data-name': 'float', keyup: function () { fnSum(); }, change: function () { fnSum(); } }),
  2264. oUnit = $('<input />', { class: 'form-control w100p' }),
  2265. oAmount = $('<input />', { class: 'form-control w100p', 'data-type': 'int', 'data-name': 'int', 'readonly': 'readonly' }),
  2266. oExchangeRate = $('<input />', { class: 'form-control w100p', value: '1.000', keyup: function () { fnSum(); }, change: function () { fnSum(); } }),
  2267. oTWAmount = $('<input />', { class: 'form-control w100p', 'data-type': 'int', 'data-name': 'int', 'readonly': 'readonly' }),
  2268. oTaxRate = $('<input />', { class: 'form-control w100p', keyup: function () { fnSum(); }, change: function () { fnSum(); } }),
  2269. oTax = $('<input />', { class: 'form-control w100p', 'data-type': 'int', 'data-name': 'int', 'readonly': 'readonly' });
  2270. let Selector = feeinfo ? 'oBillPayers-' + feeinfo.guid : 'oBillPayers' ;
  2271. var oBillPayers = $('<select />', { class: 'form-control w100p ' + Selector, 'multiple': 'multiple'});
  2272. var oConfirm = $('<input />', {
  2273. class: 'jsgrid-button jsgrid-update-button', type: 'button', title: i18next.t('common.Confirm'), click: function () {// ╠common.Confirm⇒確認╣
  2274. var sError = '';
  2275. if (!oCode.val()) {
  2276. sError += i18next.t("common.FinancialCode_required") + '<br/>'; // ╠common.FinancialCode_required⇒請選擇費用代號╣
  2277. }
  2278. if (!oCostStatement.val() && !oMemo.val()) {
  2279. sError += i18next.t("common.FinancialCostStatement_required") + '<br/>'; // ╠common.FinancialCostStatement_required⇒請輸入費用說明或備註╣
  2280. }
  2281. if (!oCurrency.val()) {
  2282. sError += i18next.t("common.Currency_required") + '<br/>'; // ╠common.Currency_required⇒請選擇幣別╣
  2283. }
  2284. if (sError) {
  2285. showMsg(sError);
  2286. return false;
  2287. }
  2288. var data = {};
  2289. data.FinancialCode = oCode.val();
  2290. data.FinancialCostStatement = oCostStatement.val();
  2291. data.Memo = oMemo.val();
  2292. data.FinancialCurrency = oCurrency.val();
  2293. data.FinancialUnitPrice = oUnitPrice.val();
  2294. data.FinancialNumber = oNumber.val();
  2295. data.FinancialUnit = oUnit.val();
  2296. data.FinancialAmount = oAmount.val();
  2297. data.FinancialExchangeRate = oExchangeRate.val();
  2298. data.FinancialTWAmount = oTWAmount.val();
  2299. data.FinancialTaxRate = oTaxRate.val() === '' ? 0 : oTaxRate.val();
  2300. data.FinancialTax = oTax.val();
  2301. if (sId === 'actualcost-box') {
  2302. data.BillNO = oBillPayers.val();
  2303. data.BillPayer = oBillPayers.attr('_payer') || '';
  2304. }
  2305. if (data.FinancialNumber.indexOf('.00') > 0)
  2306. data.FinancialNumber = data.FinancialNumber.replace('.00', '');
  2307. switch (sId) {
  2308. case 'quote-box':
  2309. if (feeinfo) {
  2310. $.each(parentdata.Quote.FeeItems, function (idx, item) {
  2311. if (feeinfo.guid === item.guid) {
  2312. data = packParams(data, 'upd');
  2313. $.extend(item, item, data);
  2314. return false;
  2315. }
  2316. });
  2317. }
  2318. else {
  2319. data = packParams(data);
  2320. data.guid = guid();
  2321. parentdata.Quote.FeeItems.push(data);
  2322. }
  2323. fnBindFeeItem(oTable, parentdata, parentdata.Quote);
  2324. break;
  2325. case 'estimatedcost-box':
  2326. if (feeinfo) {
  2327. $.each(parentdata.EstimatedCost.FeeItems, function (idx, item) {
  2328. if (feeinfo.guid === item.guid) {
  2329. data = packParams(data, 'upd');
  2330. $.extend(item, item, data);
  2331. return false;
  2332. }
  2333. });
  2334. }
  2335. else {
  2336. data = packParams(data);
  2337. data.guid = guid();
  2338. parentdata.EstimatedCost.FeeItems.push(data);
  2339. }
  2340. fnBindFeeItem(oTable, parentdata, parentdata.EstimatedCost);
  2341. break;
  2342. case 'bill_fees_' + sBillNO:
  2343. $.each(parentdata.Bills, function (idx, bill) {
  2344. if (sBillNO === bill.BillNO) {
  2345. if (feeinfo) {
  2346. $.each(bill.FeeItems, function (idx, item) {
  2347. if (feeinfo.guid === item.guid) {
  2348. data = packParams(data, 'upd');
  2349. $.extend(item, item, data);
  2350. return false;
  2351. }
  2352. });
  2353. }
  2354. else {
  2355. data = packParams(data);
  2356. data.guid = guid();
  2357. bill.FeeItems.push(data);
  2358. }
  2359. fnBindFeeItem(oTable, parentdata, bill);
  2360. return false;
  2361. }
  2362. });
  2363. break;
  2364. case 'actualcost-box':
  2365. if (feeinfo) {
  2366. $.each(parentdata.ActualCost.FeeItems, function (idx, item) {
  2367. if (feeinfo.guid === item.guid) {
  2368. data = packParams(data, 'upd');
  2369. $.extend(item, item, data);
  2370. return false;
  2371. }
  2372. });
  2373. }
  2374. else {
  2375. data = packParams(data);
  2376. data.guid = guid();
  2377. parentdata.ActualCost.FeeItems.push(data);
  2378. }
  2379. fnBindFeeItem(oTable, parentdata, parentdata.ActualCost);
  2380. break;
  2381. }
  2382. bRequestStorage = true;
  2383. oTR.remove();
  2384. }
  2385. }),
  2386. oCancel = $('<input />', {
  2387. class: 'jsgrid-button jsgrid-cancel-edit-button', type: 'button', title: i18next.t('common.Cancel'), click: function () {// ╠common.Cancel⇒取消╣
  2388. if (feeinfo) {
  2389. if (feeinfo.BillNO) {
  2390. oTR_Old.find('select').val(feeinfo.BillNO);
  2391. }
  2392. oTR.after(oTR_Old).remove();
  2393. oTR_Old = null;
  2394. }
  2395. else {
  2396. oTR.remove();
  2397. $(that).prop('disabled', false);
  2398. }
  2399. }
  2400. });
  2401. oTR.append(oTD.clone());
  2402. oTR.append(oTD.clone().append(oCode));
  2403. oTR.append(oTD.clone().append([oCostStatement, oMemo]));
  2404. oTR.append(oTD.clone().append(oCurrency));
  2405. oTR.append(oTD.clone().append(oUnitPrice));
  2406. oTR.append(oTD.clone().append(oNumber));
  2407. oTR.append(oTD.clone().append(oUnit));
  2408. oTR.append(oTD.clone().append(oAmount));
  2409. oTR.append(oTD.clone().append(oExchangeRate));
  2410. oTR.append(oTD.clone().append(oTWAmount));
  2411. oTR.append(oTD.clone().append(oTaxRate));
  2412. oTR.append(oTD.clone().append(oTax));
  2413. if (sId === 'actualcost-box') {
  2414. var saBillPayers = function () {
  2415. var saRetn = [];
  2416. $.each(parentdata.Bills, function (idx, bill) {
  2417. if (!bill.VoidReason) {
  2418. var sPayer = '',
  2419. oCur = {};
  2420. if (bill.Payer) {
  2421. oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === bill.Payer; }).First();
  2422. }
  2423. saRetn.push({
  2424. id: bill.BillNO,
  2425. text: oCur.text,
  2426. val: bill.BillNO + '-' + (oCur.text || '') + '-' + bill.BillCreateDate
  2427. });
  2428. }
  2429. });
  2430. return saRetn;
  2431. }();
  2432. oTR.append(oTD.clone().append(oBillPayers.html(createOptions(saBillPayers, 'id', 'id', false)).change(function () {
  2433. var sBill = this.value;
  2434. if (sBill) {
  2435. var oBillPayer = Enumerable.From(saBillPayers).Where(function (e) { return e.id === sBill; }).First();
  2436. $(this).attr('_payer', oBillPayer.val || '');
  2437. }
  2438. else {
  2439. $(this).attr('_payer', '');
  2440. }
  2441. })));
  2442. }
  2443. oTR.append(oTD.clone().css('cssText', 'padding-top:30px !important;').append([oConfirm, oCancel]));
  2444. oCode.html(createOptions(saFeeClass, 'id', 'text', true)).val(!feeinfo ? '' : feeinfo.FinancialCode).select2({ width: '160px' });
  2445. if (parent.SysSet.TaxRate) {
  2446. oTaxRate.val(parent.SysSet.TaxRate);
  2447. }
  2448. if (feeinfo) {
  2449. oCode.val(feeinfo.FinancialCode);
  2450. oCostStatement.val(feeinfo.FinancialCostStatement.replace(feeinfo.FinancialCode + '-', ''));
  2451. oMemo.val(feeinfo.Memo);
  2452. oCurrency.val(feeinfo.FinancialCurrency);
  2453. oUnitPrice.val(feeinfo.FinancialUnitPrice);
  2454. oNumber.val(feeinfo.FinancialNumber);
  2455. oUnit.val(feeinfo.FinancialUnit);
  2456. oAmount.val(feeinfo.FinancialAmount);
  2457. oExchangeRate.val(feeinfo.FinancialExchangeRate);
  2458. oTWAmount.val(feeinfo.FinancialTWAmount);
  2459. oTaxRate.val(feeinfo.FinancialTaxRate);
  2460. oTax.val(feeinfo.FinancialTax);
  2461. if (sId === 'actualcost-box') {
  2462. oBillPayers.val(feeinfo.BillNO);
  2463. }
  2464. oTR_Old = $(that).parents('tr').clone(true);
  2465. $(that).parents('tr').after(oTR).remove();
  2466. if ('TE001,TE199,TE299,TG001,TG199,TG299,SG001,SG199,SG299'.indexOf(feeinfo.FinancialCode) > -1) {
  2467. oCostStatement.prop('disabled', false);
  2468. }
  2469. else {
  2470. oCostStatement.prop('disabled', true);
  2471. }
  2472. }
  2473. else {
  2474. oTable.append(oTR.addClass('fee-add'));
  2475. $(that).prop('disabled', true);
  2476. }
  2477. moneyInput($('[data-type="int"]'), 2, true);
  2478. oTR.find('.' + Selector + ' option:first').remove();
  2479. if (sId === 'actualcost-box')
  2480. {
  2481. let mySelect = new vanillaSelectBox("." + Selector, {
  2482. search: true
  2483. });
  2484. mySelect.multipleSize = 2;
  2485. if (feeinfo) {
  2486. mySelect.setValue(feeinfo.BillNO);
  2487. }
  2488. }
  2489. },
  2490. /**
  2491. * 批次添加費用項目&收藏
  2492. * @param that(Object)當前dom對象
  2493. * @return data(Object)當前費用項目
  2494. */
  2495. fnPlusFeeItemStar = function (that, handle, parentdata) {
  2496. var oFinancial = $(that).parents('.financial'),
  2497. oTable = oFinancial.find('tbody'),
  2498. sId = oTable.attr('data-id'),
  2499. sBillNO = oTable.attr('data-billno') || '',
  2500. oOption = {};
  2501. oOption.Callback = function (data) {
  2502. if (data.length > 0) {
  2503. parentdata.Quote.FeeItems = clone(data);
  2504. fnBindFeeItem(handle, parentdata, parentdata.Quote);
  2505. $(that).prev().prop('disabled', false);
  2506. }
  2507. };
  2508. fnStarFeeItems(oOption);
  2509. },
  2510. /**
  2511. * 匯入費用項目
  2512. * @paramthat(Object)當前dom對象
  2513. * @returndata(Object)當前費用項目
  2514. */
  2515. fnImportFeeitems = function (type, parentdom, parentdata) {
  2516. $('#importfile').val('').off('change').on('change', function () {
  2517. if (this.value.indexOf('.xls') > -1 || this.value.indexOf('.xlsx') > -1) {
  2518. var sFileId = guid(),
  2519. sFileName = this.value;
  2520. $.ajaxFileUpload({
  2521. url: '/Controller.ashx?action=importfile&FileId=' + sFileId,
  2522. secureuri: false,
  2523. fileElementId: 'importfile',
  2524. success: function (data, status) {
  2525. var that = this;
  2526. g_api.ConnectLite('Exhibition', 'GetImportFeeitems', {//匯入費用項目
  2527. OrgID: parent.OrgID,
  2528. FileId: sFileId,
  2529. FileName: sFileName
  2530. }, function (res) {
  2531. if (res.RESULT) {
  2532. if (res.DATA.rel.length > 0) {
  2533. if (type === 'quote') {
  2534. parentdata.Quote.FeeItems = res.DATA.rel;
  2535. fnBindFeeItem(parentdom.find('[data-id="quote-box"]'), parentdata, parentdata.Quote);
  2536. }
  2537. else if (type === 'estimatedcost') {
  2538. parentdata.EstimatedCost.FeeItems = res.DATA.rel;
  2539. fnBindFeeItem(parentdom.find('[data-id="estimatedcost-box"]'), parentdata, parentdata.EstimatedCost);
  2540. }
  2541. else if (type === 'actualcost') {
  2542. parentdata.ActualCost.FeeItems = res.DATA.rel;
  2543. fnBindFeeItem(parentdom.find('[data-id="actualcost-box"]'), parentdata, parentdata.ActualCost);
  2544. }
  2545. }
  2546. else {
  2547. showMsg(i18next.t("message.NoMatchData")); // ╠message.NoMatchData⇒找不到相關資料╣
  2548. }
  2549. }
  2550. else {
  2551. showMsg(i18next.t('message.ProgressError') + '<br>' + res.MSG, 'error'); // ╠message.ProgressError⇒資料處理異常╣
  2552. }
  2553. }, function () {
  2554. showMsg(i18next.t("message.ProgressError"), 'error'); // ╠message.ProgressError⇒資料處理異常╣
  2555. });
  2556. },
  2557. error: function (data, status, e) {
  2558. showMsg(i18next.t("message.ProgressError"), 'error'); // ╠message.ProgressError⇒資料處理異常╣
  2559. }
  2560. });
  2561. bRequestStorage = true;
  2562. }
  2563. else {
  2564. showMsg(i18next.t("message.FileTypeError"), 'error'); // ╠message.FileTypeError⇒文件格式錯誤╣
  2565. }
  2566. }).click();
  2567. },
  2568. /**
  2569. * 複製費用項目
  2570. * @param that(Object)當前dom對象
  2571. * @return quote(Object)當前費用項目
  2572. */
  2573. fnCopyFeeitems = function (type, parentdom, parentdata) {
  2574. var oOption = {};
  2575. oOption.Callback = function (data) {
  2576. if (data.length > 0) {
  2577. $.each(data, function (idx, item) {
  2578. item.FinancialUnitPrice = 0;
  2579. item.FinancialNumber = 0;
  2580. item.FinancialAmount = 0;
  2581. item.FinancialTWAmount = 0;
  2582. item.FinancialTaxRate = '0%';
  2583. item.FinancialTax = 0;
  2584. item.CreateUser = parent.UserID;
  2585. item.CreateDate = newDate(null, true);
  2586. });
  2587. if (type === 'quote') {
  2588. parentdata.Quote.FeeItems = data;
  2589. fnBindFeeItem(parentdom.find('[data-id="quote-box"]'), parentdata, parentdata.Quote);
  2590. }
  2591. }
  2592. };
  2593. fnCopyFee(oOption);
  2594. },
  2595. /**
  2596. * 添加新帳單
  2597. * @param:supplier(object) 廠商資料
  2598. */
  2599. fnPushBill = function (supplier, data, parentid, bRetn) {
  2600. var fnBill = function (billno) {
  2601. var oNewBill = {};
  2602. oNewBill.guid = guid();
  2603. oNewBill.IsRetn = bRetn ? 'Y' : 'N';
  2604. oNewBill.parentid = parentid || '';
  2605. oNewBill.KeyName = 'Bill';
  2606. oNewBill.AuditVal = '0';
  2607. oNewBill.BillNO = billno;
  2608. oNewBill.BillCreateDate = newDate();
  2609. oNewBill.BillFirstCheckDate = '';
  2610. oNewBill.BillCheckDate = '';
  2611. oNewBill.Currency = 'NTD';
  2612. oNewBill.ExchangeRate = 1;
  2613. if (bRetn) {
  2614. var sRtnQuotationOrBillingCurrency = $('#ReturnQuotationOrBillingCurrency-' + parentid + ' option:selected');
  2615. oNewBill.ExchangeRate = sRtnQuotationOrBillingCurrency.attr('Correlation');
  2616. oNewBill.Currency = sRtnQuotationOrBillingCurrency.val();
  2617. }
  2618. else {
  2619. var sQuotationOrBillingCurrency = $('#QuotationOrBillingCurrency option:selected');
  2620. oNewBill.ExchangeRate = sQuotationOrBillingCurrency.attr('Correlation');
  2621. oNewBill.Currency = sQuotationOrBillingCurrency.val();
  2622. }
  2623. oNewBill.Advance = 0;
  2624. oNewBill.Memo = data.Quote.Memo || '';
  2625. oNewBill.FeeItems = clone(data.Quote.FeeItems);
  2626. oNewBill.InvoiceNumber = '';
  2627. oNewBill.InvoiceDate = '';
  2628. oNewBill.ReceiptNumber = '';
  2629. oNewBill.ReceiptDate = '';
  2630. oNewBill.SupplierGuid = supplier.guid;
  2631. oNewBill.Payer = supplier.SupplierID;
  2632. oNewBill.Number = '';
  2633. oNewBill.Unit = '';
  2634. oNewBill.Weight = '';
  2635. oNewBill.Volume = '';
  2636. oNewBill.CustomerGuid = supplier.SupplierID;
  2637. oNewBill.CustomerCode = supplier.CustomerNO;
  2638. oNewBill.UniCode = supplier.UniCode;
  2639. oNewBill.SupplierName = supplier.SupplierName;
  2640. oNewBill.SupplierEName = supplier.SupplierEName;
  2641. oNewBill.RefNumber = supplier.RefSupplierNo;
  2642. oNewBill.Contactor = supplier.Contactor;
  2643. oNewBill.ContactorName = supplier.ContactorName;
  2644. oNewBill.Telephone = supplier.Telephone || '';
  2645. oNewBill.Email = supplier.Email;
  2646. oNewBill.ReFlow = bRetn ? 'ReImport' : '';
  2647. data.Bills.push(oNewBill);
  2648. if (!bRetn) {
  2649. supplier.BillNO = billno;
  2650. }
  2651. };
  2652. return g_api.ConnectLite(Service.com, ComFn.GetSerial, {
  2653. Type: parent.UserInfo.OrgID + 'E',
  2654. Flag: 'MinYear',
  2655. Len: 3,
  2656. Str: sServiceCode,
  2657. AddType: sServiceCode,
  2658. PlusType: ''
  2659. }, function (res) {
  2660. if (res.RESULT) {
  2661. fnBill(res.DATA.rel);
  2662. }
  2663. else {
  2664. showMsg(i18next.t('message.CreateBill_Failed') + '<br>' + res.MSG, 'error'); // ╠message.CreateBill_Failed⇒帳單新增失敗╣
  2665. }
  2666. }, function () {
  2667. showMsg(i18next.t('message.CreateBill_Failed'), 'error'); // ╠message.CreateBill_Failed⇒帳單新增失敗╣
  2668. });
  2669. },
  2670. /**
  2671. * 初始化:報價/帳單幣別匯率
  2672. */
  2673. fnInitialAccountCurrency = function (tabName) {
  2674. $('#QuotationOrBillingCurrency').html(sAccountingCurrencyOptionsHtml).on('change', function () {
  2675. var sQuotationOrBillingCurrency = $('#QuotationOrBillingCurrency option:selected');
  2676. var sExchangeRate = sQuotationOrBillingCurrency.attr('Correlation');
  2677. var fExchangeRate = parseFloat(sExchangeRate);
  2678. let CurrencyID = this.value;
  2679. oCurData.Quote.QuotationOrBillingCurrency = CurrencyID;
  2680. oCurData.Quote.AccountingExchangeRate = sExchangeRate;
  2681. $('#AccountingExchangeRate').val(sExchangeRate);
  2682. bRequestStorage = true;//要變更儲存
  2683. //是主幣別(TE、TG:NTD;SG:CNY),僅顯示主幣別資訊。
  2684. var MainCurrency = fnCheckMainOrForeignCurrency(CurrencyID);
  2685. var TitleAttr = '';
  2686. if (MainCurrency) {
  2687. TitleAttr = 'common.MainCurrencyNontaxedAmountV2';
  2688. $(tabName + ' .QuotationForeignCurrency').hide();
  2689. }
  2690. else {
  2691. TitleAttr = 'common.ForeignCurrencyNontaxedAmountV2';
  2692. $(tabName + ' .QuotationForeignCurrency').show();
  2693. }
  2694. $(tabName + ' .QuotationAmountTiltle').attr('data-i18n', TitleAttr).text(i18next.t(TitleAttr));
  2695. //重算
  2696. fnCalcuQuotationFee($('.QuotationForeignCurrency'), $('.QuotationMainCurrency'), CurrencyID, fExchangeRate);
  2697. });
  2698. $('#QuotationOrBillingCurrency').val(oCurData.Quote.QuotationOrBillingCurrency);
  2699. $('#AccountingExchangeRate').val(oCurData.Quote.AccountingExchangeRate);
  2700. $('#QuotationOrBillingCurrency').change();
  2701. },
  2702. /**
  2703. * 初始化:退運報價/帳單幣別匯率
  2704. */
  2705. fnInitialReturnAccountCurrency = function (tabName, Guid) {
  2706. $('#ReturnQuotationOrBillingCurrency' + Guid).html(sAccountingCurrencyOptionsHtml).on('change', function () {
  2707. var sRtnQuotationOrBillingCurrency = $('#ReturnQuotationOrBillingCurrency' + Guid + ' option:selected');
  2708. var sCurrencyID = this.value;
  2709. var sExchangeRate = sRtnQuotationOrBillingCurrency.attr('Correlation');
  2710. var fExchangeRate = parseFloat(sExchangeRate);
  2711. $('#ReturnAccountingExchangeRate' + Guid).val(sExchangeRate);
  2712. bRequestStorage = true;//要變更儲存
  2713. var MainCurrency = fnCheckMainOrForeignCurrency(this.value);
  2714. var TitleAttr = '';
  2715. if (MainCurrency) {
  2716. TitleAttr = 'common.MainCurrencyNontaxedAmountV2';
  2717. $(tabName + ' .ReturnQuotationForeignCurrency').hide();
  2718. }
  2719. else {
  2720. TitleAttr = 'common.ForeignCurrencyNontaxedAmountV2';
  2721. $(tabName + ' .ReturnQuotationForeignCurrency').show();
  2722. }
  2723. $(tabName + ' .ReturnQuotationAmountTiltle' + Guid).attr('data-i18n', TitleAttr).text(i18next.t(TitleAttr));
  2724. //儲存資料(forJson)
  2725. $.each(oCurData.ReturnBills, function (idx, item) {
  2726. if (Guid.indexOf(item.guid) > -1) {
  2727. item.ReturnQuotationOrBillingCurrency = sCurrencyID;
  2728. item.ReturnAccountingExchangeRate = sExchangeRate;
  2729. }
  2730. });
  2731. //重算價格
  2732. fnCalcuQuotationFee($(tabName + ' .ReturnQuotationForeignCurrency'), $(tabName + ' .ReturnQuotationMainCurrency'), sCurrencyID, fExchangeRate);
  2733. });
  2734. //loading data
  2735. $.each(oCurData.ReturnBills, function (idx, item) {
  2736. var SuffixSelector = '-' + item.guid;
  2737. $(tabName + ' #ReturnQuotationOrBillingCurrency' + SuffixSelector).val(item.ReturnQuotationOrBillingCurrency);
  2738. $(tabName + ' #ReturnAccountingExchangeRate' + SuffixSelector).val(item.ReturnAccountingExchangeRate);
  2739. $(tabName + ' #ReturnQuotationOrBillingCurrency' + SuffixSelector).change();
  2740. });
  2741. },
  2742. /**
  2743. * 綁定會計區塊
  2744. */
  2745. fnBindFinancial = function () {
  2746. fnBindFeeItem($('#tab3 [data-id="quote-box"]'), oCurData, oCurData.Quote);//綁定報價
  2747. fnBindFeeItem($('#tab3 [data-id="estimatedcost-box"]'), oCurData, oCurData.EstimatedCost);//綁定預估成本
  2748. if (oCurData.EstimatedCost.AuditVal && oCurData.EstimatedCost.AuditVal === '2') {//業務審核完
  2749. fnBindFeeItem($('#tab4 [data-id="actualcost-pre-box"]'), oCurData, oCurData.EstimatedCost, true);
  2750. $('#tab4 .estimatedcost-memo').text(oCurData.EstimatedCost.Memo || '');
  2751. }
  2752. fnBindFeeItem($('#tab4 [data-id="actualcost-box"]'), oCurData, oCurData.ActualCost);//實際成本
  2753. fnInitialAccountCurrency('#tab3');//會計用匯率
  2754. $('#tab3 [data-source="quote"]').text(oCurData.Quote.Memo || '');
  2755. $('#tab3 [data-source="estimatedcost"]').text(oCurData.EstimatedCost.Memo || '');
  2756. $('#tab4 [data-source="actualcost"]').text(oCurData.ActualCost.Memo || '');
  2757. $('#tab3 .plusfeeitem,#tab4 .plusfeeitem').not('disabled').off('click').on('click', function () {
  2758. fnPlusFeeItem(this, oCurData);
  2759. });
  2760. $('#tab3 .importfeeitem').not('disabled').off('click').on('click', function () {
  2761. var sType = $(this).attr('data-type');
  2762. fnImportFeeitems(sType, $('#tab3'), oCurData);
  2763. });
  2764. $('#tab4 .importfeeitem').not('disabled').off('click').on('click', function () {
  2765. var sType = $(this).attr('data-type');
  2766. fnImportFeeitems(sType, $('#tab4'), oCurData);
  2767. });
  2768. $('#tab3 .copyfeeitem').not('disabled').off('click').on('click', function () {
  2769. var sType = $(this).attr('data-type');
  2770. fnCopyFeeitems(sType, $('#tab3'), oCurData);
  2771. });
  2772. $('#tab3 .plusfeeitemstar').not('disabled').off('click').on('click', function () {
  2773. fnPlusFeeItemStar(this, $('#tab3').find('[data-id="quote-box"]'), oCurData);
  2774. });
  2775. $('#tab3 #estimated_submitaudit').not('disabled').off('click').on('click', function () {
  2776. if (oCurData.EstimatedCost.FeeItems.length === 0 && !oCurData.EstimatedCost.Memo) {
  2777. showMsg(i18next.t("message.EstimatedCostMemo_Required")); // ╠message.EstimatedCostMemo_Required⇒預估成本沒有費用明細,請至少填寫備註╣
  2778. return false;
  2779. }
  2780. if (!oCurData.Quote.QuotationOrBillingCurrency || !oCurData.Quote.AccountingExchangeRate) {
  2781. showMsg(i18next.t("message.QuotationOrBillingCurrencyField_Required")); // ╠message.QuotationOrBillingCurrencyField_Required⇒報價/帳單幣或匯率未選擇╣
  2782. return false;
  2783. }
  2784. oCurData.Quote.AuditVal = '1';
  2785. oCurData.EstimatedCost.AuditVal = '1';
  2786. g_api.ConnectLite(sProgramId, 'ToAuditForQuote', {
  2787. ExportBillNO: sDataId,
  2788. Quote: oCurData.Quote,
  2789. EstimatedCost: oCurData.EstimatedCost
  2790. }, function (res) {
  2791. if (res.RESULT) {
  2792. fnSetDisabled($('#tab3 .quoteandprecost'), oCurData.Quote);
  2793. showMsg(i18next.t("message.ToAudit_Success"), 'success'); // ╠message.ToAudit_Success⇒提交審核成功╣
  2794. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  2795. }
  2796. else {
  2797. oCurData.Quote.AuditVal = '0';
  2798. oCurData.EstimatedCost.AuditVal = '0';
  2799. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  2800. }
  2801. }, function () {
  2802. oCurData.Quote.AuditVal = '0';
  2803. oCurData.EstimatedCost.AuditVal = '0';
  2804. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  2805. });
  2806. });
  2807. $('#tab3 #estimated_audit').not('disabled').off('click').on('click', function () {
  2808. layer.open({
  2809. type: 1,
  2810. title: i18next.t('common.Leader_Audit'),// ╠common.Leader_Audit⇒主管審核╣
  2811. area: ['400px', '260px'],//寬度
  2812. shade: 0.75,//遮罩
  2813. shadeClose: true,
  2814. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣ ╠common.Pass⇒通過╣ ╠common.NotPass⇒不通過╣
  2815. content: '<div class="pop-box">\
  2816. <textarea name="NotPassReason" id="NotPassReason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.NotPassReason" placeholder="不通過原因..."></textarea><br>\
  2817. <button type="button" data-i18n="common.Pass" id="audit_pass" class="btn-custom green">通過</button>\
  2818. <button type="button" data-i18n="common.NotPass" id="audit_notpass" class="btn-custom red">不通過</button>\
  2819. </div>',
  2820. success: function (layero, idx) {
  2821. $('.pop-box :button').click(function () {
  2822. var sNotPassReason = $('#NotPassReason').val();
  2823. if (this.id === 'audit_pass') {
  2824. oCurData.Quote.AuditVal = '2';
  2825. oCurData.EstimatedCost.AuditVal = '2';
  2826. oCurData.Quote.NotPassReason = '';
  2827. oCurData.EstimatedCost.NotPassReason = '';
  2828. }
  2829. else {
  2830. if (!sNotPassReason) {
  2831. showMsg(i18next.t("message.NotPassReason_Required")); // ╠message.NotPassReason_Required⇒請填寫不通過原因╣
  2832. return false;
  2833. }
  2834. else {
  2835. oCurData.Quote.AuditVal = '3';
  2836. oCurData.EstimatedCost.AuditVal = '3';
  2837. oCurData.Quote.NotPassReason = sNotPassReason;
  2838. oCurData.EstimatedCost.NotPassReason = sNotPassReason;
  2839. }
  2840. }
  2841. g_api.ConnectLite(sProgramId, 'AuditForQuote', {
  2842. ExportBillNO: sDataId,
  2843. Quote: oCurData.Quote,
  2844. EstimatedCost: oCurData.EstimatedCost,
  2845. Bills: oCurData.Bills
  2846. }, function (res) {
  2847. if (res.RESULT) {
  2848. showMsg(i18next.t("message.Audit_Completed"), 'success'); // ╠message.Audit_Completed⇒審核完成╣
  2849. if (oCurData.Quote.AuditVal === '2') {
  2850. var oTable2 = $('#tab4 [data-id="actualcost-pre-box"]');
  2851. fnBindFeeItem(oTable2, oCurData, oCurData.EstimatedCost, true);
  2852. $('#tab4 .estimatedcost-memo').text(oCurData.EstimatedCost.Memo || '');
  2853. }
  2854. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  2855. fnSetDisabled($('#tab3 .quoteandprecost'), oCurData.Quote);
  2856. }
  2857. else {
  2858. oCurData.Quote.AuditVal = '1';
  2859. oCurData.EstimatedCost.AuditVal = '1';
  2860. showMsg(i18next.t('message.Audit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  2861. }
  2862. }, function () {
  2863. oCurData.Quote.AuditVal = '1';
  2864. oCurData.EstimatedCost.AuditVal = '1';
  2865. showMsg(i18next.t('message.Audit_Failed'), 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  2866. });
  2867. layer.close(idx);
  2868. });
  2869. transLang(layero);
  2870. }
  2871. });
  2872. });
  2873. $('#tab3 #estimated_synquote').not('disabled').off('click').on('click', function () {
  2874. oCurData.EstimatedCost.FeeItems = clone(oCurData.Quote.FeeItems);
  2875. $.each(oCurData.EstimatedCost.FeeItems, function (idx, item) {
  2876. //item.FinancialUnitPrice = 0;
  2877. //item.FinancialNumber = 0;
  2878. //item.FinancialAmount = 0;
  2879. //item.FinancialTWAmount = 0;
  2880. //item.FinancialTaxRate = '0%';
  2881. //item.FinancialTax = 0;
  2882. item.CreateUser = parent.UserID;
  2883. item.CreateDate = newDate(null, true);
  2884. });
  2885. fnBindFeeItem($('#tab3').find('[data-id="estimatedcost-box"]'), oCurData, oCurData.EstimatedCost);
  2886. });
  2887. fnBindBillLists();
  2888. },
  2889. /**
  2890. * 獲取收據號碼
  2891. * @param btn(object)產生收據號碼按鈕
  2892. * @return bill(object)當前帳單資料
  2893. */
  2894. fnGetReceiptNumber = function (btn, bill) {
  2895. return g_api.ConnectLite(Service.com, ComFn.GetSerial, {
  2896. Type: 'SE',
  2897. Flag: 'MinYear',
  2898. Len: 6,
  2899. Str: '',
  2900. AddType: '',
  2901. PlusType: ''
  2902. }, function (res) {
  2903. if (res.RESULT) {
  2904. var oBillBox = $(btn).parents('.bill-box-' + bill.BillNO);
  2905. bill.ReceiptNumber = res.DATA.rel;
  2906. bill.ReceiptDate = newDate(null, true);
  2907. oBillBox.find('[data-id="ReceiptNumber"]').val(bill.ReceiptNumber);
  2908. oBillBox.find('[data-id="ReceiptDate"]').val(bill.ReceiptDate);
  2909. $(btn).remove();
  2910. }
  2911. else {
  2912. showMsg(i18next.t('message.CreateReceiptNumber_Failed') + '<br>' + res.MSG, 'error'); // ╠message.CreateReceiptNumber_Failed⇒收據號碼產生失敗╣
  2913. }
  2914. }, function () {
  2915. showMsg(i18next.t('message.CreateReceiptNumber_Failed'), 'error'); // ╠message.CreateReceiptNumber_Failed⇒收據號碼產生失敗╣
  2916. });
  2917. },
  2918. /**
  2919. * 帳單提交審核
  2920. * @param bill(object)帳單資料
  2921. */
  2922. fnBillToAudit = function (bill, el) {
  2923. var sMsg = '',
  2924. elBillBox = $(el).parents('.financial');
  2925. if (!bill.Currency) {
  2926. sMsg += i18next.t("ExhibitionImport_Upd.Currency_required") + '<br/>'; // ╠common.Currency_required⇒請輸入帳單幣別╣
  2927. }
  2928. if (!bill.Payer) {
  2929. sMsg += i18next.t("ExhibitionImport_Upd.Payer_required") + '<br/>'; // ╠ExhibitionImport_Upd.SupplierEamil_required⇒請輸入付款人╣
  2930. }
  2931. if (!bill.Number) {
  2932. sMsg += i18next.t("message.Number_required") + '<br/>'; // ╠message.Number_required⇒請輸入件數╣
  2933. }
  2934. if (!bill.Weight) {
  2935. sMsg += i18next.t("message.Weight_required") + '<br/>'; // ╠message.Weight_required⇒請輸入重量╣
  2936. }
  2937. if (!bill.Volume) {
  2938. sMsg += i18next.t("message.Volume_required") + '<br/>'; // ╠message.Volume_required⇒請輸入材積(CBM)╣
  2939. }
  2940. if (elBillBox.find('.jsgrid-update-button').length > 0) {
  2941. sMsg += i18next.t("message.DataEditing") + '<br/>'; // ╠message.DataEditing⇒該賬單處於編輯中╣
  2942. }
  2943. if (sMsg) {
  2944. showMsg(sMsg); // 必填欄位
  2945. return;
  2946. }
  2947. bill.AuditVal = '1';
  2948. g_api.ConnectLite(sProgramId, 'ToAuditForBill', {
  2949. ExportBillNO: sDataId,
  2950. Exhibitors: saGridData,
  2951. Bills: oCurData.Bills,
  2952. Bill: bill
  2953. }, function (res) {
  2954. if (res.RESULT) {
  2955. fnSetDisabled($('.bill-box-' + bill.BillNO).parents('.financial'), bill);
  2956. showMsg(i18next.t("message.ToAudit_Success"), 'success'); // ╠message.ToAudit_Success⇒提交審核成功╣
  2957. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  2958. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  2959. }
  2960. else {
  2961. bill.AuditVal = '0';
  2962. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  2963. }
  2964. }, function () {
  2965. bill.AuditVal = '0';
  2966. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  2967. });
  2968. },
  2969. /**
  2970. * 帳單審核
  2971. * @param bill(object)帳單資料
  2972. */
  2973. fnBillAudit = function (bill) {
  2974. layer.open({
  2975. type: 1,
  2976. title: i18next.t('common.Leader_Audit'),// ╠common.Leader_Audit⇒主管審核╣
  2977. area: ['400px', '260px'],//寬度
  2978. shade: 0.75,//遮罩
  2979. shadeClose: true,
  2980. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  2981. content: '<div class="pop-box">\
  2982. <textarea name="NotPassReason" id="NotPassReason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.NotPassReason" placeholder="不通過原因..."></textarea><br>\
  2983. <button type="button" data-i18n="common.Pass" id="audit_pass" class="btn-custom green">通過</button>\
  2984. <button type="button" data-i18n="common.NotPass" id="audit_notpass" class="btn-custom red">不通過</button>\
  2985. </div>',
  2986. success: function (layero, idx) {
  2987. $('.pop-box :button').click(function () {
  2988. var sNotPassReason = $('#NotPassReason').val();
  2989. if (this.id === 'audit_pass') {
  2990. bill.AuditVal = '2';
  2991. bill.NotPassReason = '';
  2992. }
  2993. else {
  2994. if (!sNotPassReason) {
  2995. showMsg(i18next.t("message.NotPassReason_Required")); // ╠message.NotPassReason_Required⇒請填寫不通過原因╣
  2996. return false;
  2997. }
  2998. else {
  2999. bill.AuditVal = '3';
  3000. bill.NotPassReason = sNotPassReason;
  3001. }
  3002. }
  3003. bill.BillCheckDate = newDate();
  3004. bill.CreateDate = newDate();
  3005. if (!bill.BillFirstCheckDate) {
  3006. bill.BillFirstCheckDate = bill.BillCheckDate;
  3007. }
  3008. g_api.ConnectLite(sProgramId, 'AuditForBill', {
  3009. ExportBillNO: sDataId,
  3010. Bills: oCurData.Bills,
  3011. Bill: bill
  3012. }, function (res) {
  3013. if (res.RESULT) {
  3014. $('.bill-box-' + bill.BillNO).find('.bill-chewckdate').text(bill.BillCheckDate);
  3015. fnSetDisabled($('.bill-box-' + bill.BillNO).parents('.financial'), bill);
  3016. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3017. showMsg(i18next.t("message.Audit_Completed"), 'success'); // ╠message.Audit_Completed⇒審核完成╣
  3018. if (bill.AuditVal === '2') {
  3019. parent.msgs.server.pushTransfer(parent.OrgID, parent.UserID, bill.BillNO, 1);
  3020. }
  3021. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3022. }
  3023. else {
  3024. bill.AuditVal = '1';
  3025. if (bill.BillCheckDate === bill.BillFirstCheckDate) {
  3026. bill.BillFirstCheckDate = '';
  3027. }
  3028. bill.BillCheckDate = '';
  3029. showMsg(i18next.t('message.Audit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  3030. }
  3031. }, function () {
  3032. bill.AuditVal = '1';
  3033. if (bill.BillCheckDate === bill.BillFirstCheckDate) {
  3034. bill.BillFirstCheckDate = '';
  3035. }
  3036. bill.BillCheckDate = '';
  3037. showMsg(i18next.t('message.Audit_Failed'), 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  3038. });
  3039. layer.close(idx);
  3040. });
  3041. transLang(layero);
  3042. }
  3043. });
  3044. },
  3045. /**
  3046. * 會計取消審核
  3047. * @param bill(object)帳單資料
  3048. */
  3049. fnBillCancelAudit = function (bill) {
  3050. var sBillCheckDate = bill.BillCheckDate;
  3051. bill.AuditVal = '0';
  3052. bill.BillCheckDate = '';
  3053. g_api.ConnectLite(sProgramId, 'CancelAudit', {
  3054. ExportBillNO: sDataId,
  3055. Bills: oCurData.Bills,
  3056. Bill: bill,
  3057. LogData: fnGetBillLogData(bill)
  3058. }, function (res) {
  3059. if (res.RESULT) {
  3060. $('.bill-box-' + bill.BillNO).find('.bill-chewckdate').text('');
  3061. fnSetDisabled($('.bill-box-' + bill.BillNO).parents('.financial'), bill);
  3062. showMsg(i18next.t("message.CancelAudit_Success"), 'success'); // ╠message.CancelAudit_Success⇒取消審核完成╣
  3063. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3064. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3065. }
  3066. else {
  3067. bill.AuditVal = '2';
  3068. bill.BillCheckDate = sBillCheckDate;
  3069. showMsg(i18next.t('message.CancelAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.CancelAudit_Failed⇒取消審核失敗╣
  3070. }
  3071. }, function () {
  3072. bill.AuditVal = '2';
  3073. bill.BillCheckDate = sBillCheckDate;
  3074. showMsg(i18next.t('message.CancelAudit_Failed'), 'error'); // ╠message.CancelAudit_Failed⇒取消審核失敗╣
  3075. });
  3076. },
  3077. /**
  3078. * 列印事件
  3079. * @paramtemplid (string) 模版id
  3080. * @paramaction (string) 動作標識
  3081. * @parambill (objec) 帳單資料
  3082. */
  3083. fnPrint = function (templid, action, bill) {
  3084. var bReceipt = action.indexOf('Receipt') > -1,
  3085. fnToPrint = function (idx, paydatetext) {
  3086. g_api.ConnectLite(sProgramId, bReceipt ? 'PrintReceipt' : 'PrintBill', {
  3087. ExportBillNO: sDataId,
  3088. TemplID: templid,
  3089. Bill: bill,
  3090. Action: action,
  3091. PayDateText: paydatetext || ''
  3092. }, function (res) {
  3093. if (res.RESULT) {
  3094. if (idx) {
  3095. layer.close(idx);
  3096. }
  3097. var saPath = res.DATA.rel,
  3098. sTitle = bReceipt ? 'common.Receipt_Preview' : 'common.Bill_Preview';
  3099. if (action.indexOf('Print_') > -1) {
  3100. var index = layer.open({
  3101. type: 2,
  3102. title: i18next.t(sTitle),
  3103. content: gServerUrl + '/' + (typeof saPath === 'string' ? saPath : saPath[0]),
  3104. area: ['900px', '500px'],
  3105. maxmin: true
  3106. });
  3107. //layer.full(index); //弹出即全屏
  3108. }
  3109. else {
  3110. if (typeof saPath === 'string') {
  3111. DownLoadFile(saPath);
  3112. }
  3113. else {
  3114. $.each(saPath, function (i, path) {
  3115. setTimeout(function () {
  3116. DownLoadFile(path);
  3117. }, 500 * i);
  3118. });
  3119. }
  3120. }
  3121. }
  3122. else {
  3123. // ╠common.Preview_Failed⇒預覽失敗╣ ╠common.DownLoad_Failed⇒下載失敗╣
  3124. showMsg(i18next.t('common.Preview_Failed') + '<br>' + res.MSG, 'error');
  3125. }
  3126. }, function () {
  3127. // ╠common.Preview_Failed⇒預覽失敗╣ ╠common.DownLoad_Failed⇒下載失敗╣
  3128. showMsg(i18next.t('common.Preview_Failed'), 'error');
  3129. }, true, i18next.t('message.Dataprocessing'));// ╠message.Dataprocessing⇒資料處理中...╣
  3130. };
  3131. if (bReceipt) {
  3132. fnToPrint();
  3133. }
  3134. else {
  3135. layer.open({
  3136. type: 1,
  3137. title: i18next.t('common.PayDatePopTitle'),// ╠common.PayDatePopTitle⇒付款日期設定╣
  3138. area: ['300px', '170px'],//寬度
  3139. shade: 0.75,//遮罩
  3140. shadeClose: true,
  3141. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  3142. content: '<div class="pop-box">\
  3143. <div class="col-sm-12" hidden>\
  3144. <input id="radio_1" type="radio" name="printitem" value="a"/>\
  3145. <label for="radio_1" data-i18n="common.PayDateText1">請立即安排付款</label>\
  3146. <input id="radio_2" type="radio" name="printitem" value="b" />\
  3147. <label for="radio_2" data-i18n="common.PayDateText2">a.s.a.p</label>\
  3148. <input id="radio_3" type="radio" name="printitem" value="c" checked="checked"/>\
  3149. <label for="radio_3" data-i18n="common.PayDateText3">日期</label>\
  3150. </div>\
  3151. <div class="col-sm-12 print-paydate">\
  3152. <input name="PayDate" type="text" maxlength="100" id="PayDate" class="form-control date-picker w100p" />\
  3153. </div>\
  3154. </div>',// common.PayDateText1請立即安排付款 common.PayDateText2a.s.a.p common.PayDateText3日期
  3155. success: function (layero, idx) {
  3156. var BillCheckDate = bill.BillCheckDate ? bill.BillCheckDate : new Date();
  3157. var sDefultDate = newDate(new Date(BillCheckDate).dateAdd('d', 15), true);
  3158. $('[name=printitem]').click(function () {
  3159. if (this.value === 'c') {
  3160. $('.print-paydate').show();
  3161. }
  3162. else {
  3163. $('.print-paydate').hide();
  3164. }
  3165. });
  3166. $('#PayDate').val(sDefultDate).datepicker({
  3167. changeYear: true,
  3168. changeMonth: true,
  3169. altFormat: 'yyyy/MM/dd',
  3170. onSelect: function (d, e) { },
  3171. afterInject: function (d, e) { }
  3172. });
  3173. transLang(layero);
  3174. },
  3175. yes: function (index, layero) {
  3176. var sPayDate = $('#PayDate').val(),
  3177. sPayDateType = $('[name=printitem]:checked').val(),
  3178. sPayDateText = $('[name=printitem]:checked').next().text();
  3179. if (sPayDateType === 'c' && !sPayDate) {
  3180. showMsg(i18next.t("message.PayDate_required")); // ╠message.PayDate_required⇒請選擇付款日期╣
  3181. return false;
  3182. }
  3183. fnToPrint(index, sPayDateType === 'c' ? sPayDate : sPayDateText);
  3184. }
  3185. });
  3186. }
  3187. },
  3188. /**
  3189. * 過帳
  3190. * @param bill(object)帳單資料
  3191. */
  3192. fnBillPost = function (bill) {
  3193. bill.AuditVal = '5';
  3194. bill.CreateDate = newDate();
  3195. g_api.ConnectLite(sProgramId, 'BillPost', {
  3196. ExportBillNO: sDataId,
  3197. Bills: oCurData.Bills,
  3198. Bill: bill
  3199. }, function (res) {
  3200. if (res.RESULT) {
  3201. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  3202. showMsg(i18next.t("message.BillPost_Success"), 'success'); // ╠message.BillPost_Success⇒過帳完成╣
  3203. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3204. parent.msgs.server.pushTransfer(parent.OrgID, parent.UserID, bill.BillNO, 1);
  3205. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3206. }
  3207. else {
  3208. bill.AuditVal = '2';
  3209. showMsg(i18next.t('message.BillPost_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillPost_Failed⇒過帳失敗╣
  3210. }
  3211. }, function () {
  3212. bill.AuditVal = '2';
  3213. showMsg(i18next.t('message.BillPost_Failed'), 'error'); // ╠message.BillPost_Failed⇒過帳失敗╣
  3214. });
  3215. },
  3216. /**
  3217. * 取消過帳
  3218. * @param bill(object)帳單資料
  3219. */
  3220. fnBillCancelPost = function (bill) {
  3221. bill.AuditVal = '2';
  3222. g_api.ConnectLite(sProgramId, 'BillCancelPost', {
  3223. ExportBillNO: sDataId,
  3224. Bills: oCurData.Bills,
  3225. Bill: bill,
  3226. LogData: fnGetBillLogData(bill)
  3227. }, function (res) {
  3228. if (res.RESULT) {
  3229. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  3230. showMsg(i18next.t("message.BillCancePost_Success"), 'success'); // ╠message.BillCancePost_Success⇒取消過帳完成╣
  3231. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3232. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3233. }
  3234. else {
  3235. bill.AuditVal = '5';
  3236. showMsg(i18next.t('message.BillCancePost_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillCancePost_Failed⇒取消過帳失敗╣
  3237. }
  3238. }, function () {
  3239. bill.AuditVal = '5';
  3240. showMsg(i18next.t('message.BillCancePost_Failed'), 'error'); // ╠message.BillCancePost_Failed⇒取消過帳失敗╣
  3241. });
  3242. },
  3243. /**
  3244. * 會計銷帳
  3245. * @param bill(object)帳單資料
  3246. */
  3247. fnBillWriteOff = function (bill) {
  3248. bill.AuditVal = '4';
  3249. bill.BillWriteOffDate = newDate();
  3250. g_api.ConnectLite(sProgramId, 'WriteOff', {
  3251. ExportBillNO: sDataId,
  3252. Bills: oCurData.Bills,
  3253. Bill: bill
  3254. }, function (res) {
  3255. if (res.RESULT) {
  3256. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  3257. showMsg(i18next.t("message.BillWriteOff_Success"), 'success'); // ╠message.BillWriteOff_Success⇒銷帳完成╣
  3258. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3259. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3260. }
  3261. else {
  3262. bill.AuditVal = '5';
  3263. showMsg(i18next.t('message.BillWriteOff_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillWriteOff_Failed⇒銷帳失敗╣
  3264. }
  3265. }, function () {
  3266. bill.AuditVal = '5';
  3267. showMsg(i18next.t('message.BillWriteOff_Failed'), 'error'); // ╠message.BillWriteOff_Failed⇒銷帳失敗╣
  3268. });
  3269. },
  3270. /**
  3271. * 會計取消銷帳
  3272. * @param bill(object)帳單資料
  3273. */
  3274. fnBillCancelWriteOff = function (bill) {
  3275. bill.AuditVal = '5';
  3276. bill.BillWriteOffDate = '';
  3277. g_api.ConnectLite(sProgramId, 'CancelWriteOff', {
  3278. ExportBillNO: sDataId,
  3279. Bills: oCurData.Bills,
  3280. Bill: bill,
  3281. LogData: fnGetBillLogData(bill)
  3282. }, function (res) {
  3283. if (res.RESULT) {
  3284. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  3285. showMsg(i18next.t("message.BillCancelWriteOff_Success"), 'success'); // ╠message.BillCancelWriteOff_Success⇒取消銷帳完成╣
  3286. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3287. }
  3288. else {
  3289. bill.AuditVal = '4';
  3290. showMsg(i18next.t('message.BillCancelWriteOff_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillCancelWriteOff_Failed⇒取消銷帳失敗╣
  3291. }
  3292. }, function () {
  3293. bill.AuditVal = '4';
  3294. showMsg(i18next.t('message.BillCancelWriteOff_Failed'), 'error'); // ╠message.BillCancelWriteOff_Failed⇒取消銷帳失敗╣
  3295. });
  3296. },
  3297. /**
  3298. * 帳單作廢
  3299. * @param bill(object)帳單資料
  3300. */
  3301. fnBillVoid = function (bill) {
  3302. layer.open({
  3303. type: 1,
  3304. title: i18next.t('common.VoidBill'),// ╠common.VoidBill⇒作廢帳單╣
  3305. area: ['400px', '220px'],//寬度
  3306. shade: 0.75,//遮罩
  3307. shadeClose: true,
  3308. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  3309. content: '<div class="pop-box">\
  3310. <textarea name="VoidReason" id="VoidReason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.VoidReason" placeholder="作廢原因..."></textarea>\
  3311. </div>',
  3312. success: function (layero, idx) {
  3313. transLang(layero);
  3314. },
  3315. yes: function (index, layero) {
  3316. var sAuditVal = bill.AuditVal,
  3317. sVoidReason = layero.find('#VoidReason').val();
  3318. if (sVoidReason) {
  3319. bill.VoidReason = sVoidReason;
  3320. bill.AuditVal = '6';
  3321. g_api.ConnectLite(sProgramId, 'BillVoid', {
  3322. ExportBillNO: sDataId,
  3323. Bills: oCurData.Bills,
  3324. Bill: bill,
  3325. LogData: fnGetBillLogData(bill)
  3326. }, function (res) {
  3327. if (res.RESULT) {
  3328. layer.close(index);
  3329. showMsg(i18next.t("message.Void_Success"), 'success'); // ╠message.Void_Success⇒作廢成功╣
  3330. fnBindBillLists();
  3331. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3332. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3333. }
  3334. else {
  3335. bill.AuditVal = sAuditVal;
  3336. bill.VoidReason = '';
  3337. showMsg(i18next.t('message.Void_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  3338. }
  3339. }, function () {
  3340. bill.AuditVal = sAuditVal;
  3341. bill.VoidReason = '';
  3342. showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  3343. });
  3344. }
  3345. else {
  3346. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  3347. }
  3348. }
  3349. });
  3350. },
  3351. /**
  3352. * 帳單刪除
  3353. * @param bill(object)帳單資料
  3354. */
  3355. fnBillDelete = function (bill) {
  3356. // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  3357. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  3358. var saNewBills = [];
  3359. $.each(oCurData.Bills, function (idx, _bill) {
  3360. if (_bill.BillNO !== bill.BillNO) {
  3361. saNewBills.push(_bill);
  3362. }
  3363. });
  3364. g_api.ConnectLite(sProgramId, 'BillDelete', {
  3365. ExportBillNO: sDataId,
  3366. Bills: saNewBills,
  3367. Bill: bill,
  3368. LogData: fnGetBillLogData(bill)
  3369. }, function (res) {
  3370. if (res.RESULT) {
  3371. showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣
  3372. oCurData.Bills = saNewBills;
  3373. fnBindBillLists();
  3374. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3375. fnDeleteBillInfo(bill.BillNO);
  3376. }
  3377. else {
  3378. showMsg(i18next.t("message.Delete_Failed") + '<br>' + res.MSG, 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  3379. }
  3380. }, function () {
  3381. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  3382. });
  3383. layer.close(index);
  3384. });
  3385. },
  3386. /**
  3387. * 抽單
  3388. * @param bill(object)帳單資料
  3389. */
  3390. fnBillReEdit = function (bill) {
  3391. bill.AuditVal = '7';
  3392. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  3393. Params: {
  3394. exportexhibition: {
  3395. values: { Bills: JSON.stringify(oCurData.Bills) },
  3396. keys: { ExportBillNO: sDataId }
  3397. }
  3398. }
  3399. }, function (res) {
  3400. if (res.d > 0) {
  3401. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  3402. showMsg(i18next.t("message.ReEdit_Success"), 'success'); // ╠message.ReEdit_Success⇒抽單成功╣
  3403. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3404. }
  3405. else {
  3406. bill.AuditVal = '1';
  3407. showMsg(i18next.t('message.ReEdit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  3408. }
  3409. }, function () {
  3410. bill.AuditVal = '1';
  3411. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  3412. });
  3413. },
  3414. /**
  3415. * 取消抽單
  3416. * @param bill(object)帳單資料
  3417. */
  3418. fnBillCancelReEdit = function (bill) {
  3419. bill.AuditVal = '1';
  3420. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  3421. Params: {
  3422. exportexhibition: {
  3423. values: { Bills: JSON.stringify(oCurData.Bills) },
  3424. keys: { ExportBillNO: sDataId }
  3425. }
  3426. }
  3427. }, function (res) {
  3428. if (res.d > 0) {
  3429. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  3430. showMsg(i18next.t("message.CancelReEdit_Success"), 'success'); // ╠message.CancelReEdit_Success⇒取消抽單成功╣
  3431. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  3432. }
  3433. else {
  3434. bill.AuditVal = '7';
  3435. showMsg(i18next.t('message.CancelReEdit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.CancelReEdit_Failed⇒取消抽單失敗╣
  3436. }
  3437. }, function () {
  3438. bill.AuditVal = '7';
  3439. showMsg(i18next.t('message.CancelReEdit_Failed'), 'error'); // ╠message.CancelReEdit_Failed⇒取消抽單失敗╣
  3440. });
  3441. },
  3442. /**
  3443. * 綁定帳單
  3444. */
  3445. fnBindBillLists = function () {
  3446. var oBillsBox = $('#accordion');
  3447. //oBillsBox.html('');
  3448. //$('#tab3 .amountsum').val(0);
  3449. if (oCurData.Bills.length > 0) {//實際帳單
  3450. oCurData.Bills = Enumerable.From(oCurData.Bills).OrderBy("x=>x.BillCreateDate").ToArray();
  3451. $.each(oCurData.Bills, function (idx, bill) {
  3452. if ($('.bill-box-' + bill.BillNO).length === 0) {
  3453. bill.Index = idx + 1;
  3454. bill.Advance = bill.Advance || 0;
  3455. var sHtml = $("#temp_billbox").render([bill]);
  3456. oBillsBox.append(sHtml);
  3457. var oBillBox = $('.bill-box-' + bill.BillNO);
  3458. $('.bills-box').show();
  3459. oBillBox.find('[data-id="Currency"]').html(sAccountingCurrencyOptionsHtml).on('change', function () {
  3460. var sCurrencyId = this.value,
  3461. oCurrency = Enumerable.From(saAccountingCurrency).Where(function (e) { return e.ArgumentID === sCurrencyId; }).FirstOrDefault();
  3462. if (oCurrency === undefined)
  3463. oCurrency = {};
  3464. let TitleAttr = '';
  3465. let MainCurrency = fnCheckMainOrForeignCurrency(sCurrencyId);
  3466. if (MainCurrency) {
  3467. TitleAttr = 'common.MainCurrencyNontaxedAmountV2';
  3468. oBillBox.find('.BillMainCurrencyAdd [data-id="plusfeeitem"]').show();
  3469. oBillBox.find('.BillForeignCurrency').hide();
  3470. oGlobalItem.parentdata.Quote.QuotationOrBillingCurrency = sCurrencyId;
  3471. fnBindFeeItem(oGlobalItem.dom, oGlobalItem.parentdata, oGlobalItem.data);
  3472. }
  3473. else {
  3474. TitleAttr = 'common.ForeignCurrencyNontaxedAmountV2';
  3475. oBillBox.find('.BillMainCurrencyAdd [data-id="plusfeeitem"]').hide();
  3476. oBillBox.find('.BillForeignCurrency').show();
  3477. oGlobalItem.parentdata.Quote.QuotationOrBillingCurrency = sCurrencyId;
  3478. fnBindFeeItem(oGlobalItem.dom, oGlobalItem.parentdata, oGlobalItem.data);
  3479. }
  3480. bill.Currency = sCurrencyId;
  3481. bill.ExchangeRate = oCurrency.Correlation || '';
  3482. oBillBox.find('[data-id="ExchangeRate"]').val(oCurrency.Correlation || '');
  3483. oBillBox.find('.BillAmountTiltle').attr('data-i18n', TitleAttr).text(i18next.t(TitleAttr));
  3484. let ExchangeRate = oBillBox.find('[data-id="ExchangeRate"]').val();
  3485. fnCalcuBillsFee(oBillBox, '.BillForeignCurrency', '.BillMainCurrency', sCurrencyId, ExchangeRate);
  3486. bRequestStorage = true;
  3487. }).val(bill.Currency);
  3488. oBillBox.find('[data-id="Currency"]').change();
  3489. //oBillBox.find('[data-id="Currency"] option:first').remove();
  3490. fnBindFeeItem($('[data-id=bill_fees_' + bill.BillNO + ']'), oCurData, bill);
  3491. //觸發點擊項目 產生資料內容
  3492. oBillBox.click(function () {
  3493. if ($(this).attr('aria-expanded') === 'false') {
  3494. oBillBox.find('[data-id="Payer"]').html(sCustomersNotAuditOptionsHtml).val(bill.Payer);
  3495. setTimeout(function () {
  3496. oBillBox.find('[data-id="Payer"]').select2({ width: '250px' });
  3497. }, 1000);
  3498. if (bill.Payer) {
  3499. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === bill.Payer; }),
  3500. saContactors = [];
  3501. if (oCur.Count() > 0) {
  3502. saContactors = JSON.parse(oCur.First().Contactors || '[]');
  3503. }
  3504. oBillBox.find('[data-id="Contactor"]').html(createOptions(saContactors, 'guid', 'FullName')).val(bill.Contactor).off('change').on('change', function (e) {
  3505. var sContactor = this.value;
  3506. if (sContactor) {
  3507. var oContactor = Enumerable.From(saContactors).Where(function (e) { return e.guid == sContactor; }).First();
  3508. bill.ContactorName = oContactor.FullName;
  3509. bill.Contactor = sContactor;
  3510. }
  3511. else {
  3512. bill.ContactorName = '';
  3513. bill.Contactor = '';
  3514. }
  3515. bRequestStorage = true;
  3516. });;
  3517. oBillBox.find('[data-id="Contactor"]').select2();
  3518. }
  3519. else {
  3520. oBillBox.find('[data-id="Contactor"]').html(createOptions([]));
  3521. }
  3522. oBillBox.find('[data-id="Telephone"]').val(bill.Telephone);
  3523. oBillBox.find('[data-id="ExchangeRate"]').val(bill.ExchangeRate || 1.00);
  3524. oBillBox.find('[data-id="Number"]').val(bill.Number).on('keyup blur', function (e) {
  3525. this.value = this.value.replace(/\D/g, '');
  3526. });
  3527. oBillBox.find('[data-id="Unit"]').val(bill.Unit);
  3528. moneyInput(oBillBox.find('[data-id="Advance"]'), 2);
  3529. moneyInput(oBillBox.find('[data-id="mAdvance"]'), 0);
  3530. oBillBox.find('[data-id="Advance"]').val(bill.Advance);
  3531. SetBillPrepayEvent(oBillBox, bill);
  3532. oBillBox.find('[data-id="Weight"]').val(bill.Weight).on('keyup blur', function (e) {
  3533. keyIntp(e, this, 3);
  3534. });
  3535. oBillBox.find('[data-id="Volume"]').val(bill.Volume).on('keyup blur', function (e) {
  3536. keyIntp(e, this, 2);
  3537. });
  3538. if (bill.ReceiptNumber) {//如果收據號碼已經產生就移除該按鈕
  3539. oBillBox.find('[data-id="ReceiptNumber"]').val(bill.ReceiptNumber);
  3540. oBillBox.find('[data-id="ReceiptDate"]').val(bill.ReceiptDate);
  3541. oBillBox.find('[data-id="createreceiptnumber"]').remove();
  3542. }
  3543. oBillBox.find('[data-id="Memo"]').val(bill.Memo);
  3544. oBillBox.find('[data-id="InvoiceNumber"]').val(bill.InvoiceNumber).on('blur', function (e) {
  3545. var that = this,
  3546. sInvoiceNumber = that.value;
  3547. if (sInvoiceNumber) {
  3548. return g_api.ConnectLite(Service.opm, ComFn.CheckInvoiceNum, {
  3549. InvoiceNumber: sInvoiceNumber
  3550. }, function (res) {
  3551. if (res.RESULT) {
  3552. var bExsit = res.DATA.rel;
  3553. if (bExsit) {
  3554. // ╠message.InvoiceNumberRepeat⇒發票號碼重複,請重新輸入!╣ ╠message.Tips⇒提示╣
  3555. layer.alert(i18next.t("message.InvoiceNumberRepeat"), { icon: 0, title: i18next.t("common.Tips") }, function (index) {
  3556. $(that).val('');
  3557. layer.close(index);
  3558. });
  3559. }
  3560. }
  3561. });
  3562. }
  3563. });
  3564. oBillBox.find('[data-id="InvoiceDate"]').val(bill.InvoiceDate);
  3565. oBillBox.find('.date-picker').datepicker({
  3566. changeYear: true,
  3567. changeMonth: true,
  3568. altFormat: 'yyyy/MM/dd'
  3569. });
  3570. oBillBox.find('[data-id="Payer"]').on('change', function () {
  3571. var sCustomerId = this.value,
  3572. saContactors = [];
  3573. if (sCustomerId) {
  3574. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === sCustomerId; }).First();
  3575. saContactors = JSON.parse(oCur.Contactors || '[]');
  3576. //bill.CustomerCode = oCur.CustomerNO;
  3577. oBillBox.find('[data-id="Contactor"]').html(createOptions(saContactors, 'guid', 'FullName')).off('change').on('change', function () {
  3578. var sContactor = this.value;
  3579. if (sContactor) {
  3580. var oContactor = Enumerable.From(saContactors).Where(function (e) { return e.guid == sContactor; }).First();
  3581. bill.ContactorName = oContactor.FullName;
  3582. bill.Contactor = sContactor;
  3583. }
  3584. else {
  3585. bill.ContactorName = '';
  3586. bill.Contactor = '';
  3587. }
  3588. bRequestStorage = true;
  3589. });
  3590. oBillBox.find('[data-id="Telephone"]').val(oCur.Telephone);
  3591. oBillBox.find('[data-id="Contactor"]').select2();
  3592. }
  3593. else {
  3594. oBillBox.find('[data-id="Contactor"]').html(createOptions([]));
  3595. oBillBox.find('[data-id="Telephone"]').val('');
  3596. }
  3597. oBillBox.find('[data-id="Telephone"]').change();
  3598. bRequestStorage = true;
  3599. });
  3600. oBillBox.find('.bill-print').each(function () {
  3601. var that = this,
  3602. sTypeId = $(that).attr('data-action'),
  3603. oToolBar = null;
  3604. switch (sTypeId) {
  3605. case 'Print_Bill':
  3606. oToolBar = oPrintMenu.InvoicePrintMenu.tmpl
  3607. break;
  3608. case 'Print_Receipt':
  3609. oToolBar = oPrintMenu.ReceiptPrintMenu.tmpl
  3610. break;
  3611. case 'Download_Bill':
  3612. case 'Download_BatchBill':
  3613. oToolBar = oPrintMenu.InvoiceDownLoadMenu.tmpl
  3614. break;
  3615. case 'Download_Receipt':
  3616. oToolBar = oPrintMenu.ReceiptDownLoadMenu.tmpl
  3617. break;
  3618. }
  3619. $(that).toolbar({
  3620. content: oToolBar,
  3621. position: 'left',
  3622. adjustment: 10,
  3623. style: 'yida',
  3624. }).on('toolbarItemClick',
  3625. function (e, ele) {
  3626. fnPrint($(ele).attr('data-id'), sTypeId, bill);
  3627. }
  3628. );
  3629. });
  3630. oBillBox.find('.btn-custom').not('disabled').off('click').on('click', function () {
  3631. var that = this,
  3632. sId = $(that).attr('data-id');
  3633. switch (sId) {
  3634. case 'plusfeeitem'://新增費用項目
  3635. fnPlusFeeItem(that, oCurData, null, bill.Currency);
  3636. break;
  3637. case 'createreceiptnumber'://產生收據號碼
  3638. fnGetReceiptNumber(that, bill).done(function () {
  3639. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  3640. Params: {
  3641. exportexhibition: {
  3642. values: { Bills: JSON.stringify(oCurData.Bills) },
  3643. keys: { ExportBillNO: sDataId }
  3644. }
  3645. }
  3646. });
  3647. });
  3648. break;
  3649. case 'bill_submitaudit'://提交審核
  3650. fnBillToAudit(bill, that);
  3651. break;
  3652. case 'bill_audit'://主管審核
  3653. fnBillAudit(bill);
  3654. break;
  3655. case 'bill_cancelaudit'://取消審核
  3656. fnBillCancelAudit(bill);
  3657. break;
  3658. case 'bill_post'://過帳
  3659. fnBillPost(bill);
  3660. break;
  3661. case 'bill_cancelpost'://取消過帳
  3662. fnBillCancelPost(bill);
  3663. break;
  3664. case 'bill_writeoff'://銷帳
  3665. fnBillWriteOff(bill);
  3666. break;
  3667. case 'bill_canceloff'://銷帳
  3668. fnBillCancelWriteOff(bill);
  3669. break;
  3670. case 'bill_void'://作廢
  3671. fnBillVoid(bill);
  3672. break;
  3673. case 'bill_delete'://刪除
  3674. fnBillDelete(bill);
  3675. break;
  3676. case 'bill_reedit'://抽單
  3677. fnBillReEdit(bill);
  3678. break;
  3679. case 'bill_cancelreedit'://取消抽單
  3680. fnBillCancelReEdit(bill);
  3681. break;
  3682. }
  3683. });
  3684. }
  3685. });
  3686. //createOptions(sSelectedOrganizers.filter(e => e != null ), 'id', 'text')
  3687. //組團單位
  3688. oBillBox.find('[data-id="BillOrganizer"]').html(createOptions(sSelectedOrganizers.filter(e => e != null), 'id', 'text')).on('change', function () {
  3689. bill.BillOrganizer = this.value;
  3690. bRequestStorage = true;
  3691. }).val(bill.BillOrganizer);
  3692. }
  3693. });
  3694. }
  3695. fnSetPermissions();//設置權限
  3696. $('#tab3').css({ 'padding-top': 40 });
  3697. $('#topshow_box').show();//當審通過之後才顯示總金額
  3698. transLang(oBillsBox);
  3699. },
  3700. /**
  3701. * 設置操作權限
  3702. */
  3703. fnSetPermissions = function () {
  3704. if (parent.UserInfo.roles.indexOf('Admin') === -1) {
  3705. if ((parent.UserInfo.roles.indexOf('CDD') > -1 && (oCurData.ResponsiblePerson === parent.UserID || oCurData.DepartmentID === parent.UserInfo.DepartmentID)) || parent.UserInfo.roles.indexOf('CDD') === -1 || parent.SysSet.CDDProUsers.indexOf(parent.UserID) > -1) {//報關作業
  3706. $('[href="#tab3"],[href="#tab4"],[href="#tab5"],[href="#tab6"]').parent().show();
  3707. }
  3708. else {
  3709. $('[href="#tab3"],[href="#tab4"],[href="#tab5"],[href="#tab6"]').parent().hide();
  3710. }
  3711. if (!(parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser)) {//其他
  3712. $('#tab3,#tab5').find(':input,button,textarea').not('.alreadyaudit,.cancelaudi,.writeoff,.bills-print,.estimated_addreturnbills,.prepay,.mprepay,.billvoid,.canceloff,.cancelpost').attr('disabled', 'disabled');
  3713. $('#tab3,#tab5').find('.icon-p').addClass('disabled');
  3714. }
  3715. if (parent.UserInfo.roles.indexOf('Business') > -1) {//業務
  3716. $('#tab4,#tab6').find(':input,button,textarea').attr('disabled', 'disabled');
  3717. $('#tab4,#tab6').find('.icon-p').addClass('disabled');
  3718. }
  3719. if (parent.UserInfo.roles.indexOf('Account') > -1) {//會計
  3720. $('#tab1,#tab2,#tab3,#tab5').find(':input,button,textarea').not('.alreadyaudit,.cancelaudi,.writeoff,.bills-print,.jsgrid-button,.estimated_addreturnbills,.prepay,.mprepay,.billvoid,.canceloff,.cancelpost,.importfeeitem,.plusfeeitem').attr('disabled', 'disabled');
  3721. $('#tab3,#tab5').find('.icon-p').addClass('disabled');
  3722. }
  3723. }
  3724. },
  3725. /**------------------------帳單部分---------------------------End*/
  3726. /**------------------------退運帳單部分---------------------------Start*/
  3727. /**
  3728. * 添加新帳單
  3729. */
  3730. fnRenderReturnBills = function () {
  3731. oCurData.ReturnBills = Enumerable.From(oCurData.ReturnBills).OrderBy("x=>x.CreateDate").ToArray();
  3732. var oReturnQuoteBox = $('.return-quote-box'),
  3733. oReturnActualcostBox = $('.return-actualcost-box'),
  3734. sReturnQuoteBoxHtml = $("#temp_return_quote_box").render(oCurData.ReturnBills),
  3735. sReturnActualcostBoxHtml = $("#temp_return_actualcost_box").render(oCurData.ReturnBills);
  3736. oReturnQuoteBox.html(sReturnQuoteBoxHtml);
  3737. oReturnActualcostBox.html(sReturnActualcostBoxHtml);
  3738. $.each(oCurData.ReturnBills, function (idx, Returns) {
  3739. var oFieldset_Return = $('.fieldset-' + Returns.guid);
  3740. fnBindFeeItem(oFieldset_Return.find('[data-id="quote-box"]'), Returns, Returns.Quote);//綁定報價
  3741. fnBindFeeItem(oFieldset_Return.find('[data-id="estimatedcost-box"]'), Returns, Returns.EstimatedCost);//綁定預估成本
  3742. if (Returns.EstimatedCost.AuditVal && Returns.EstimatedCost.AuditVal === '2') {//業務審核完
  3743. fnBindFeeItem(oFieldset_Return.find('[data-id="actualcost-pre-box"]'), Returns, Returns.EstimatedCost, true);
  3744. oFieldset_Return.find('.estimatedcost-memo').text(Returns.EstimatedCost.Memo || '');
  3745. }
  3746. fnBindFeeItem(oFieldset_Return.find('[data-id="actualcost-box"]'), Returns, Returns.ActualCost);//實際成本
  3747. fnInitialReturnAccountCurrency('.fieldset-' + Returns.guid, '-' + Returns.guid);//會計用匯率
  3748. oFieldset_Return.find('[data-source="quote"]').text(Returns.Quote.Memo || '');
  3749. oFieldset_Return.find('[data-source="estimatedcost"]').text(Returns.EstimatedCost.Memo || '');
  3750. oFieldset_Return.find('[data-source="actualcost"]').text(Returns.ActualCost.Memo || '');
  3751. oFieldset_Return.find('.plusfeeitem').not('disabled').off('click').on('click', function () {
  3752. fnPlusFeeItem(this, Returns);
  3753. });
  3754. oFieldset_Return.find('.importfeeitem').not('disabled').off('click').on('click', function () {
  3755. var sType = $(this).attr('data-type');
  3756. fnImportFeeitems(sType, oFieldset_Return, Returns);
  3757. });
  3758. oFieldset_Return.find('.copyfeeitem').not('disabled').off('click').on('click', function () {
  3759. var sType = $(this).attr('data-type');
  3760. fnCopyFeeitems(sType, oFieldset_Return, Returns);
  3761. });
  3762. oFieldset_Return.find('.plusfeeitemstar').not('disabled').off('click').on('click', function () {
  3763. fnPlusFeeItemStar(this, oFieldset_Return.find('[data-id="quote-box"]'), Returns);
  3764. });
  3765. oFieldset_Return.find('.estimated_submitaudit').not('disabled').off('click').on('click', function () {
  3766. if (Returns.EstimatedCost.FeeItems.length === 0 && !Returns.EstimatedCost.Memo) {
  3767. showMsg(i18next.t("message.EstimatedCostMemo_Required")); // ╠message.EstimatedCostMemo_Required⇒預估成本沒有費用明細,請至少填寫備註╣
  3768. return false;
  3769. }
  3770. if (!Returns.ReturnAccountingExchangeRate || !Returns.ReturnQuotationOrBillingCurrency) {
  3771. showMsg(i18next.t("message.QuotationOrBillingCurrencyField_Required")); // ╠message.QuotationOrBillingCurrencyField_Required⇒報價/帳單幣或匯率未選擇╣
  3772. return false;
  3773. }
  3774. Returns.Quote.AuditVal = '1';
  3775. Returns.EstimatedCost.AuditVal = '1';
  3776. g_api.ConnectLite(sProgramId, 'ReturnToAuditForQuote', {
  3777. ExportBillNO: sDataId,
  3778. ReturnBills: oCurData.ReturnBills,
  3779. SourceID: Returns.Quote.guid,
  3780. Index: idx + 1
  3781. }, function (res) {
  3782. if (res.RESULT) {
  3783. fnSetDisabled(oFieldset_Return.find('.quoteandprecost'), Returns.Quote);
  3784. showMsg(i18next.t("message.ToAudit_Success"), 'success'); // ╠message.ToAudit_Success⇒提交審核成功╣
  3785. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  3786. }
  3787. else {
  3788. Returns.Quote.AuditVal = '0';
  3789. Returns.EstimatedCost.AuditVal = '0';
  3790. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  3791. }
  3792. }, function () {
  3793. Returns.Quote.AuditVal = '0';
  3794. Returns.EstimatedCost.AuditVal = '0';
  3795. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  3796. });
  3797. });
  3798. oFieldset_Return.find('.estimated_audit').not('disabled').off('click').on('click', function () {
  3799. layer.open({
  3800. type: 1,
  3801. title: i18next.t('common.Leader_Audit'),// ╠common.Leader_Audit⇒主管審核╣
  3802. area: ['400px', '260px'],//寬度
  3803. shade: 0.75,//遮罩
  3804. shadeClose: true,
  3805. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  3806. content: '<div class="pop-box">\
  3807. <textarea name="NotPassReason" id="NotPassReason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.NotPassReason" placeholder="不通過原因..."></textarea><br>\
  3808. <button type="button" data-i18n="common.Pass" id="audit_pass" class="btn-custom green">通過</button>\
  3809. <button type="button" data-i18n="common.NotPass" id="audit_notpass" class="btn-custom red">不通過</button>\
  3810. </div>',
  3811. success: function (layero, index) {
  3812. $('.pop-box :button').click(function () {
  3813. var fnAuditForQuote = function () {
  3814. g_api.ConnectLite(sProgramId, 'ReturnAuditForQuote', {
  3815. ExportBillNO: sDataId,
  3816. ReturnBills: oCurData.ReturnBills,
  3817. AuditVal: Returns.Quote.AuditVal,
  3818. SourceID: Returns.Quote.guid,
  3819. Index: idx + 1
  3820. }, function (res) {
  3821. if (res.RESULT) {
  3822. showMsg(i18next.t("message.Audit_Completed"), 'success'); // ╠message.Audit_Completed⇒審核完成╣
  3823. fnSetDisabled(oFieldset_Return.find('.quoteandprecost'), Returns.Quote);
  3824. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  3825. }
  3826. else {
  3827. Returns.Quote.AuditVal = '1';
  3828. Returns.EstimatedCost.AuditVal = '1';
  3829. showMsg(i18next.t('message.Audit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  3830. }
  3831. }, function () {
  3832. Returns.Quote.AuditVal = '1';
  3833. Returns.EstimatedCost.AuditVal = '1';
  3834. showMsg(i18next.t('message.Audit_Failed'), 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  3835. });
  3836. },
  3837. sNotPassReason = $('#NotPassReason').val();
  3838. if (this.id === 'audit_pass') {
  3839. Returns.Quote.AuditVal = '2';
  3840. Returns.EstimatedCost.AuditVal = '2';
  3841. Returns.Quote.NotPassReason = '';
  3842. Returns.EstimatedCost.NotPassReason = '';
  3843. }
  3844. else {
  3845. ;
  3846. if (!sNotPassReason) {
  3847. showMsg(i18next.t("message.NotPassReason_Required")); // ╠message.NotPassReason_Required⇒請填寫不通過原因╣
  3848. return false;
  3849. }
  3850. else {
  3851. Returns.Quote.AuditVal = '3';
  3852. Returns.EstimatedCost.AuditVal = '3';
  3853. Returns.Quote.NotPassReason = sNotPassReason;
  3854. Returns.EstimatedCost.NotPassReason = sNotPassReason;
  3855. }
  3856. }
  3857. fnAuditForQuote();
  3858. layer.close(index);
  3859. });
  3860. transLang(layero);
  3861. }
  3862. });
  3863. });
  3864. oFieldset_Return.find('.estimated_synquote').not('disabled').off('click').on('click', function () {
  3865. Returns.EstimatedCost.FeeItems = clone(Returns.Quote.FeeItems);
  3866. $.each(Returns.EstimatedCost.FeeItems, function (idx, item) {
  3867. item.FinancialUnitPrice = 0;
  3868. item.FinancialNumber = 0;
  3869. item.FinancialAmount = 0;
  3870. item.FinancialTWAmount = 0;
  3871. item.FinancialTaxRate = '0%';
  3872. item.FinancialTax = 0;
  3873. item.CreateUser = parent.UserID;
  3874. item.CreateDate = newDate(null, true);
  3875. });
  3876. fnBindFeeItem(oFieldset_Return.find('[data-id="estimatedcost-box"]'), Returns, Returns.EstimatedCost);
  3877. });
  3878. if (Returns.Quote.AuditVal === '2' && (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser)) {
  3879. oFieldset_Return.find('.estimated_addreturnbills').removeAttr('disabled').show().off('click').on('click', function () {
  3880. var fnGetBillsAdd = function () {
  3881. var saBillsAdd = [],
  3882. iNum = 1,
  3883. oSame = {},
  3884. d = $.Deferred();
  3885. $.each(saGridData, function (m, item) {
  3886. var iExsit = Enumerable.From(Returns.Bills).Where(function (e) { return (e.CustomerGuid === item.SupplierID && !e.VoidReason); }).Count();
  3887. if (!oSame[item.SupplierID]) {
  3888. oSame[item.SupplierID] = 1;
  3889. }
  3890. else {
  3891. oSame[item.SupplierID]++;
  3892. }
  3893. if (iExsit === 0 || oSame[item.SupplierID] > iExsit) {
  3894. item.RowIndex = iNum;
  3895. saBillsAdd.push(item);
  3896. iNum++;
  3897. oSame[item.SupplierID]--;
  3898. }
  3899. });
  3900. d.resolve({
  3901. data: saBillsAdd,
  3902. itemsCount: saBillsAdd.length
  3903. });
  3904. return d.promise();
  3905. },
  3906. oConfig = {
  3907. Id: 'PopIsBatch',
  3908. Title: i18next.t('common.SelectBatchList'),// ╠message.SelectBatchList⇒請選擇要批次操作的資料╣
  3909. PageSize: 10000,
  3910. Get: fnGetBillsAdd,
  3911. SearchFields: [
  3912. { id: "Pop_SupplierName", type: 'text', i18nkey: 'common.SupplierCName' },
  3913. { id: "Pop_SupplierEName", type: 'text', i18nkey: 'common.SupplierEName' }
  3914. ],
  3915. Fields: [
  3916. { name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 40 },
  3917. { name: "CustomerNO", title: 'Customers_Upd.CustomerNO', width: 80 },
  3918. { name: "SupplierName", title: 'common.SupplierCName', width: 150 },
  3919. { name: "SupplierEName", title: 'common.SupplierEName', width: 150 }
  3920. ],
  3921. Callback: function (items) {
  3922. if (items.length > 0) {
  3923. var saPost = [];
  3924. $.each(items, function (e, _item) {
  3925. saPost.push(fnPushBill(_item, Returns, Returns.guid, true));
  3926. });
  3927. $.whenArray(saPost).done(function () {
  3928. fnRenderReturnBills();
  3929. });
  3930. }
  3931. }
  3932. };
  3933. oPenPopm(oConfig);
  3934. });
  3935. }
  3936. else {
  3937. oFieldset_Return.find('.estimated_addreturnbills').hide()
  3938. }
  3939. $.each(Returns.Bills, function (i, bill) {
  3940. bill.Advance = bill.Advance || 0;
  3941. var oBillsBox = $('.return-bill-' + bill.parentid),
  3942. sHtml = $("#temp_returnbillbox").render([bill]);
  3943. oBillsBox.append(sHtml);
  3944. var oBillBox = $('.bill-box-' + bill.BillNO);
  3945. oBillBox.find('[data-id="Currency"]').html(sAccountingCurrencyOptionsHtml).on('change', function () {
  3946. var sCurrencyId = this.value,
  3947. oCurrency = Enumerable.From(saAccountingCurrency).Where(function (e) { return e.ArgumentID === sCurrencyId; }).FirstOrDefault();
  3948. if (oCurrency === undefined)
  3949. oCurrency = {};
  3950. let TitleAttr = '';
  3951. let MainCurrency = fnCheckMainOrForeignCurrency(sCurrencyId);
  3952. if (MainCurrency) {
  3953. TitleAttr = 'common.MainCurrencyNontaxedAmountV2';
  3954. oBillBox.find('.ReturnBillMainCurrencyAdd [data-id="plusfeeitem"]').show();
  3955. oBillBox.find('.ReturnBillForeignCurrency').hide();
  3956. oGlobalItem.parentdata.Quote.QuotationOrBillingCurrency = sCurrencyId;
  3957. fnBindFeeItem(oGlobalItem.dom, oGlobalItem.parentdata, oGlobalItem.data);
  3958. }
  3959. else {
  3960. TitleAttr = 'common.ForeignCurrencyNontaxedAmountV2';
  3961. oBillBox.find('.ReturnBillMainCurrencyAdd [data-id="plusfeeitem"]').hide();
  3962. oBillBox.find('.ReturnBillForeignCurrency').show();
  3963. oGlobalItem.parentdata.Quote.QuotationOrBillingCurrency = sCurrencyId;
  3964. fnBindFeeItem(oGlobalItem.dom, oGlobalItem.parentdata, oGlobalItem.data);
  3965. }
  3966. oBillBox.find('.ReturnBillAmountTiltle-' + bill.guid).attr('data-i18n', TitleAttr).text(i18next.t(TitleAttr));
  3967. bill.Currency = sCurrencyId;
  3968. bill.ExchangeRate = oCurrency.Correlation || '';
  3969. oBillBox.find('[data-id="ExchangeRate"]').val(oCurrency.Correlation || '');
  3970. let ExchangeRate = oBillBox.find('[data-id="ExchangeRate"]').val();
  3971. fnCalcuBillsFee(oBillBox, '.ReturnBillForeignCurrency', '.ReturnBillMainCurrency', sCurrencyId, ExchangeRate);
  3972. bRequestStorage = true;
  3973. }).val(bill.Currency);
  3974. oBillBox.find('[data-id="Currency"]').change();
  3975. //oBillBox.find('[data-id="Currency"] option:first').remove();
  3976. oBillBox.find('[data-id="Payer"]').html(sCustomersNotAuditOptionsHtml).val(bill.Payer);
  3977. oBillBox.find('[data-id="ReFlow"]').val(bill.ReFlow || '');
  3978. setTimeout(function () {
  3979. oBillBox.find('[data-id="Payer"]').select2({ width: '250px' });
  3980. }, 1000);
  3981. if (bill.Payer) {
  3982. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === bill.Payer; }),
  3983. saContactors = [];
  3984. if (oCur.Count() > 0) {
  3985. saContactors = JSON.parse(oCur.First().Contactors || '[]');
  3986. }
  3987. oBillBox.find('[data-id="Contactor"]').html(createOptions(saContactors, 'guid', 'FullName')).val(bill.Contactor).off('change').on('change', function (e) {
  3988. var sContactor = this.value;
  3989. if (sContactor) {
  3990. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  3991. Type: '',
  3992. Params: {
  3993. customers: {
  3994. guid: bill.Payer
  3995. },
  3996. }
  3997. }, function (res) {
  3998. var oRes = $.parseJSON(res.d);
  3999. if (oRes.Contactors) {
  4000. oRes.Contactors = $.parseJSON(oRes.Contactors || '[]');
  4001. var oContactor = Enumerable.From(oRes.Contactors).Where(function (e) { return e.guid === sContactor; }).First();
  4002. bill.ContactorName = oContactor.FullName;
  4003. bill.Contactor = sContactor;
  4004. }
  4005. });
  4006. }
  4007. else {
  4008. bill.ContactorName = '';
  4009. bill.Contactor = '';
  4010. }
  4011. bRequestStorage = true;
  4012. });
  4013. oBillBox.find('[data-id="Contactor"]').select2();
  4014. }
  4015. else {
  4016. oBillBox.find('[data-id="Contactor"]').html(createOptions([]));
  4017. }
  4018. oBillBox.find('[data-id="Telephone"]').val(bill.Telephone);
  4019. moneyInput(oBillBox.find('[data-id="Advance"]'), 2);
  4020. moneyInput(oBillBox.find('[data-id="mAdvance"]'), 0);
  4021. oBillBox.find('[data-id="Advance"]').val(bill.Advance);
  4022. SetBillPrepayEvent(oBillBox, bill);
  4023. oBillBox.find('[data-id="ExchangeRate"]').val(bill.ExchangeRate || 1.00);
  4024. oBillBox.find('[data-id="Number"]').val(bill.Number).on('keyup blur', function (e) {
  4025. this.value = this.value.replace(/\D/g, '');
  4026. });
  4027. oBillBox.find('[data-id="Unit"]').val(bill.Unit);
  4028. oBillBox.find('[data-id="Weight"]').val(bill.Weight).on('keyup blur', function (e) {
  4029. keyIntp(e, this, 3);
  4030. });
  4031. oBillBox.find('[data-id="Volume"]').val(bill.Volume).on('keyup blur', function (e) {
  4032. keyIntp(e, this, 2);
  4033. });
  4034. fnBindFeeItem($('[data-id=bill_fees_' + bill.BillNO + ']'), Returns, bill);
  4035. if (bill.ReceiptNumber) {//如果收據號碼已經產生就移除該按鈕
  4036. oBillBox.find('[data-id="ReceiptNumber"]').val(bill.ReceiptNumber);
  4037. oBillBox.find('[data-id="ReceiptDate"]').val(bill.ReceiptDate);
  4038. oBillBox.find('[data-id="createreceiptnumber"]').remove();
  4039. }
  4040. oBillBox.find('[data-id="Memo"]').val(bill.Memo);
  4041. oBillBox.find('[data-id="InvoiceNumber"]').val(bill.InvoiceNumber).on('blur', function (e) {
  4042. var that = this,
  4043. sInvoiceNumber = that.value;
  4044. if (sInvoiceNumber) {
  4045. return g_api.ConnectLite(Service.opm, ComFn.CheckInvoiceNum, {
  4046. InvoiceNumber: sInvoiceNumber
  4047. }, function (res) {
  4048. if (res.RESULT) {
  4049. var bExsit = res.DATA.rel;
  4050. if (bExsit) {
  4051. // ╠message.InvoiceNumberRepeat⇒發票號碼重複,請重新輸入!╣ ╠message.Tips⇒提示╣
  4052. layer.alert(i18next.t("message.InvoiceNumberRepeat"), { icon: 0, title: i18next.t("common.Tips") }, function (index) {
  4053. $(that).val('');
  4054. layer.close(index);
  4055. });
  4056. }
  4057. }
  4058. });
  4059. }
  4060. });
  4061. oBillBox.find('[data-id="InvoiceDate"]').val(bill.InvoiceDate);
  4062. oBillBox.find('.date-picker').datepicker({
  4063. changeYear: true,
  4064. changeMonth: true,
  4065. altFormat: 'yyyy/MM/dd'
  4066. });
  4067. inputChange(oBillBox.find('[data-source="bill"]'), bill);
  4068. oBillBox.find('[data-id="Payer"]').on('change', function () {
  4069. var sCustomerId = this.value,
  4070. saContactors = [];
  4071. if (sCustomerId) {
  4072. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === sCustomerId; }).First();
  4073. saContactors = JSON.parse(oCur.Contactors || '[]');
  4074. //bill.CustomerCode = oCur.CustomerNO;
  4075. //bill.UniCode = oCur.UniCode;
  4076. oBillBox.find('[data-id="Contactor"]').html(createOptions(saContactors, 'guid', 'FullName')).off('change').on('change', function () {
  4077. var sContactor = this.value;
  4078. if (sContactor) {
  4079. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  4080. Type: '',
  4081. Params: {
  4082. customers: {
  4083. guid: sCustomerId
  4084. },
  4085. }
  4086. }, function (res) {
  4087. var oRes = $.parseJSON(res.d);
  4088. if (oRes.Contactors) {
  4089. oRes.Contactors = $.parseJSON(oRes.Contactors || '[]');
  4090. var oContactor = Enumerable.From(oRes.Contactors).Where(function (e) { return e.guid === sContactor; }).First();
  4091. bill.ContactorName = oContactor.FullName;
  4092. bill.Contactor = sContactor;
  4093. }
  4094. });
  4095. }
  4096. else {
  4097. bill.ContactorName = '';
  4098. bill.Contactor = '';
  4099. }
  4100. bRequestStorage = true;
  4101. });
  4102. oBillBox.find('[data-id="Telephone"]').val(oCur.Telephone);
  4103. oBillBox.find('[data-id="Contactor"]').select2();
  4104. }
  4105. else {
  4106. oBillBox.find('[data-id="Contactor"]').html(createOptions([]));
  4107. oBillBox.find('[data-id="Telephone"]').val('');
  4108. }
  4109. oBillBox.find('[data-id="Telephone"]').change();
  4110. bRequestStorage = true;
  4111. });
  4112. oBillBox.find('.bill-print').each(function () {
  4113. var that = this,
  4114. sTypeId = $(that).attr('data-action'),
  4115. oToolBar = null;
  4116. switch (sTypeId) {
  4117. case 'Print_Bill':
  4118. oToolBar = oPrintMenu.InvoicePrintMenu.tmpl
  4119. break;
  4120. case 'Print_Receipt':
  4121. oToolBar = oPrintMenu.ReceiptPrintMenu.tmpl
  4122. break;
  4123. case 'Download_Bill':
  4124. case 'Download_BatchBill':
  4125. oToolBar = oPrintMenu.InvoiceDownLoadMenu.tmpl
  4126. break;
  4127. case 'Download_Receipt':
  4128. oToolBar = oPrintMenu.ReceiptDownLoadMenu.tmpl
  4129. break;
  4130. }
  4131. $(that).toolbar({
  4132. content: oToolBar,
  4133. position: 'left',
  4134. adjustment: 10,
  4135. style: 'yida',
  4136. }).on('toolbarItemClick',
  4137. function (e, ele) {
  4138. fnPrint($(ele).attr('data-id'), sTypeId, bill);
  4139. }
  4140. );
  4141. });
  4142. oBillBox.find('.btn-custom').not('disabled').off('click').on('click', function () {
  4143. var that = this,
  4144. sId = $(that).attr('data-id');
  4145. switch (sId) {
  4146. case 'plusfeeitem'://新增費用項目
  4147. fnPlusFeeItem(that, Returns, null, bill.Currency);
  4148. break;
  4149. case 'createreceiptnumber'://產生收據號碼
  4150. fnGetReceiptNumber(that, bill).done(function () {
  4151. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  4152. Params: {
  4153. exportexhibition: {
  4154. values: { ReturnBills: JSON.stringify(oCurData.ReturnBills) },
  4155. keys: { ExportBillNO: sDataId }
  4156. }
  4157. }
  4158. });
  4159. });
  4160. break;
  4161. case 'bill_submitaudit'://提交審核
  4162. fnReturnBillToAudit(bill, that);
  4163. break;
  4164. case 'bill_audit'://主管審核
  4165. fnReturnBillAudit(bill);
  4166. break;
  4167. case 'bill_cancelaudit'://取消審核
  4168. fnReturnBillCancelAudit(bill);
  4169. break;
  4170. case 'bill_post'://過帳
  4171. fnReturnBillPost(bill);
  4172. break;
  4173. case 'bill_cancelpost'://取消過帳
  4174. fnReturnBillCancelPost(bill);
  4175. break;
  4176. case 'bill_writeoff'://銷帳
  4177. fnReturnBillWriteOff(bill);
  4178. break;
  4179. case 'bill_canceloff'://取消銷帳
  4180. fnReturnBillCancelWriteOff(bill);
  4181. break;
  4182. case 'bill_void'://作廢
  4183. fnReturnBillVoid(bill);
  4184. break;
  4185. case 'bill_delete'://刪除
  4186. fnReturnBillDelete(bill);
  4187. break;
  4188. case 'bill_reedit'://抽單
  4189. fnReturnBillReEdit(bill);
  4190. break;
  4191. case 'bill_cancelreedit'://取消抽單
  4192. fnReturnBillCancelReEdit(bill);
  4193. break;
  4194. }
  4195. });
  4196. });
  4197. });
  4198. fnSetPermissions();//設置權限
  4199. $('#topshow_box_return').show();//當審通過之後才顯示總金額
  4200. transLang($('#tab5,#tab6'));
  4201. },
  4202. /**
  4203. * 添加新帳單
  4204. */
  4205. fnPushReturnBill = function () {
  4206. var oNewReturnBill = {};
  4207. oNewReturnBill.guid = guid();
  4208. oNewReturnBill.index = oCurData.ReturnBills.length + 1;
  4209. oNewReturnBill.Quote = { guid: guid(), KeyName: 'Quote', AuditVal: '0', FeeItems: [] };
  4210. oNewReturnBill.EstimatedCost = { guid: guid(), KeyName: 'EstimatedCost', AuditVal: '0', FeeItems: [] };
  4211. oNewReturnBill.ActualCost = { guid: guid(), KeyName: 'ActualCost', AuditVal: '0', FeeItems: [] };
  4212. oNewReturnBill.Bills = [];
  4213. oNewReturnBill.CreateDate = newDate();
  4214. oNewReturnBill.ReturnQuotationOrBillingCurrency = ''
  4215. oNewReturnBill.ReturnAccountingExchangeRate = '';
  4216. oCurData.ReturnBills.push(oNewReturnBill);
  4217. fnRenderReturnBills();
  4218. },
  4219. fnReturnBillToAudit = function (bill, el) {
  4220. var sMsg = '',
  4221. elBillBox = $(el).parents('.financial');
  4222. if (!bill.Currency) {
  4223. sMsg += i18next.t("ExhibitionImport_Upd.Currency_required") + '<br/>'; // ╠common.Currency_required⇒請輸入帳單幣別╣
  4224. }
  4225. if (!bill.Payer) {
  4226. sMsg += i18next.t("ExhibitionImport_Upd.Payer_required") + '<br/>'; // ╠ExhibitionImport_Upd.SupplierEamil_required⇒請輸入付款人╣
  4227. }
  4228. if (!bill.Number) {
  4229. sMsg += i18next.t("message.Number_required") + '<br/>'; // ╠message.Number_required⇒請輸入件數╣
  4230. }
  4231. if (!bill.Weight) {
  4232. sMsg += i18next.t("message.Weight_required") + '<br/>'; // ╠message.Weight_required⇒請輸入重量╣
  4233. }
  4234. if (!bill.Volume) {
  4235. sMsg += i18next.t("message.Volume_required") + '<br/>'; // ╠message.Volume_required⇒請輸入材積(CBM)╣
  4236. }
  4237. if (!bill.ReFlow) {
  4238. sMsg += i18next.t("message.ReFlow_required"); // ╠message.ReFlow_required⇒請輸入退運流程╣
  4239. }
  4240. if (elBillBox.find('.jsgrid-update-button').length > 0) {
  4241. sMsg += i18next.t("message.DataEditing") + '<br/>'; // ╠message.DataEditing⇒該賬單處於編輯中╣
  4242. }
  4243. if (sMsg) {
  4244. showMsg(sMsg); // 必填欄位
  4245. return;
  4246. }
  4247. bill.AuditVal = '1';
  4248. g_api.ConnectLite(sProgramId, 'ReturnToAuditForBill', {
  4249. ExportBillNO: sDataId,
  4250. Exhibitors: saGridData,
  4251. ReturnBills: oCurData.ReturnBills,
  4252. Bill: bill
  4253. }, function (res) {
  4254. if (res.RESULT) {
  4255. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4256. showMsg(i18next.t("message.ToAudit_Success"), 'success'); // ╠message.ToAudit_Success⇒提交審核成功╣
  4257. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  4258. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4259. }
  4260. else {
  4261. bill.AuditVal = '0';
  4262. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  4263. }
  4264. }, function () {
  4265. bill.AuditVal = '0';
  4266. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  4267. });
  4268. },
  4269. /**
  4270. * 帳單審核
  4271. * @param bill(object)帳單資料
  4272. */
  4273. fnReturnBillAudit = function (bill) {
  4274. layer.open({
  4275. type: 1,
  4276. title: i18next.t('common.Leader_Audit'),// ╠common.Leader_Audit⇒主管審核╣
  4277. area: ['400px', '260px'],//寬度
  4278. shade: 0.75,//遮罩
  4279. shadeClose: true,
  4280. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  4281. content: '<div class="pop-box">\
  4282. <textarea name="NotPassReason" id="NotPassReason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.NotPassReason" placeholder="不通過原因..."></textarea><br>\
  4283. <button type="button" data-i18n="common.Pass" id="audit_pass" class="btn-custom green">通過</button>\
  4284. <button type="button" data-i18n="common.NotPass" id="audit_notpass" class="btn-custom red">不通過</button>\
  4285. </div>',
  4286. success: function (layero, idx) {
  4287. $('.pop-box :button').click(function () {
  4288. var sNotPassReason = $('#NotPassReason').val();
  4289. if (this.id === 'audit_pass') {
  4290. bill.AuditVal = '2';
  4291. bill.NotPassReason = '';
  4292. }
  4293. else {
  4294. if (!sNotPassReason) {
  4295. showMsg(i18next.t("message.NotPassReason_Required")); // ╠message.NotPassReason_Required⇒請填寫不通過原因╣
  4296. return false;
  4297. }
  4298. else {
  4299. bill.AuditVal = '3';
  4300. bill.NotPassReason = sNotPassReason;
  4301. }
  4302. }
  4303. bill.BillCheckDate = newDate();
  4304. bill.CreateDate = newDate();
  4305. if (!bill.BillFirstCheckDate) {
  4306. bill.BillFirstCheckDate = bill.BillCheckDate;
  4307. }
  4308. g_api.ConnectLite(sProgramId, 'ReturnAuditForBill', {
  4309. ExportBillNO: sDataId,
  4310. ReturnBills: oCurData.ReturnBills,
  4311. Bill: bill
  4312. }, function (res) {
  4313. if (res.RESULT) {
  4314. $('.bill-box-' + bill.BillNO).find('.bill-chewckdate').text(bill.BillCheckDate);
  4315. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4316. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  4317. showMsg(i18next.t("message.Audit_Completed"), 'success'); // ╠message.Audit_Completed⇒審核完成╣
  4318. if (bill.AuditVal === '2') {
  4319. parent.msgs.server.pushTransfer(parent.OrgID, parent.UserID, bill.BillNO, 1);
  4320. }
  4321. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4322. }
  4323. else {
  4324. bill.AuditVal = '1';
  4325. if (bill.BillCheckDate === bill.BillFirstCheckDate) {
  4326. bill.BillFirstCheckDate = '';
  4327. }
  4328. bill.BillCheckDate = '';
  4329. showMsg(i18next.t('message.Audit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  4330. }
  4331. }, function () {
  4332. bill.AuditVal = '1';
  4333. if (bill.BillCheckDate === bill.BillFirstCheckDate) {
  4334. bill.BillFirstCheckDate = '';
  4335. }
  4336. bill.BillCheckDate = '';
  4337. showMsg(i18next.t('message.Audit_Failed'), 'error'); // ╠message.Audit_Failed⇒審核失敗╣
  4338. });
  4339. layer.close(idx);
  4340. });
  4341. transLang(layero);
  4342. }
  4343. });
  4344. },
  4345. /**
  4346. * 會計審核
  4347. * @param bill(object)帳單資料
  4348. */
  4349. fnReturnBillAccountAudit = function (bill) {
  4350. },
  4351. /**
  4352. * 會計取消審核
  4353. * @param bill(object)帳單資料
  4354. */
  4355. fnReturnBillCancelAudit = function (bill) {
  4356. var sBillCheckDate = bill.BillCheckDate;
  4357. bill.AuditVal = '0';
  4358. bill.BillCheckDate = '';
  4359. g_api.ConnectLite(sProgramId, 'ReturnCancelAudit', {
  4360. ExportBillNO: sDataId,
  4361. ReturnBills: oCurData.ReturnBills,
  4362. Bill: bill,
  4363. LogData: fnGetBillLogData(bill)
  4364. }, function (res) {
  4365. if (res.RESULT) {
  4366. $('.bill-box-' + bill.BillNO).find('.bill-chewckdate').text('');
  4367. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4368. showMsg(i18next.t("message.CancelAudit_Success"), 'success'); // ╠message.CancelAudit_Success⇒取消審核完成╣
  4369. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  4370. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4371. }
  4372. else {
  4373. bill.AuditVal = '2';
  4374. bill.BillCheckDate = sBillCheckDate;
  4375. showMsg(i18next.t('message.CancelAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.CancelAudit_Failed⇒取消審核失敗╣
  4376. }
  4377. }, function () {
  4378. bill.AuditVal = '2';
  4379. bill.BillCheckDate = sBillCheckDate;
  4380. showMsg(i18next.t('message.CancelAudit_Failed'), 'error'); // ╠message.CancelAudit_Failed⇒取消審核失敗╣
  4381. });
  4382. },
  4383. /**
  4384. * 過帳
  4385. * @param bill(object)帳單資料
  4386. */
  4387. fnReturnBillPost = function (bill) {
  4388. bill.AuditVal = '5';
  4389. bill.CreateDate = newDate();
  4390. g_api.ConnectLite(sProgramId, 'ReturnBillPost', {
  4391. ExportBillNO: sDataId,
  4392. ReturnBills: oCurData.ReturnBills,
  4393. Bill: bill
  4394. }, function (res) {
  4395. if (res.RESULT) {
  4396. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4397. showMsg(i18next.t("message.BillPost_Success"), 'success'); // ╠message.BillPost_Success⇒過帳完成╣
  4398. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  4399. parent.msgs.server.pushTransfer(parent.OrgID, parent.UserID, bill.BillNO, 1);
  4400. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4401. }
  4402. else {
  4403. bill.AuditVal = '2';
  4404. showMsg(i18next.t('message.BillPost_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillPost_Failed⇒過帳失敗╣
  4405. }
  4406. }, function () {
  4407. bill.AuditVal = '2';
  4408. showMsg(i18next.t('message.BillPost_Failed'), 'error'); // ╠message.BillPost_Failed⇒過帳失敗╣
  4409. });
  4410. },
  4411. /**
  4412. * 取消過帳
  4413. * @param bill(object)帳單資料
  4414. */
  4415. fnReturnBillCancelPost = function (bill) {
  4416. bill.AuditVal = '2';
  4417. g_api.ConnectLite(sProgramId, 'ReturnBillCancelPost', {
  4418. ExportBillNO: sDataId,
  4419. ReturnBills: oCurData.ReturnBills,
  4420. Bill: bill,
  4421. LogData: fnGetBillLogData(bill)
  4422. }, function (res) {
  4423. if (res.RESULT) {
  4424. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4425. showMsg(i18next.t("message.BillCancePost_Success"), 'success'); // ╠message.BillCancePost_Success⇒取消過帳完成╣
  4426. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  4427. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4428. }
  4429. else {
  4430. bill.AuditVal = '5';
  4431. showMsg(i18next.t('message.BillCancePost_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillCancePost_Failed⇒取消過帳失敗╣
  4432. }
  4433. }, function () {
  4434. bill.AuditVal = '5';
  4435. showMsg(i18next.t('message.BillCancePost_Failed'), 'error'); // ╠message.BillCancePost_Failed⇒取消過帳失敗╣
  4436. });
  4437. },
  4438. /**
  4439. * 會計銷帳
  4440. * @param bill(object)帳單資料
  4441. */
  4442. fnReturnBillWriteOff = function (bill) {
  4443. bill.AuditVal = '4';
  4444. bill.BillWriteOffDate = newDate();
  4445. g_api.ConnectLite(sProgramId, 'ReturnWriteOff', {
  4446. ExportBillNO: sDataId,
  4447. ReturnBills: oCurData.ReturnBills,
  4448. Bill: bill
  4449. }, function (res) {
  4450. if (res.RESULT) {
  4451. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4452. showMsg(i18next.t("message.BillWriteOff_Success"), 'success'); // ╠message.BillWriteOff_Success⇒銷帳完成╣
  4453. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  4454. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4455. }
  4456. else {
  4457. bill.AuditVal = '5';
  4458. showMsg(i18next.t('message.BillWriteOff_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillWriteOff_Failed⇒銷帳失敗╣
  4459. }
  4460. }, function () {
  4461. bill.AuditVal = '5';
  4462. showMsg(i18next.t('message.BillWriteOff_Failed'), 'error'); // ╠message.BillWriteOff_Failed⇒銷帳失敗╣
  4463. });
  4464. },
  4465. /**
  4466. * 會計取消銷帳
  4467. * @param bill(object)帳單資料
  4468. */
  4469. fnReturnBillCancelWriteOff = function (bill) {
  4470. bill.AuditVal = '5';
  4471. bill.BillWriteOffDate = '';
  4472. g_api.ConnectLite(sProgramId, 'ReturnCancelWriteOff', {
  4473. ExportBillNO: sDataId,
  4474. ReturnBills: oCurData.ReturnBills,
  4475. Bill: bill,
  4476. LogData: fnGetBillLogData(bill)
  4477. }, function (res) {
  4478. if (res.RESULT) {
  4479. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4480. showMsg(i18next.t("message.BillCancelWriteOff_Success"), 'success'); // ╠message.BillCancelWriteOff_Success⇒取消銷帳完成╣
  4481. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4482. }
  4483. else {
  4484. bill.AuditVal = '4';
  4485. showMsg(i18next.t('message.BillCancelWriteOff_Failed') + '<br>' + res.MSG, 'error'); // ╠message.BillCancelWriteOff_Failed⇒取消銷帳失敗╣
  4486. }
  4487. }, function () {
  4488. bill.AuditVal = '4';
  4489. showMsg(i18next.t('message.BillCancelWriteOff_Failed'), 'error'); // ╠message.BillCancelWriteOff_Failed⇒取消銷帳失敗╣
  4490. });
  4491. },
  4492. /**
  4493. * 帳單作廢
  4494. * @param bill(object)帳單資料
  4495. */
  4496. fnReturnBillVoid = function (bill) {
  4497. layer.open({
  4498. type: 1,
  4499. title: i18next.t('common.VoidBill'),// ╠common.VoidBill⇒作廢帳單╣
  4500. area: ['400px', '220px'],//寬度
  4501. shade: 0.75,//遮罩
  4502. shadeClose: true,
  4503. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  4504. content: '<div class="pop-box">\
  4505. <textarea name="VoidReason" id="VoidReason" style="min-width:300px;" class="form-control" rows="5" cols="20" placeholderid="common.VoidReason" placeholder="作廢原因..."></textarea>\
  4506. </div>',
  4507. success: function (layero, idx) {
  4508. transLang(layero);
  4509. },
  4510. yes: function (index, layero) {
  4511. var sAuditVal = bill.AuditVal,
  4512. sVoidReason = layero.find('#VoidReason').val();
  4513. if (sVoidReason) {
  4514. bill.VoidReason = sVoidReason;
  4515. bill.AuditVal = '6';
  4516. g_api.ConnectLite(sProgramId, 'ReturnBillVoid', {
  4517. ExportBillNO: sDataId,
  4518. ReturnBills: oCurData.ReturnBills,
  4519. Bill: bill,
  4520. LogData: fnGetBillLogData(bill)
  4521. }, function (res) {
  4522. if (res.RESULT) {
  4523. layer.close(index);
  4524. showMsg(i18next.t("message.Void_Success"), 'success'); // ╠message.Void_Success⇒作廢成功╣
  4525. fnRenderReturnBills();
  4526. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  4527. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4528. }
  4529. else {
  4530. bill.AuditVal = sAuditVal;
  4531. bill.VoidReason = '';
  4532. showMsg(i18next.t('message.Void_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  4533. }
  4534. }, function () {
  4535. bill.AuditVal = sAuditVal;
  4536. bill.VoidReason = '';
  4537. showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  4538. });
  4539. }
  4540. else {
  4541. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  4542. }
  4543. }
  4544. });
  4545. },
  4546. /**
  4547. * 帳單刪除
  4548. * @param bill(object)帳單資料
  4549. */
  4550. fnReturnBillDelete = function (bill) {
  4551. // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  4552. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  4553. var saNewBills = [];
  4554. $.each(oCurData.ReturnBills, function (idx, Returns) {
  4555. if (Returns.guid === bill.parentid) {
  4556. var saNewBills = [];
  4557. $.each(Returns.Bills, function (i, _bill) {
  4558. if (_bill.BillNO !== bill.BillNO) {
  4559. saNewBills.push(_bill);
  4560. }
  4561. });
  4562. Returns.Bills = saNewBills;
  4563. return false;
  4564. }
  4565. });
  4566. g_api.ConnectLite(sProgramId, 'ReturnBillDelete', {
  4567. ExportBillNO: sDataId,
  4568. ReturnBills: oCurData.ReturnBills,
  4569. Bill: bill,
  4570. LogData: fnGetBillLogData(bill)
  4571. }, function (res) {
  4572. if (res.RESULT) {
  4573. showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣
  4574. fnRenderReturnBills();
  4575. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  4576. fnDeleteBillInfo(bill.BillNO);
  4577. }
  4578. else {
  4579. showMsg(i18next.t("message.Delete_Failed") + '<br>' + res.MSG, 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  4580. }
  4581. }, function () {
  4582. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  4583. });
  4584. layer.close(index);
  4585. });
  4586. },
  4587. /**
  4588. * 抽單
  4589. * @param bill(object)帳單資料
  4590. */
  4591. fnReturnBillReEdit = function (bill) {
  4592. bill.AuditVal = '7';
  4593. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  4594. Params: {
  4595. exportexhibition: {
  4596. values: { ReturnBills: JSON.stringify(oCurData.ReturnBills) },
  4597. keys: { ExportBillNO: sDataId }
  4598. }
  4599. }
  4600. }, function (res) {
  4601. if (res.d > 0) {
  4602. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4603. showMsg(i18next.t("message.ReEdit_Success"), 'success'); // ╠message.ReEdit_Success⇒抽單成功╣
  4604. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4605. }
  4606. else {
  4607. bill.AuditVal = '1';
  4608. showMsg(i18next.t('message.ReEdit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  4609. }
  4610. }, function () {
  4611. bill.AuditVal = '1';
  4612. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  4613. });
  4614. },
  4615. /**
  4616. * 取消抽單
  4617. * @param bill(object)帳單資料
  4618. */
  4619. fnReturnBillCancelReEdit = function (bill) {
  4620. bill.AuditVal = '1';
  4621. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  4622. Params: {
  4623. exportexhibition: {
  4624. values: { ReturnBills: JSON.stringify(oCurData.ReturnBills) },
  4625. keys: { ExportBillNO: sDataId }
  4626. }
  4627. }
  4628. }, function (res) {
  4629. if (res.d > 0) {
  4630. fnSetDisabled($('.bill-box-' + bill.BillNO), bill);
  4631. showMsg(i18next.t("message.CancelReEdit_Success"), 'success'); // ╠message.CancelReEdit_Success⇒取消抽單成功╣
  4632. fnUpdateBillInfo(sProgramId, sDataId, bill.BillNO);
  4633. }
  4634. else {
  4635. bill.AuditVal = '7';
  4636. showMsg(i18next.t('message.CancelReEdit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.CancelReEdit_Failed⇒取消抽單失敗╣
  4637. }
  4638. }, function () {
  4639. bill.AuditVal = '7';
  4640. showMsg(i18next.t('message.CancelReEdit_Failed'), 'error'); // ╠message.CancelReEdit_Failed⇒取消抽單失敗╣
  4641. });
  4642. },
  4643. /**------------------------退運帳單部分---------------------------End*/
  4644. /**
  4645. * Grid初始化
  4646. */
  4647. fnGridInit = function () {
  4648. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 120;
  4649. $("#jsGrid").jsGrid({
  4650. width: "100%",
  4651. height: "auto",
  4652. autoload: true,
  4653. filtering: true,
  4654. pageLoading: true,
  4655. inserting: true,
  4656. editing: true,
  4657. sorting: false,
  4658. paging: false,
  4659. pageIndex: 1,
  4660. pageSize: parent.SysSet.GridRecords || 10,
  4661. invalidMessage: i18next.t('common.InvalidData'),// ╠common.InvalidData⇒输入的数据无效!╣
  4662. confirmDeleting: true,
  4663. deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
  4664. pagePrevText: "<",
  4665. pageNextText: ">",
  4666. pageFirstText: "<<",
  4667. pageLastText: ">>",
  4668. rowClass: function (item) {
  4669. if (item.VoidContent) {
  4670. return 'data-void';
  4671. }
  4672. },
  4673. fields: [
  4674. {
  4675. name: "RowIndex", title: 'common.RowNumber', width: 50, align: "center", sorting: false,
  4676. itemTemplate: function (val, item) {
  4677. var sVal = val || '';
  4678. if (item.VoidContent) {// ╠common.Toolbar_Void⇒作廢╣
  4679. sVal = '<span class="tooltips" title="' + i18next.t('common.Toolbar_Void') + ':' + item.VoidContent + '">' + sVal + '</span>';
  4680. }
  4681. return sVal;
  4682. }
  4683. },
  4684. {//╠common.SupplierName⇒客戶/參展廠商名稱╣
  4685. name: "SupplierName", title: 'common.SupplierName', width: 150, filtering: true, inserting: true, editing: false, validate: { validator: 'required', message: i18next.t('common.Supplier_required') },
  4686. insertTemplate: function () {
  4687. var oSelect = $('<select/>', {
  4688. change: function () {
  4689. var sCustomerId = this.value,
  4690. sRefSupplierNo = $('#RefNumber').val() + rndnum(3);
  4691. if (sCustomerId) {
  4692. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === sCustomerId; }).First();
  4693. oAddItem.guid = guid();
  4694. oAddItem.SupplierID = oCur.id;
  4695. oAddItem.CustomerNO = oCur.CusNO;
  4696. oAddItem.UniCode = oCur.UniCode;
  4697. oAddItem.SupplierName = oCur.textcn;
  4698. oAddItem.SupplierEName = oCur.texteg;
  4699. oAddItem.RefSupplierNo = sRefSupplierNo;
  4700. oAddItem.Telephone = oCur.Telephone;
  4701. oAddItem.Email = oCur.Email;
  4702. oAddItem.ContactorName = '';
  4703. oAddItem.CreateUser = parent.UserID;
  4704. oAddItem.CreateDate = new Date().formate("yyyy/MM/dd HH:mm:ss");
  4705. oSelect.parent().next().find(':input').val(oAddItem.SupplierEName);
  4706. oSelect.parent().next().next().find(':input').val(sRefSupplierNo);
  4707. var saContactors = JSON.parse(oCur.Contactors || '[]');
  4708. oSelect.parent().next().next().next().find('select').html(createOptions(saContactors, 'guid', 'FullName')).on('change', function () {
  4709. var sContactor = this.value;
  4710. if (sContactor) {
  4711. var oContactor = Enumerable.From(saContactors).Where(function (e) { return e.guid === sContactor; }).First();
  4712. $(this).parent().next().find(':input').val(oContactor.TEL1);
  4713. $(this).parent().next().next().find(':input').val(oContactor.Email);
  4714. oAddItem.Contactor = sContactor;
  4715. oAddItem.ContactorName = oContactor.FullName;
  4716. oAddItem.Telephone = oContactor.TEL1;
  4717. oAddItem.Email = oContactor.Email;
  4718. }
  4719. else {
  4720. oAddItem.Contactor = '';
  4721. oAddItem.ContactorName = '';
  4722. oAddItem.Telephone = '';
  4723. oAddItem.Email = '';
  4724. $(this).parent().next().find(':input').val('');
  4725. $(this).parent().next().next().find(':input').val('');
  4726. }
  4727. });
  4728. oSelect.parent().next().next().next().next().find(':input').val(oCur.Telephone);
  4729. oSelect.parent().next().next().next().next().next().find(':input').val(oCur.Email);
  4730. }
  4731. else {
  4732. oSelect.parent().next().next().next().find('select').html(createOptions([]));
  4733. oAddItem = {};
  4734. }
  4735. bRequestStorage = true;
  4736. }
  4737. });
  4738. setTimeout(function () {
  4739. oSelect.html(sCustomersNotAuditOptionsHtml).select2({ width: '180px' });
  4740. }, 1000);
  4741. return this.insertControl = oSelect;
  4742. },
  4743. insertValue: function () {
  4744. return this.insertControl.val();
  4745. },
  4746. filterTemplate: function () {
  4747. var oSelect = $('<select/>', {
  4748. change: function () {
  4749. var sCustomerId = this.value;
  4750. if (sCustomerId) {
  4751. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === sCustomerId; }).First();
  4752. var saContactors = JSON.parse(oCur.Contactors || '[]');
  4753. oSelect.parent().next().next().next().find('select').html(createOptions(saContactors, 'guid', 'FullName'))
  4754. }
  4755. else {
  4756. oSelect.parent().next().next().next().find('select').html(createOptions([]));
  4757. }
  4758. bRequestStorage = true;
  4759. }
  4760. });
  4761. setTimeout(function () {
  4762. oSelect.html(sCustomersOptionsHtml).select2({ width: '180px' });
  4763. }, 1000);
  4764. return this.filterControl = oSelect;
  4765. },
  4766. filterValue: function () {
  4767. return this.filterControl.val() === '' ? '' : this.filterControl.find("option:selected").text();
  4768. }
  4769. },
  4770. {//╠common.SupplierEName⇒客戶/參展廠商英文名稱╣
  4771. name: "SupplierEName", title: 'common.SupplierEName', width: 150, filtering: true, inserting: true, editing: false,
  4772. insertTemplate: function () {
  4773. return this.insertControl = $('<input/>', { type: 'text', class: 'form-control w100p', disabled: true });
  4774. }, insertValue: function () {
  4775. return this.insertControl.val();
  4776. }, filterTemplate: function () {
  4777. return this.filterControl = $('<input/>', { type: 'text' });
  4778. }, filterValue: function () {
  4779. return this.filterControl.val();
  4780. }
  4781. },
  4782. {//╠common.RefSupplierNo⇒客戶/廠商查詢號碼╣
  4783. name: "RefSupplierNo", title: 'common.RefSupplierNo', width: 100, filtering: true, inserting: true, editing: false,
  4784. insertTemplate: function () {
  4785. return this.insertControl = $('<input/>', { type: 'text', class: 'form-control w100p', disabled: true });
  4786. }, insertValue: function () {
  4787. return this.insertControl.val();
  4788. }, filterTemplate: function () {
  4789. return this.filterControl = $('<input/>', { type: 'text' });
  4790. }, filterValue: function () {
  4791. return this.filterControl.val();
  4792. }
  4793. },
  4794. {
  4795. name: "Contactor", title: 'common.Contactor', type: "text", filtering: true, width: 100,
  4796. itemTemplate: function (val, item) {
  4797. return item.ContactorName;
  4798. },
  4799. insertTemplate: function () {
  4800. return this.insertControl = $('<select/>', {
  4801. html: createOptions([])
  4802. });
  4803. }, insertValue: function () {
  4804. return this.insertControl.val();
  4805. },
  4806. editTemplate: function (val, item) {
  4807. var saContactors = [];
  4808. if (item.SupplierID) {
  4809. var saCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === item.SupplierID; }).ToArray();
  4810. if (saCur.length > 0) {
  4811. saContactors = JSON.parse(saCur[0].Contactors || '[]');
  4812. }
  4813. }
  4814. return this.editControl = $('<select/>', {
  4815. html: createOptions(saContactors, 'guid', 'FullName'),
  4816. change: function () {
  4817. var sContactor = this.value;
  4818. if (sContactor) {
  4819. var oContactor = Enumerable.From(saContactors).Where(function (e) { return e.guid === sContactor; }).First();
  4820. $(this).parent().next().find(':input').val(oContactor.TEL1);
  4821. $(this).parent().next().next().find(':input').val(oContactor.Email);
  4822. item.Contactor = sContactor;
  4823. item.ContactorName = oContactor.FullName;
  4824. item.Telephone = oContactor.TEL1;
  4825. item.Email = oContactor.Email;
  4826. }
  4827. else {
  4828. item.Contactor = '';
  4829. item.ContactorName = '';
  4830. item.Telephone = '';
  4831. item.Email = '';
  4832. $(this).parent().next().find(':input').val('');
  4833. $(this).parent().next().next().find(':input').val('');
  4834. }
  4835. bRequestStorage = true;
  4836. }
  4837. }).val(val);
  4838. },
  4839. editValue: function () {
  4840. return this.editControl.val();
  4841. }
  4842. },
  4843. { name: "Telephone", title: 'common.Telephone', type: "text", filtering: true, width: 100 },
  4844. { name: "Email", title: 'common.Email', type: "text", filtering: true, width: 130 },
  4845. {
  4846. name: "Flow_Status", title: 'common.Flow_Status', type: "text", width: 80, filtering: true, editing: false, inserting: false,
  4847. filterTemplate: function () {
  4848. return this.filterControl = $('<select/>', {
  4849. class: 'form-control w100p',
  4850. html: '<option value="">請選擇...</option>'
  4851. + '<option value="已收文件">已收文件</option>'
  4852. + '<option value="貨物進倉">貨物進倉</option>'
  4853. + '<option value="報關作業">報關作業</option>'
  4854. + '<option value="出口放行">出口放行</option>'
  4855. + '<option value="航行中">航行中</option>'
  4856. + '<option value="貨物抵港">貨物抵港</option>'
  4857. + '<option value="貨物放行">貨物放行</option>'
  4858. + '<option value="等待進場">等待進場</option>'
  4859. + '<option value="送達攤位">送達攤位</option>'
  4860. + ' <option value="退運">退運</option>'
  4861. });
  4862. }, filterValue: function () {
  4863. return this.filterControl.val();
  4864. }
  4865. },
  4866. {// ╠common.Other⇒其他╣
  4867. title: 'common.Other', width: 200,
  4868. itemTemplate: function (val, item) {
  4869. var oDom = [$("<a/>", {
  4870. html: i18next.t('ExhibitionExport_Upd.ExportOperationFlow'),// ╠ExhibitionExport_Upd.ExportOperationFlow⇒出口作業流程╣
  4871. class: 'a-url',
  4872. click: function () {
  4873. showWaiting();
  4874. oCurSupplierData = item;
  4875. layer.open({
  4876. type: 2,
  4877. title: i18next.t('ExhibitionExport_Upd.ExportOperationFlow'),// ╠ExhibitionExport_Upd.ExportOperationFlow⇒出口作業流程╣
  4878. shade: 0.75,
  4879. maxmin: true, //开启最大化最小化按钮
  4880. area: ['90%', '80%'],
  4881. content: '/Page/Pop/ExportFlowPop.html',
  4882. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  4883. success: function (layero, index) {
  4884. var iframe = $('iframe').contents(),
  4885. oForm = iframe.find('#form_ExportFlowPop');
  4886. //加載運輸方式, 加載機場, 加載貨棧場, 加載倉庫
  4887. if (item.ClearanceData && !item.ClearanceData.WaitingApproach) {
  4888. oForm.find('#ClearanceData_WaitingApproach_Checked').parents('.form-group').remove();
  4889. }
  4890. fnSGMod(oForm.find('.shjy-box'));//上海駒驛須移除選項
  4891. oForm.find('.Control_Transport').html(sTransportOptionsHtml);
  4892. setFormVal(oForm, item);
  4893. setFlowBox(oForm, item);
  4894. saBatchArr = [];
  4895. iframe.find('#IsBatch').click(function () {
  4896. var that = this;
  4897. if (that.checked) {
  4898. if (saGridData.length > 1) {
  4899. var oConfig = {
  4900. Id: 'PopIsBatch',
  4901. Title: i18next.t('common.SelectBatchList'),// ╠common.SelectBatchList⇒請選擇要批次操作的資料╣
  4902. PageSize: 10000,
  4903. Get: fnGetPop_CusSupplier,
  4904. SearchFields: [
  4905. { id: "Pop_SupplierName", type: 'text', i18nkey: 'common.SupplierName' },
  4906. { id: "Pop_SupplierEName", type: 'text', i18nkey: 'common.SupplierEName' }
  4907. ],
  4908. Fields: [
  4909. { name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 50 },
  4910. { name: "CustomerNO", title: 'Customers_Upd.CustomerNO', width: 80 },
  4911. { name: "SupplierName", title: 'common.SupplierName', width: 150 },
  4912. { name: "SupplierEName", title: 'common.SupplierEName', width: 150 }
  4913. ],
  4914. Callback: function (items) {
  4915. $.each(items, function (idx, _item) {
  4916. saBatchArr.push(_item.guid);
  4917. });
  4918. if (saBatchArr.length === 0) {
  4919. $(that).click();
  4920. }
  4921. },
  4922. CancelCallback: function () {
  4923. $(that).click();
  4924. }
  4925. };
  4926. oPenPopm(oConfig);
  4927. }
  4928. }
  4929. else {
  4930. saBatchArr = [];
  4931. }
  4932. });
  4933. iframe.find('.quickquery-city').off('keyup').on('keyup', function () {
  4934. this.value = this.value.toUpperCase();
  4935. }).off('blur').on('blur', function () {
  4936. var sId = this.value,
  4937. oPort = Enumerable.From(saPort).Where(function (e) { return e.id === sId; });
  4938. if (oPort.Count() === 1) {
  4939. $(this).parent().next().next().find(':input').val(oPort.First().text);
  4940. }
  4941. }).autocompleter({
  4942. // marker for autocomplete matches
  4943. highlightMatches: true,
  4944. // object to local or url to remote search
  4945. source: saPort,
  4946. // custom template
  4947. template: '{{ id }} <span>({{ label }})</span>',
  4948. // show hint
  4949. hint: true,
  4950. // abort source if empty field
  4951. empty: false,
  4952. // max results
  4953. limit: 20,
  4954. callback: function (value, index, selected) {
  4955. if (selected) {
  4956. var that = this;
  4957. $(that).parent().find(':input').val(selected.id);
  4958. $(that).parent().next().next().find(':input').val(selected.text);
  4959. }
  4960. }
  4961. });
  4962. transLang(iframe);
  4963. closeWaiting();
  4964. },
  4965. yes: function (index, layero) {
  4966. var iframe = $('iframe').contents(),
  4967. oForm = iframe.find('#form_ExportFlowPop'),
  4968. newData = getFormSerialize(oForm);
  4969. delete item.ExportData;
  4970. delete item.ClearanceData;
  4971. delete item.ReImport;
  4972. delete item.TranserThird;
  4973. delete item.PartThird;
  4974. delete item.PartReImport;
  4975. delete item.ReImportFour;
  4976. delete item.TransferFour;
  4977. delete item.ReImportFive;
  4978. delete item.TransferFive;
  4979. delete item.ReImportSix;
  4980. delete item.TransferSix;
  4981. delete item.ReturnType;
  4982. delete item.LastReturnType;
  4983. delete item.ReturnType_4;
  4984. delete item.ReturnType_5;
  4985. if (newData.ReturnType === '') {
  4986. delete newData.ReImport;
  4987. delete newData.TranserThird;
  4988. delete newData.PartThird;
  4989. delete newData.PartReImport;
  4990. delete newData.TransferFour;
  4991. delete newData.ReImportFour;
  4992. delete newData.ReImportFive;
  4993. delete newData.TransferFive;
  4994. delete newData.ReImportSix;
  4995. delete newData.TransferSix;
  4996. delete newData.LastReturnType;
  4997. delete newData.ReturnType_4;
  4998. delete newData.ReturnType_5;
  4999. }
  5000. else if (newData.ReturnType === 'H') {
  5001. delete newData.TranserThird;
  5002. delete newData.PartThird;
  5003. delete newData.PartReImport;
  5004. delete newData.TransferFour;
  5005. delete newData.ReImportFour;
  5006. delete newData.ReImportFive;
  5007. delete newData.TransferFive;
  5008. delete newData.ReImportSix;
  5009. delete newData.TransferSix;
  5010. delete newData.LastReturnType;
  5011. delete newData.ReturnType_4;
  5012. delete newData.ReturnType_5;
  5013. }
  5014. else if (newData.ReturnType === 'T') {
  5015. delete newData.ReImport;
  5016. delete newData.PartThird;
  5017. delete newData.PartReImport;
  5018. if (newData.LastReturnType === '') {
  5019. delete newData.TransferFour;
  5020. delete newData.ReImportFour;
  5021. delete newData.ReImportFive;
  5022. delete newData.TransferFive;
  5023. delete newData.ReImportSix;
  5024. delete newData.TransferSix;
  5025. delete newData.LastReturnType;
  5026. delete newData.ReturnType_4;
  5027. delete newData.ReturnType_5;
  5028. }
  5029. else if (newData.LastReturnType === 'H') {
  5030. delete newData.TransferFour;
  5031. delete newData.ReImportFive;
  5032. delete newData.TransferFive;
  5033. delete newData.ReImportSix;
  5034. delete newData.TransferSix;
  5035. delete newData.ReturnType_4;
  5036. delete newData.ReturnType_5;
  5037. }
  5038. else if (newData.LastReturnType === 'F') {
  5039. delete newData.ReImportFour;
  5040. if (newData.ReturnType_4 === '') {
  5041. delete newData.ReImportFive;
  5042. delete newData.TransferFive;
  5043. delete newData.ReImportSix;
  5044. delete newData.TransferSix;
  5045. delete newData.ReturnType_5;
  5046. }
  5047. else if (newData.ReturnType_4 === 'H') {
  5048. delete newData.TransferFive;
  5049. delete newData.ReImportSix;
  5050. delete newData.TransferSix;
  5051. delete newData.ReturnType_5;
  5052. }
  5053. else if (newData.ReturnType_4 === 'F') {
  5054. delete newData.ReImportFive;
  5055. if (newData.ReturnType_5 === '') {
  5056. delete newData.ReImportSix;
  5057. delete newData.TransferSix;
  5058. delete newData.ReturnType_5;
  5059. }
  5060. else if (newData.ReturnType_5 === 'H') {
  5061. delete newData.TransferSix;
  5062. }
  5063. else if (newData.ReturnType_5 === 'F') {
  5064. delete newData.ReImportSix;
  5065. }
  5066. }
  5067. }
  5068. }
  5069. else {
  5070. delete newData.TranserThird;
  5071. delete newData.ReImport;
  5072. delete newData.TransferFour;
  5073. delete newData.ReImportFour;
  5074. delete newData.ReImportFive;
  5075. delete newData.TransferFive;
  5076. delete newData.ReImportSix;
  5077. delete newData.TransferSix;
  5078. delete newData.LastReturnType;
  5079. delete newData.ReturnType_4;
  5080. delete newData.ReturnType_5;
  5081. }
  5082. newData.Flow_Status = oCurData.Flow_Status = fnGetFlowStatus(newData);
  5083. $.extend(item, item, newData);
  5084. var saOthers = Enumerable.From(saGridData).Where(function (_item) { return _item.guid !== item.guid; }).ToArray();
  5085. saOthers.push(item);
  5086. saGridData = saOthers;
  5087. if (saBatchArr.length > 0) {
  5088. $.each(saGridData, function (idx, _item) {
  5089. if (saBatchArr.indexOf(_item.guid) > -1 && _item.guid !== oCurSupplierData.guid) {
  5090. var oMach = clone(newData),
  5091. iExportData_Intowarehouse_Number = 0,
  5092. iTranserThird_Number = 0;
  5093. if (oMach.ReturnType === '') {
  5094. iExportData_Intowarehouse_Number = !(_item.ExportData) ? 0 : _item.ExportData.Intowarehouse.Number || 0;
  5095. _item.ExportData = oMach.ExportData;
  5096. _item.ClearanceData = oMach.ClearanceData;
  5097. _item.ExportData.Intowarehouse.Number = iExportData_Intowarehouse_Number;
  5098. }
  5099. else if (oMach.ReturnType === 'H') {
  5100. var iReImport_Number = !(_item.ReImport) ? 0 : _item.ReImport.Number || 0;
  5101. iExportData_Intowarehouse_Number = !(_item.ExportData) ? 0 : _item.ExportData.Intowarehouse.Number || 0
  5102. _item.ExportData = oMach.ExportData;
  5103. _item.ClearanceData = oMach.ClearanceData;
  5104. _item.ReImport = oMach.ReImport;
  5105. _item.ExportData.Intowarehouse.Number = iExportData_Intowarehouse_Number;
  5106. _item.ReImport.Number = iReImport_Number;
  5107. }
  5108. else if (oMach.ReturnType === 'T' && oMach.LastReturnType === 'H') {
  5109. var iReImportFour_Number = !(_item.ReImportFour) ? 0 : _item.ReImportFour.Number || 0;
  5110. iExportData_Intowarehouse_Number = !(_item.ExportData) ? 0 : _item.ExportData.Intowarehouse.Number || 0;
  5111. iTranserThird_Number = !(_item.TranserThird) ? 0 : _item.TranserThird.Number || 0;
  5112. _item.ExportData = oMach.ExportData;
  5113. _item.ClearanceData = oMach.ClearanceData;
  5114. _item.TranserThird = oMach.TranserThird;
  5115. _item.ReImportFour = oMach.ReImportFour;
  5116. _item.ExportData.Intowarehouse.Number = iExportData_Intowarehouse_Number;
  5117. _item.TranserThird.Number = iTranserThird_Number;
  5118. _item.ReImportFour.Number = iReImportFour_Number;
  5119. }
  5120. else if (oMach.ReturnType === 'T' && oMach.LastReturnType === 'F') {
  5121. var iTransferFour_Number = !(_item.TransferFour) ? 0 : _item.TransferFour.Number || 0;
  5122. iExportData_Intowarehouse_Number = !(_item.ExportData) ? 0 : _item.ExportData.Intowarehouse.Number || 0;
  5123. iTranserThird_Number = !(_item.TranserThird) ? 0 : _item.TranserThird.Number || 0;
  5124. _item.ExportData = oMach.ExportData;
  5125. _item.ClearanceData = oMach.ClearanceData;
  5126. _item.TranserThird = oMach.TranserThird;
  5127. _item.TransferFour = oMach.TransferFour;
  5128. _item.ExportData.Intowarehouse.Number = iExportData_Intowarehouse_Number;
  5129. _item.TranserThird.Number = iTranserThird_Number;
  5130. _item.TransferFour.Number = iTransferFour_Number;
  5131. }
  5132. else if (oMach.ReturnType === 'T') {
  5133. iTranserThird_Number = !(_item.TranserThird) ? 0 : _item.TranserThird.Number || 0;
  5134. iExportData_Intowarehouse_Number = !(_item.ExportData) ? 0 : _item.ExportData.Intowarehouse.Number || 0;
  5135. _item.ExportData = oMach.ExportData;
  5136. _item.ClearanceData = oMach.ClearanceData;
  5137. _item.TranserThird = oMach.TranserThird;
  5138. _item.ExportData.Intowarehouse.Number = iExportData_Intowarehouse_Number;
  5139. _item.TranserThird.Number = iTranserThird_Number;
  5140. }
  5141. else if (oMach.ReturnType === 'P') {
  5142. var iPartThird_Number = !(_item.PartThird) ? 0 : _item.PartThird.Number || 0,
  5143. iPartReImport_Number = !(_item.PartReImport) ? 0 : _item.PartReImport.Number || 0;
  5144. iExportData_Intowarehouse_Number = !(_item.ExportData) ? 0 : _item.ExportData.Intowarehouse.Number || 0;
  5145. _item.ExportData = oMach.ExportData;
  5146. _item.ClearanceData = oMach.ClearanceData;
  5147. _item.PartThird = oMach.PartThird;
  5148. _item.PartReImport = oMach.PartReImport;
  5149. _item.ExportData.Intowarehouse.Number = iExportData_Intowarehouse_Number;
  5150. _item.PartThird.Number = iPartThird_Number;
  5151. _item.PartReImport.Number = iPartReImport_Number;
  5152. }
  5153. _item.ReturnType = oMach.ReturnType;
  5154. _item.LastReturnType = oMach.LastReturnType;
  5155. _item.Flow_Status = fnGetFlowStatus(_item);
  5156. }
  5157. });
  5158. oGrid.loadData();
  5159. }
  5160. layer.close(index);
  5161. }
  5162. });
  5163. return false;
  5164. }
  5165. }),//出口作業流程
  5166. $('<a/>', {
  5167. html: i18next.t('common.MailTrackingNumber'),// ╠common.MailTrackingNumber⇒寄送客戶查詢碼╣
  5168. class: item.guid + ((oCurData.IsSendMail || '').indexOf(item.guid) > -1 ? ' a-mailurl' : ' a-url'),
  5169. click: function () {
  5170. fnSendTrackingNumberEmail(item);
  5171. return false;
  5172. }
  5173. })
  5174. ],
  5175. oVoid = $('<a/>', {
  5176. // ╠common.Toolbar_OpenVoid⇒啟用╣ ╠common.Toolbar_Void⇒作廢╣
  5177. html: item.VoidContent !== undefined ? i18next.t('common.Toolbar_OpenVoid') : i18next.t('common.Toolbar_Void'),
  5178. class: 'a-url',
  5179. click: function () {
  5180. var that = this;
  5181. if (item.VoidContent) {
  5182. delete item.VoidContent;
  5183. $(that).text(i18next.t('common.Toolbar_Void'));// ╠common.Toolbar_Void⇒作廢╣
  5184. $(that).parents('tr').removeClass('data-void').removeAttr('title');
  5185. }
  5186. else {
  5187. layer.open({
  5188. type: 1,
  5189. title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣
  5190. shade: 0.75,
  5191. maxmin: true, //开启最大化最小化按钮
  5192. area: ['500px', '250px'],
  5193. content: '<div class="pop-box">\
  5194. <textarea name="VoidContent" id="VoidContent" style="min-width:300px;" class="form-control" rows="5" cols="20"></textarea>\
  5195. </div>',
  5196. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  5197. success: function (layero, index) {
  5198. },
  5199. yes: function (index, layero) {
  5200. var sVoidContent = $('#VoidContent').val();
  5201. item.VoidContent = sVoidContent;
  5202. if (!sVoidContent) {
  5203. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  5204. return false;
  5205. }
  5206. $(that).text(i18next.t('common.Toolbar_OpenVoid'));// ╠common.Toolbar_OpenVoid⇒啟用╣
  5207. $(that).parents('tr').addClass('data-void').attr('title', i18next.t('common.Toolbar_Void') + ':' + sVoidContent);// ╠common.Toolbar_Void⇒作廢╣
  5208. layer.close(index);
  5209. }
  5210. });
  5211. }
  5212. return false;
  5213. }
  5214. }),
  5215. oCreateBill = $('<a/>', {
  5216. html: i18next.t('common.CreateBill'),// ╠common.CreateBill⇒建立帳單╣
  5217. class: 'a-url',
  5218. click: function () {
  5219. var that = this;
  5220. $(that).hide();
  5221. fnPushBill(item, oCurData, item.guid, false).done(function () {
  5222. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  5223. Params: {
  5224. exportexhibition: {
  5225. values: {
  5226. Bills: JSON.stringify(oCurData.Bills),
  5227. Exhibitors: JSON.stringify(saGridData)
  5228. },
  5229. keys: { ExportBillNO: sDataId }
  5230. }
  5231. }
  5232. }, function (res) {
  5233. if (res.d > 0) {
  5234. fnBindBillLists();
  5235. $(that).remove();
  5236. showMsg(i18next.t("common.Create_Success"), 'success'); // ╠common.Create_Success⇒創建成功╣
  5237. }
  5238. else {
  5239. $(that).show();
  5240. showMsg(i18next.t("common.Create_Failed"), 'error'); // ╠common.Create_Failed⇒創建失敗╣
  5241. }
  5242. });
  5243. });
  5244. return false;
  5245. }
  5246. });
  5247. if ((item.VoidContent && parent.UserInfo.IsManager) || !item.VoidContent) {
  5248. oDom.push(oVoid);
  5249. }
  5250. if (oCurData.Quote.AuditVal === '2' && !item.VoidContent) {
  5251. var iExsitVoid = Enumerable.From(oCurData.Bills).Where(function (e) { return (e.parentid === item.guid && e.VoidReason); }).Count();
  5252. var iExsit = Enumerable.From(oCurData.Bills).Where(function (e) { return e.parentid === item.guid; }).Count();
  5253. if (iExsit === 0 || (iExsit - iExsitVoid) === 0) {
  5254. oDom.push(oCreateBill);
  5255. }
  5256. }
  5257. return $('<div>', { 'style': 'width:100%;text-align: center;' }).append(oDom);
  5258. }
  5259. },
  5260. { type: "control" }
  5261. ],
  5262. controller: {
  5263. loadData: function (args) {
  5264. if (sAction === 'Upd') {
  5265. if (saGridData.length > 0) {
  5266. $('.batch-mail').show();
  5267. $('.batch-import').hide();
  5268. }
  5269. else {
  5270. $('.batch-mail').hide();
  5271. $('.batch-import').show();
  5272. }
  5273. }
  5274. $.each(saNewCustomers, function (idx, data) {
  5275. oAddItem = {};
  5276. oAddItem.guid = guid();
  5277. oAddItem.SupplierID = data.guid;
  5278. oAddItem.CustomerNO = data.CustomerNO;
  5279. oAddItem.UniCode = data.UniCode;
  5280. oAddItem.SupplierName = data.CustomerCName;
  5281. oAddItem.SupplierEName = data.CustomerEName;
  5282. if($('#RefNumber').val() != ""){
  5283. oAddItem.RefSupplierNo = $('#RefNumber').val() + rndnum(3);
  5284. }
  5285. oAddItem.Telephone = data.Telephone;
  5286. oAddItem.Email = data.Email;
  5287. oAddItem.Contactor = data.ContactorId;
  5288. oAddItem.ContactorName = data.ContactorName;
  5289. oAddItem.CreateUser = parent.UserID;
  5290. oAddItem.CreateDate = new Date().formate("yyyy/MM/dd HH:mm:ss");
  5291. saGridData.push(oAddItem);
  5292. });
  5293. if (args.Contactor !== undefined) {
  5294. var filters = $.grep(saGridData, function (client) {
  5295. return (!args.Contactor || client.ContactorName.indexOf(args.Contactor) > -1)
  5296. && (!args.Telephone || client.Telephone.indexOf(args.Telephone) > -1)
  5297. && (!args.Email || client.Email.indexOf(args.Email) > -1)
  5298. && (!args.Flow_Status || (client.Flow_Status || '').indexOf(args.Flow_Status) > -1)
  5299. && (!args.SupplierEName || client.SupplierEName.indexOf(args.SupplierEName) > -1)
  5300. && (!args.SupplierName || args.SupplierName.indexOf(client.SupplierName) > -1)
  5301. && (!args.RefSupplierNo || client.RefSupplierNo.indexOf(args.RefSupplierNo) > -1);
  5302. });
  5303. if (filters.length > 0) {
  5304. filters = Enumerable.From(filters).OrderBy("x=>x.CreateDate").ToArray();
  5305. }
  5306. $.each(filters, function (idx, filter) {
  5307. filter.RowIndex = idx + 1;
  5308. });
  5309. return {
  5310. data: filters,
  5311. itemsCount: filters.length //data.length
  5312. };
  5313. }
  5314. else {
  5315. if (saGridData.length > 0) {
  5316. saGridData = Enumerable.From(saGridData).OrderBy("x=>x.CreateDate").ToArray();
  5317. }
  5318. $.each(saGridData, function (idx, filter) {
  5319. filter.RowIndex = idx + 1;
  5320. });
  5321. return {
  5322. data: saGridData,
  5323. itemsCount: saGridData.length //data.length
  5324. };
  5325. }
  5326. },
  5327. insertItem: function (args) {
  5328. oAddItem.Contactor = args.Contactor;
  5329. oAddItem.Telephone = args.Telephone;
  5330. oAddItem.Email = args.Email;
  5331. saGridData.push(oAddItem);
  5332. oAddItem = {};
  5333. if (sAction === 'Add') {
  5334. showMsg(i18next.t("message.SaveCusFirst"))// ╠message.SaveCusFirst⇒請先儲存再新增廠商╣
  5335. saGridData = [];
  5336. return $.Deferred().reject().promise();
  5337. }
  5338. else {
  5339. bRequestStorage = true;
  5340. }
  5341. },
  5342. updateItem: function (args) {
  5343. $.each(saGridData, function (e, item) {
  5344. if (item.guid === args.guid) {
  5345. item = args;
  5346. bRequestStorage = true;
  5347. return false;
  5348. }
  5349. });
  5350. },
  5351. deleteItem: function (args) {
  5352. if (args.BillNO || (oCurData.IsSendMail || '').indexOf(args.guid) > -1) {
  5353. showMsg(i18next.t("message.NotToDelete_Supplier")); // ╠message.NotToDelete_Supplier⇒該筆廠商已經產生帳單或寄送過郵件,不可以刪除!╣
  5354. return $.Deferred().reject().promise();
  5355. }
  5356. else {
  5357. var saNewList = [];
  5358. $.each(saGridData, function (idx, item) {
  5359. if (item.guid !== args.guid) {
  5360. saNewList.push(item);
  5361. }
  5362. });
  5363. saGridData = saNewList;
  5364. }
  5365. bRequestStorage = true;
  5366. }
  5367. },
  5368. onInit: function (args) {
  5369. oGrid = args.grid;
  5370. setTimeout(function () {
  5371. $('.tooltips').each(function () {
  5372. $(this).parents('tr').attr('title', this.title);
  5373. });
  5374. }, 1000);
  5375. }
  5376. });
  5377. },
  5378. /**
  5379. * ToolBar 按鈕事件 function
  5380. * @param {Object}inst 按鈕物件對象
  5381. * @param {Object} e 事件對象
  5382. */
  5383. fnButtonHandler = function (inst, e) {
  5384. var sId = inst.id;
  5385. switch (sId) {
  5386. case "Toolbar_Qry":
  5387. break;
  5388. case "Toolbar_Save":
  5389. if (!$("#form_main").valid()) {
  5390. oValidator.focusInvalid();
  5391. return;
  5392. }
  5393. if (sAction === 'Add') {
  5394. fnAdd('add');
  5395. }
  5396. else {
  5397. fnUpd();
  5398. }
  5399. break;
  5400. case "Toolbar_ReAdd":
  5401. if (!$("#form_main").valid()) {
  5402. oValidator.focusInvalid();
  5403. return;
  5404. }
  5405. fnAdd('readd');
  5406. break;
  5407. case "Toolbar_Clear":
  5408. clearPageVal();
  5409. break;
  5410. case "Toolbar_Leave":
  5411. pageLeave();
  5412. break;
  5413. case "Toolbar_Add":
  5414. break;
  5415. case "Toolbar_Upd":
  5416. break;
  5417. case "Toolbar_Copy":
  5418. break;
  5419. case "Toolbar_Imp":
  5420. fnImport();
  5421. break;
  5422. case "Toolbar_Exp":
  5423. //fnOpenPopToExcel();
  5424. break;
  5425. case "Toolbar_Void":
  5426. if (fnCheckBillEffective(oCurData.Bills) || fnCheckRtnBillEffective(oCurData.ReturnBills)) {
  5427. showMsg(i18next.t("message.OpmNotToVoid")); // ╠message.OpmNotToVoid⇒已建立有效的賬單,暫時不可作廢╣
  5428. return;
  5429. }
  5430. fnVoid();
  5431. break;
  5432. case "Toolbar_OpenVoid":
  5433. // ╠message.ToOpenVoid⇒確定要啟用該筆資料嗎?╣ ╠common.Tips⇒提示╣
  5434. layer.confirm(i18next.t('message.ToOpenVoid'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  5435. fnOpenVoid();
  5436. layer.close(index);
  5437. });
  5438. break;
  5439. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  5440. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  5441. fnDel();
  5442. layer.close(index);
  5443. });
  5444. break;
  5445. default:
  5446. alert("No handle '" + sId + "'");
  5447. break;
  5448. }
  5449. },
  5450. /**
  5451. * 初始化 function
  5452. */
  5453. init = function () {
  5454. var saCusBtns = [],
  5455. myHelpers = {
  5456. setSupplierName: function (val1, val2) {
  5457. return !val1 ? val2 : val1;
  5458. },
  5459. dtformate: function (val) {
  5460. return newDate(val);
  5461. },
  5462. setStatus: function (status) {
  5463. return sStatus;
  5464. }
  5465. };
  5466. $.views.helpers(myHelpers);
  5467. if (sAction !== 'Upd') {
  5468. saCusBtns = [{
  5469. id: 'Toolbar_Imp',
  5470. value: 'common.Toolbar_Imp'// ╠common.Toolbar_Imp⇒匯入╣
  5471. }];
  5472. }
  5473. commonInit({
  5474. PrgId: sProgramId,
  5475. ButtonHandler: fnButtonHandler,
  5476. Buttons: saCusBtns,
  5477. GoTop: true,
  5478. tabClick: function (el) {
  5479. switch (el.id) {
  5480. case 'litab2':
  5481. if (!$(el).data('action')) {
  5482. fnGridInit();
  5483. //oGrid.loadData();
  5484. $(el).data('action', true);
  5485. }
  5486. break;
  5487. case 'litab3':
  5488. case 'litab4':
  5489. if (!$(el).data('action')) {
  5490. fnBindFinancial();
  5491. $('#litab3').data('action', true);
  5492. $('#litab4').data('action', true);
  5493. fnOpenAccountingArea($('div .OnlyForAccounting'), parent.UserInfo.roles);
  5494. fnOpenAccountingArea($('div .BillOrganizers'), parent.UserInfo.roles);
  5495. }
  5496. break;
  5497. case 'litab5':
  5498. case 'litab6':
  5499. if (!$(el).data('action')) {
  5500. if (oCurData.ReturnBills.length > 0) {
  5501. fnRenderReturnBills();
  5502. }
  5503. $('#litab5').data('action', true);
  5504. $('#litab6').data('action', true);
  5505. fnOpenAccountingArea($('div .OnlyForAccounting'), parent.UserInfo.roles);
  5506. }
  5507. break;
  5508. }
  5509. }
  5510. });
  5511. //加載報關類別,加載成本頁簽
  5512. $.whenArray([
  5513. fnGet(),
  5514. fnSetCustomersDrop(),
  5515. fnGetOfficeTempls({
  5516. TemplID: parent.SysSet.InvoiceDownLoadMenu + parent.SysSet.InvoicePrintMenu + parent.SysSet.ReceiptDownLoadMenu + parent.SysSet.ReceiptPrintMenu,
  5517. CallBack: function (data) {
  5518. oPrintMenu.InvoiceDownLoadMenu = { tmpl: $('<div data-id="InvoiceDownLoadMenu">') };
  5519. oPrintMenu.InvoicePrintMenu = { tmpl: $('<div data-id="InvoicePrintMenu">') };
  5520. oPrintMenu.ReceiptDownLoadMenu = { tmpl: $('<div data-id="ReceiptDownLoadMenu">') };
  5521. oPrintMenu.ReceiptPrintMenu = { tmpl: $('<div data-id="ReceiptPrintMenu">') };
  5522. $.each(data, function (idx, item) {
  5523. var sType = '';
  5524. if (parent.SysSet.InvoiceDownLoadMenu.indexOf(item.TemplID) > -1) {
  5525. sType = 'InvoiceDownLoadMenu';
  5526. }
  5527. else if (parent.SysSet.InvoicePrintMenu.indexOf(item.TemplID) > -1) {
  5528. sType = 'InvoicePrintMenu';
  5529. }
  5530. else if (parent.SysSet.ReceiptDownLoadMenu.indexOf(item.TemplID) > -1) {
  5531. sType = 'ReceiptDownLoadMenu';
  5532. }
  5533. else if (parent.SysSet.ReceiptPrintMenu.indexOf(item.TemplID) > -1) {
  5534. sType = 'ReceiptPrintMenu';
  5535. }
  5536. oPrintMenu[sType].tmpl.append('<a href="#" class="print-item" data-id="' + item.TemplID + '">' + item.TemplName + '</a>');
  5537. });
  5538. }
  5539. }),
  5540. fnSetEpoDrop({
  5541. Select: $('#ExhibitionNO'),
  5542. Select2: true
  5543. }),
  5544. fnSetUserDrop([
  5545. {
  5546. Select: $('#ResponsiblePerson'),
  5547. ShowId: true,
  5548. Select2: true,
  5549. Action: sAction,
  5550. ServiceCode: parent.SysSet.EXCode,
  5551. CallBack: function (data) {
  5552. var sCode = parent.UserInfo.ServiceCode;
  5553. if (sAction === 'Add' && sCode && parent.SysSet.EXCode.indexOf(sCode) > -1) {
  5554. $('#ResponsiblePerson').val(parent.UserInfo.MemberID);
  5555. sServiceCode = sCode;
  5556. sDeptCode = parent.UserInfo.DepartmentID;
  5557. }
  5558. }
  5559. }
  5560. ]),
  5561. fnSetArgDrop([
  5562. {
  5563. ArgClassID: 'Clearance',
  5564. Select: $('#CustomsClearance'),
  5565. ShowId: true
  5566. },
  5567. {
  5568. ArgClassID: 'Currency',
  5569. CallBack: function (data) {
  5570. saCurrency = data;
  5571. sCurrencyOptionsHtml = createOptions(data, 'id', 'text');
  5572. }
  5573. },
  5574. {
  5575. ArgClassID: 'Transport',
  5576. Select: $('#TransportationMode'),
  5577. ShowId: true,
  5578. CallBack: function (data) {
  5579. sTransportOptionsHtml = createOptions(data, 'id', 'text', true);
  5580. }
  5581. },
  5582. {
  5583. ArgClassID: 'Port',
  5584. CallBack: function (data) {
  5585. saPort = data;
  5586. $('.quickquery-city').on('keyup', function () {
  5587. this.value = this.value.toUpperCase();
  5588. }).on('blur', function () {
  5589. var sId = this.value,
  5590. oPort = Enumerable.From(saPort).Where(function (e) { return e.id === sId; });
  5591. if (oPort.Count() === 1) {
  5592. $(this).parent().next().next().find(':input').val(oPort.First().text);
  5593. }
  5594. }).autocompleter({
  5595. // marker for autocomplete matches
  5596. highlightMatches: true,
  5597. // object to local or url to remote search
  5598. source: saPort,
  5599. // custom template
  5600. template: '{{ id }} <span>({{ label }})</span>',
  5601. // show hint
  5602. hint: true,
  5603. // abort source if empty field
  5604. empty: false,
  5605. // max results
  5606. limit: 20,
  5607. callback: function (value, index, selected) {
  5608. if (selected) {
  5609. var that = this;
  5610. $(that).parent().find(':input').val(selected.id);
  5611. $(that).parent().next().next().find(':input').val(selected.text);
  5612. }
  5613. }
  5614. });
  5615. }
  5616. },
  5617. {
  5618. ArgClassID: 'FeeClass',
  5619. CallBack: function (data) {
  5620. saFeeClass = data;
  5621. }
  5622. }
  5623. ]),
  5624. fnGetNewExhibition(),
  5625. fnGetNewCustomers()
  5626. ])
  5627. .done(function (res) {
  5628. if (res && res[0].RESULT === 1) {
  5629. var oRes = res[0].DATA.rel;
  5630. fnGetCurrencyThisYear(oRes.CreateDate).done(function () {
  5631. oRes.Exhibitors = saGridData = !oRes.Exhibitors ? [] : JSON.parse(oRes.Exhibitors);
  5632. oRes.Quote = JSON.parse(oRes.Quote || '{}');
  5633. oRes.EstimatedCost = JSON.parse(oRes.EstimatedCost || '{}');
  5634. oRes.ActualCost = JSON.parse(oRes.ActualCost || '{}');
  5635. oRes.Bills = JSON.parse(oRes.Bills || '[]');
  5636. oRes.ReturnBills = !oRes.ReturnBills ? [] : JSON.parse(oRes.ReturnBills);
  5637. oRes.Quote.FeeItems = oRes.Quote.FeeItems || [];
  5638. oRes.EstimatedCost.FeeItems = oRes.EstimatedCost.FeeItems || [];
  5639. oRes.ActualCost.FeeItems = oRes.ActualCost.FeeItems || [];
  5640. oRes.Quote.guid = oRes.Quote.guid || guid();
  5641. oRes.Quote.KeyName = oRes.Quote.KeyName || 'Quote';
  5642. oRes.Quote.AuditVal = oRes.Quote.AuditVal || '0';
  5643. oRes.EstimatedCost.guid = oRes.EstimatedCost.guid || guid();
  5644. oRes.EstimatedCost.KeyName = oRes.EstimatedCost.KeyName || 'EstimatedCost';
  5645. oRes.EstimatedCost.AuditVal = oRes.EstimatedCost.AuditVal || '0';
  5646. oRes.ActualCost.guid = oRes.ActualCost.guid || guid();
  5647. oRes.ActualCost.KeyName = oRes.ActualCost.KeyName || 'ActualCost';
  5648. oRes.ActualCost.AuditVal = oRes.ActualCost.AuditVal || '0';
  5649. oCurData = oRes;
  5650. nowResponsiblePerson = oCurData.ResponsiblePerson;
  5651. //預設產生帳單組團單位
  5652. $.each(sOrganizers, function (idx, sO) {
  5653. if (sO) {
  5654. let OrganizersIndx = idx + 1
  5655. $('#Organizer' + OrganizersIndx).val(sO).trigger('change.select2');
  5656. var AKOf = Enumerable.From(saCustomers).Where(function (e) { return e.id === sO; }).FirstOrDefault();
  5657. if (AKOf)
  5658. sSelectedOrganizers[OrganizersIndx] = { id: AKOf.id, text: AKOf.text, title: AKOf.text };
  5659. }
  5660. });
  5661. $('[data-id="BillOrganizer"]').html(createOptions(sSelectedOrganizers.filter(e => e != null), 'id', 'text'));
  5662. //預設產生帳單組團單位-END
  5663. if (oCurData.Agent) {
  5664. var oCur = Enumerable.From(saCustomers).Where(function (e) { return e.id === oCurData.Agent; }).First(),
  5665. saContactors = JSON.parse(oCur.Contactors || '[]');
  5666. $('#AgentContactor').html(createOptions(saContactors, 'guid', 'FullName'));
  5667. }
  5668. else {
  5669. $('#AgentContactor').html(createOptions([]));
  5670. }
  5671. setFormVal(oForm, oRes);
  5672. fnSetUserDrop([
  5673. {
  5674. MemberID: oCurData.ResponsiblePerson,
  5675. CallBack: function (data) {
  5676. var oRes = data[0];
  5677. sServiceCode = oRes.ServiceCode;
  5678. sDeptCode = oRes.DepartmentID;
  5679. }
  5680. }
  5681. ]);
  5682. setNameById().done(function () {
  5683. getPageVal();//緩存頁面值,用於清除
  5684. });
  5685. $('#ExhibitionDateStart').val(newDate(oCurData.ExhibitionDateStart, 'date', true));
  5686. $('#ExhibitionDateEnd').val(newDate(oCurData.ExhibitionDateEnd, 'date', true));
  5687. if (saGridData.length > 0) {
  5688. $.each(saGridData, function (idx, item) {
  5689. if (!item.guid) {
  5690. item.guid = guid();
  5691. }
  5692. });
  5693. }
  5694. $('#Batch_Mail').on('click', function () {
  5695. fnBatchMail();
  5696. });
  5697. $('#Batch_Import').on('click', function () {
  5698. fnBatchImport();
  5699. });
  5700. if (parent.UserInfo.MemberID === oCurData.ResponsiblePerson || parent.UserInfo.MemberID === oCurData.CreateUser) {
  5701. $('#returnquote_add').removeAttr('disabled').click(function () {
  5702. fnPushReturnBill();
  5703. });
  5704. $('.returnquote-add').show();
  5705. }
  5706. moneyInput($('[data-type="int"]'), 0);
  5707. var Authorized = ExhibitionBillAuthorize(oCurData);
  5708. if (Authorized) {
  5709. $('[href="#tab3"],[href="#tab4"],[href="#tab5"],[href="#tab6"]').parent().show();
  5710. if (sGoTab) {
  5711. $('#litab' + sGoTab).find('a').click();
  5712. if (sBillNOGO && $('.bill-box-' + sBillNOGO).length > 0) {
  5713. $('.bill-box-' + sBillNOGO).click();
  5714. goToJys($('.bill-box-' + sBillNOGO));
  5715. }
  5716. }
  5717. }
  5718. else {
  5719. $('[href="#tab3"],[href="#tab4"],[href="#tab5"],[href="#tab6"]').parent().hide();
  5720. }
  5721. });
  5722. }
  5723. else{
  5724. fnGetCurrencyThisYear(new Date());
  5725. if(sAction === 'Add' && sExhibitionNO){
  5726. $("#ExhibitionNO").val(sExhibitionNO).select2();
  5727. $("#ExportBillEName").val(saNewExhibition.Exhibitioname_EN);
  5728. $('#ExhibitionDateStart').val(newDate(saNewExhibition.ExhibitionDateStart, 'date', true));
  5729. $('#ExhibitionDateEnd').val(newDate(saNewExhibition.ExhibitionDateEnd, 'date', true));
  5730. }
  5731. }
  5732. });
  5733. $.validator.addMethod("compardate", function (value, element, parms) {
  5734. if (new Date(value) < new Date($('#ExhibitionDateStart').val())) {
  5735. return false;
  5736. }
  5737. return true;
  5738. });
  5739. oValidator = $("#form_main").validate({
  5740. ignore: '',
  5741. rules: {
  5742. AgentEamil: {
  5743. email: true
  5744. }
  5745. },
  5746. messages: {
  5747. AgentEamil: i18next.t("message.IncorrectEmail")// ╠message.IncorrectEmail⇒郵箱格式不正確╣
  5748. }
  5749. });
  5750. $.timepicker.dateRange($('#ExhibitionDateStart'), $('#ExhibitionDateEnd'),
  5751. {
  5752. minInterval: (1000 * 60 * 60 * 24 * 1), // 1 days
  5753. changeYear: true,
  5754. changeMonth: true
  5755. }
  5756. );
  5757. //$('#Volume').on('blur', function () {
  5758. // var sVal = this.value;
  5759. // $('#VolumeWeight').val((Math.floor(sVal * 100) / 100 * 167).toFloat(2));
  5760. //});
  5761. $('#ResponsiblePerson').change(function () {
  5762. var sVal = this.value;
  5763. if (sVal) {
  5764. fnSetUserDrop([
  5765. {
  5766. MemberID: sVal,
  5767. CallBack: function (data) {
  5768. var oRes = data[0];
  5769. sServiceCode = oRes.ServiceCode;
  5770. sDeptCode = oRes.DepartmentID;
  5771. }
  5772. }
  5773. ]);
  5774. }
  5775. else {
  5776. sServiceCode = '';
  5777. sDeptCode = '';
  5778. }
  5779. });
  5780. $('#ExhibitionNO').change(function () {
  5781. var sId = this.value;
  5782. if (sId) {
  5783. fnSetEpoDrop({
  5784. SN: sId,
  5785. CallBack: function (data) {
  5786. var oExhibition = data[0];
  5787. $('#ExportBillEName').val(oExhibition.Exhibitioname_EN);
  5788. if (oExhibition.ExhibitionDateStart) {
  5789. $('#ExhibitionDateStart').val(newDate(oExhibition.ExhibitionDateStart, 'date'));
  5790. }
  5791. if (oExhibition.ExhibitionDateEnd) {
  5792. $('#ExhibitionDateEnd').val(newDate(oExhibition.ExhibitionDateEnd, 'date'));
  5793. }
  5794. }
  5795. });
  5796. }
  5797. else {
  5798. $('#ExportBillEName').val('');
  5799. $('#ExhibitionDateStart').val('');
  5800. $('#ExhibitionDateEnd').val('');
  5801. }
  5802. });
  5803. $(window).on('scroll', function () {
  5804. var h = ($(document).height(), $(this).scrollTop());
  5805. if (h < 81) {
  5806. $('.sum-box').css({ top: 125 - h });
  5807. $('.BatchBillsDownLoad').css({ top: 140 - h });
  5808. }
  5809. else {
  5810. $('.sum-box,.BatchBillsDownLoad').css({ top: 44 });
  5811. }
  5812. });
  5813. $('#Batch_BillsDownLoad').on('click', function () {
  5814. });
  5815. $('#Batch_RerurnBillsDownLoad').on('click', function () {
  5816. });
  5817. };
  5818. init();
  5819. };
  5820. require(['base', 'select2', 'autocompleter', 'formatnumber', 'jquerytoolbar', 'timepicker', 'jsgrid', 'ajaxfile', 'common_opm', 'util'], fnPageInit, 'timepicker');