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.

1221 lines
62 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = 'InvoiceApplyForCustomer_Qry',
  4. sEditPrgId = 'InvoiceApplyForCustomer_Upd',
  5. sAction = getUrlParam('Action') || 'Add',
  6. sDataId = getUrlParam('Guid'),
  7. sCheckId = sDataId,
  8. fnPageInit = function () {
  9. var oCurData = { CheckFlows: [], HandleFlows: [], PayeeInfo: [] },
  10. oForm = $('#form_main'),
  11. saCheckOrder_Push = [],
  12. saUsers = [],
  13. sCurAuditFlowId = null,
  14. sCurHandleFlowId = null,
  15. sOptionHtml_Currency = '',
  16. sOptionHtml_ComplaintNumber = '',
  17. bGoNext = true,
  18. /**
  19. * 獲取當前審核人員
  20. * @param {Object} data當前審核資料
  21. */
  22. fnGetCurAuditor = function (data) {
  23. var saCheckFlows = $.parseJSON(data.CheckFlows),
  24. saNewList = Enumerable.From(saCheckFlows).GroupBy("$.Order").ToArray(),
  25. bAuditor = false,
  26. bHandle = false,
  27. bAllAudit = false;
  28. if ('B,E'.indexOf(data.Status) > -1) {//只有審核中或者待經辦的資料才可以出現審核區塊
  29. $.each(saNewList, function (idx, _data) {
  30. var sSignedWay = _data.source[0].SignedWay,
  31. iCount = Enumerable.From(_data.source).Where(function (e) { return (e.SignedDecision === 'Y' || e.SignedDecision === 'O'); }).Count(),
  32. sCurAuditor = Enumerable.From(_data.source).ToString(",", "$.SignedId");
  33. if ((('flow1,flow3'.indexOf(sSignedWay) > -1 && iCount === 0) || (sSignedWay === 'flow2' && iCount !== _data.source.length))) {
  34. if (sCurAuditor.indexOf(parent.UserID) > -1) {
  35. var oCurUser = Enumerable.From(_data.source).Where(function (e) { return e.SignedId === parent.UserID; }).First();
  36. if (sSignedWay === 'flow2' && iCount < _data.source.length - 1) {
  37. bGoNext = false;
  38. }
  39. if (!oCurUser.SignedDecision) {
  40. sCurAuditFlowId = oCurUser.FlowId;
  41. bAuditor = true;
  42. }
  43. }
  44. if (!bAllAudit) {//只要有需要審核的人,就不要檢核是否簽辦
  45. bAllAudit = true;
  46. }
  47. return false;
  48. }
  49. });
  50. if (!bAuditor && !bAllAudit) {//當沒有要審核的人員並且審核全部完成時才會檢核簽辦
  51. var saHandleFlows = $.parseJSON(data.HandleFlows),
  52. sCurAuditor = saHandleFlows[0].SignedId;
  53. if (saHandleFlows[0].SignedDecision !== 'Y' && sCurAuditor === parent.UserID) {
  54. sCurHandleFlowId = saHandleFlows[0].FlowId
  55. bHandle = true;
  56. }
  57. }
  58. }
  59. return {
  60. IsAuditor: bAuditor,
  61. IsHandler: bHandle
  62. };
  63. },
  64. /**
  65. * 註冊加簽事件
  66. * @param {Number} _grididx當前Gird 序號
  67. */
  68. fnRegisterAddFlows = function (_grididx) {
  69. $('.flowlink' + _grididx).on('click', function () {
  70. var oOption = {};
  71. oOption.SignedWay = $(this).data('id');
  72. oOption.Callback = function (data) {
  73. if (data.Users.length > 0) {
  74. var oFlow = {};
  75. if (data.FlowType === 'flow1') {
  76. $.each(data.Users, function (idx, user) {
  77. oFlow = {};
  78. oFlow.id = guid();
  79. oFlow.Order = saCheckOrder_Push.length + 1;
  80. oFlow.SignedWay = data.FlowType;
  81. oFlow.SignedMember = [{
  82. id: user.id,
  83. name: user.name,
  84. deptname: user.deptname,
  85. jobname: user.jobname
  86. }];
  87. saCheckOrder_Push.push(oFlow);
  88. });
  89. }
  90. else {
  91. var saSignedMembers = [];
  92. $.each(data.Users, function (idx, user) {
  93. saSignedMembers.push({
  94. id: user.id,
  95. name: user.name,
  96. deptname: user.deptname,
  97. jobname: user.jobname
  98. });
  99. });
  100. oFlow.id = guid();
  101. oFlow.Order = saCheckOrder_Push.length + 1;
  102. oFlow.SignedWay = data.FlowType;
  103. oFlow.SignedMember = saSignedMembers;
  104. saCheckOrder_Push.push(oFlow);
  105. }
  106. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  107. $("#jsGrid" + _grididx).jsGrid("loadData");
  108. }
  109. };
  110. oPenUserListPop(oOption);
  111. });
  112. },
  113. /**
  114. * 獲取資料
  115. */
  116. fnGet = function () {
  117. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  118. {
  119. Guid: sDataId
  120. },
  121. function (res) {
  122. if (res.RESULT) {
  123. var oRes = res.DATA.rel,
  124. saFlowsText = [],
  125. sStatus = '';
  126. if (oRes.Status === 'C-O') {
  127. sStatus = '(' + i18next.t("common.HasReEdited") + ')';// ╠common.HasReEdited⇒已抽單╣
  128. }
  129. else if (oRes.Status === 'D-O') {
  130. sStatus = '(' + i18next.t("common.HasReturned") + ')';// ╠common.HasReturned⇒已退件╣
  131. }
  132. else if (oRes.Status === 'X') {
  133. sStatus = '(' + i18next.t("common.HasVoid") + ')';// ╠common.HasVoid⇒已作廢╣
  134. }
  135. //根據帳單狀態,移除抽單按鈕(扣除已經辦只能admin抽單)
  136. fnCheckReEdit(oRes.Status, oRes.Applicant);
  137. if (oRes.Applicant !== parent.UserID) {
  138. $('#Toolbar_Copy').remove();
  139. }
  140. if ('B,Y'.indexOf(oRes.Status) === -1) {
  141. $('#Toolbar_Void').remove();
  142. }
  143. var SuperAuditor = parent.SysSet.InvoiceApplySuperAuditor.indexOf(parent.UserID) > -1;
  144. var oCheck = fnGetCurAuditor(oRes);
  145. if (oCheck.IsAuditor) {
  146. $('#IsAuditor').show();
  147. }
  148. if (oCheck.IsHandler) {
  149. $('#IsHandler').show();
  150. }
  151. if (oCheck.IsAuditor || oCheck.IsHandler) {
  152. $('.submitdecision').click(function () {
  153. var sSubmitAction = $(this).data('id');
  154. fnSubmitDecision(sSubmitAction);
  155. });
  156. }
  157. //條件:經辦中、SuperAuditor、未經辦(最後一關)
  158. if ("B".indexOf(oRes.Status) > -1 && SuperAuditor && !oCheck.IsHandler) {
  159. if (!oCheck.IsAuditor) {
  160. $('#SuperAuditor').show();
  161. $('.submitdecisionforall').click(function () {
  162. fnSubmitDecisionForAll();
  163. });
  164. }
  165. }
  166. if (oRes.VoidReason) {
  167. $('#VoidReason').text(oRes.VoidReason);
  168. $('.VoidReason').show();
  169. }
  170. if (oRes.CrosssignTurn === 'N') {
  171. $('.crosssignturn').remove();
  172. }
  173. if (oRes.PaymentType === 'A') {
  174. $('.PaymentTime').text(i18next.t("common.CompanyRegulations"));
  175. }
  176. else {
  177. $('.PaymentTime').text(newDate(oRes.PaymentTime, true));
  178. }
  179. oCurData = oRes;
  180. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  181. oCurData.CheckFlows = $.parseJSON(oCurData.CheckFlows);
  182. oCurData.HandleFlows = $.parseJSON(oCurData.HandleFlows);
  183. oCurData.PayeeInfo = $.parseJSON(oCurData.PayeeInfo);
  184. oCurData.RemittanceInformation = $.parseJSON(oCurData.RemittanceInformation);
  185. setFormVal(oForm, oRes);
  186. $('#Applicant').text(oCurData.ApplicantName + '(' + oCurData.Applicant + ') ' + oCurData.DeptName);
  187. $('#PayeeCode').text(oCurData.CustomerNO);
  188. $('.eip-note').text(oCurData.KeyNote);
  189. $('#status').text(sStatus);
  190. $('#Payee').text(oCurData.PayeeName);
  191. $('#Handle_Person').text(oCurData.Handle_PersonName);// ╠common.Important_1⇒普通╣ ╠common.Important_2⇒重要╣ ╠common.Important_3⇒很重要╣
  192. $('#Important').text(oCurData.Important === '1' ? i18next.t("common.Important_1") : oCurData.Important === '2' ? i18next.t("common.Important_2") : i18next.t("common.Important_3"));
  193. $('#SignedNumber').text(oCurData.SignedNumber);
  194. $('[name="PaymentWay"]').each(function () {
  195. var radio = $(this).parents('.radio');
  196. if (!this.checked) {
  197. radio.next().remove();
  198. }
  199. else {
  200. radio.next().addClass('show-text');
  201. }
  202. radio.remove();
  203. });
  204. $.each(oCurData.CheckOrder, function (idx, order) {
  205. var sFlowType = i18next.t('common.' + order.SignedWay);
  206. if (order.SignedWay !== 'flow1') {
  207. saFlowsText.push(sFlowType + '(' + Enumerable.From(order.SignedMember).ToString(",", "$.name") + ')');
  208. }
  209. else {
  210. saFlowsText.push(Enumerable.From(order.SignedMember).ToString(",", "$.name"));
  211. }
  212. });
  213. $('#Recipient').text(saFlowsText.join('->'));
  214. fnGetFiles($('#AdditionalFiles'), oCurData.Guid, oCurData.RelationId, oCurData.ExFeild1, sProgramId);//加載附件
  215. fnUpload();//初始化上傳控件(審批與簽辦)
  216. fnRead();//如果是被通知的人,則修改為已閱讀狀態
  217. $("#jsGrid").jsGrid("loadData");
  218. $("#jsGrid1").jsGrid("loadData");
  219. $("#jsGrid2").jsGrid("loadData");
  220. $('[name="SignedDecision"]').click(function () {
  221. if (this.value === 'O') {
  222. $('#addotheraudit').slideDown();
  223. }
  224. else {
  225. $('#addotheraudit').slideUp();
  226. }
  227. });
  228. $('[name="HandleDecision"]').click(function () {
  229. if (this.value === 'O') {
  230. $('#addotherhandle').slideDown();
  231. }
  232. else {
  233. $('#addotherhandle').slideUp();
  234. }
  235. });
  236. }
  237. });
  238. },
  239. /**
  240. * 複製
  241. */
  242. fnCopy = function () {
  243. var data = oCurData;
  244. data = packParams(data);
  245. if (data.Status === 'D-O') {
  246. data.RelationId = data.Guid;
  247. }
  248. else {
  249. delete data.RelationId;
  250. }
  251. data.OrgID = parent.OrgID;
  252. data.Guid = guid();
  253. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|IAC|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  254. data.CheckFlows = fnCheckFlows(data, false, true, saUsers);
  255. data.HandleFlows = fnHandleFlows(data, saUsers);
  256. data.CheckOrder = JSON.stringify(data.CheckOrder);
  257. data.PayeeInfo = JSON.stringify(data.PayeeInfo);
  258. data.RemittanceInformation = JSON.stringify(data.RemittanceInformation);
  259. data.Status = 'A';
  260. data.IsHandled = 'N';
  261. data.PayeeType = 'C';
  262. data.Inspectors = '';
  263. data.Reminders = '';
  264. data.VoidReason = '';
  265. data.Flows_Lock = data.Flows_Lock || 'N';
  266. data.Handle_Lock = data.Handle_Lock || 'N';
  267. delete data.RowIndex;
  268. delete data.ApplicantName;
  269. delete data.Handle_PersonName;
  270. delete data.DeptName;
  271. delete data.PayeeCode;
  272. delete data.CustomerNO;
  273. delete data.CreateUserName;
  274. delete data.ModifyUserName;
  275. if (!data.EffectTime) {
  276. delete data.EffectTime;
  277. }
  278. if (data.PaymentType === 'A') {
  279. delete data.PaymentTime;
  280. }
  281. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  282. Params: {
  283. invoiceapplyinfo: data
  284. }
  285. }, function (res) {
  286. if (res.d > 0) {
  287. showMsgAndGo(i18next.t("message.Copy_Success"), sEditPrgId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Copy_Success⇒複製成功╣
  288. }
  289. else {
  290. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  291. }
  292. }, function () {
  293. showMsg(i18next.t("message.Copy_Failed"), 'error'); // ╠message.Copy_Failed⇒複製失敗╣
  294. });
  295. },
  296. /**
  297. * 資料作廢
  298. */
  299. fnVoid = function () {
  300. layer.open({
  301. type: 1,
  302. title: i18next.t('common.Toolbar_Void'),// ╠common.Toolbar_Void⇒作廢╣
  303. shade: 0.75,
  304. maxmin: true, //开启最大化最小化按钮
  305. area: ['500px', '250px'],
  306. content: '<div class="pop-box">\
  307. <textarea name="VoidContent" id="VoidContent" style="min-width:300px;" class="form-control" rows="5" cols="20"></textarea>\
  308. </div>',
  309. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  310. success: function (layero, index) {
  311. },
  312. yes: function (index, layero) {
  313. var data = {
  314. Status: 'X',
  315. VoidReason: $('#VoidContent').val()
  316. };
  317. if (!$('#VoidContent').val()) {
  318. showMsg(i18next.t("message.VoidReason_Required")); // ╠message.VoidReason_Required⇒請填寫作廢原因╣
  319. return false;
  320. }
  321. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  322. Params: {
  323. invoiceapplyinfo: {
  324. values: data,
  325. keys: { Guid: sDataId }
  326. }
  327. }
  328. }, function (res) {
  329. if (res.d > 0) {
  330. DelTask(sDataId);
  331. showMsgAndGo(i18next.t('message.Void_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  332. }
  333. else {
  334. showMsg(i18next.t('message.Void_Failed'), 'error'); // ╠message.Void_Failed⇒作廢失敗╣
  335. }
  336. });
  337. layer.close(index);
  338. }
  339. });
  340. },
  341. /**
  342. * 複製
  343. */
  344. fnRead = function () {
  345. var bToUpd = false;
  346. $.each(oCurData.CheckFlows, function (idx, _data) {
  347. if (_data.SignedId === parent.UserID && _data.SignedWay === 'flow4' && _data.SignedDecision === 'T') {
  348. _data.SignedDecision = 'R';
  349. bToUpd = true;
  350. return false;
  351. }
  352. });
  353. if (bToUpd) {
  354. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  355. Params: {
  356. invoiceapplyinfo: {
  357. values: { CheckFlows: JSON.stringify(oCurData.CheckFlows) },
  358. keys: { Guid: sDataId }
  359. }
  360. }
  361. });
  362. }
  363. },
  364. /**
  365. * 抽單
  366. */
  367. fnReEdit = function () {
  368. var data = {};
  369. data.Status = 'C-O';
  370. data = packParams(data, 'upd');
  371. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  372. Params: {
  373. invoiceapplyinfo: {
  374. values: data,
  375. keys: { Guid: sDataId }
  376. }
  377. }
  378. }, function (res) {
  379. if (res.d > 0) {
  380. showMsg(i18next.t("message.ReEdit_Success"), 'success'); // ╠message.ReEdit_Success⇒抽單成功╣
  381. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  382. Params: {
  383. task: {
  384. values: { Status: 'O' },
  385. keys: { SourceID: sDataId }
  386. }
  387. }
  388. });
  389. fnGet();
  390. }
  391. else {
  392. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  393. }
  394. }, function () {
  395. showMsg(i18next.t('message.ReEdit_Failed'), 'error'); // ╠message.ReEdit_Failed⇒抽單失敗╣
  396. });
  397. },
  398. /**
  399. * 提交決定
  400. * @param {String} action 簽核 or 經辦
  401. */
  402. fnSubmitDecision = function (action) {
  403. var data = getFormSerialize(oForm),
  404. saNewCheckFlows = clone(oCurData.CheckFlows),
  405. saNewHandleFlows = clone(oCurData.HandleFlows),
  406. saNewCheckOrderPush = clone(saCheckOrder_Push),
  407. saAdds = [],//加簽核順序
  408. saNextUsers = [],//下組簽核人員
  409. saTipsUsers = [],//需要通知的人員
  410. saNextSignedWays = [],//下組需要處理的動作
  411. iCurOder = 0,//當前順序
  412. sHandlePerson = "";//經辦人
  413. if (action === 'Signed') {
  414. if (data.SignedDecision === 'N' && !data.SignedOpinion) {
  415. showMsg(i18next.t("message.SignedOpinion_required")); // ╠message.SignedOpinion_required⇒請填寫簽核意見╣
  416. return false;
  417. }
  418. else if (data.SignedDecision === 'O' && saCheckOrder_Push.length === 0) {
  419. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  420. return false;
  421. }
  422. var oCurFlow = Enumerable.From(oCurData.CheckFlows).Where(function (e) { return e.FlowId == sCurAuditFlowId; }).First(),
  423. oNewCurFlow = clone(oCurFlow);
  424. iCurOder = parseInt(oCurFlow.Order);
  425. $.each(saNewCheckOrderPush, function (idx, _push) {
  426. _push.Order = idx + 1 + iCurOder;
  427. });
  428. $.each(saNewCheckFlows, function (idx, _flow) {
  429. if (sCurAuditFlowId === _flow.FlowId) {
  430. _flow.SignedDecision = data.SignedDecision;
  431. _flow.SignedOpinion = data.SignedOpinion;
  432. _flow.SignedDate = newDate();
  433. if (data.SignedDecision === 'O') {
  434. _flow.SignedPush = saCheckOrder_Push;
  435. }
  436. }
  437. if (data.SignedDecision === 'O' && _flow.Order > iCurOder) {
  438. _flow.Order = parseInt(_flow.Order) + saNewCheckOrderPush.length;
  439. if (data.NoreTurn) {//如果再回傳給自己的話排序再增加一個值
  440. _flow.Order++;
  441. }
  442. else {//如果加簽核流程最後一個是通知,並且原流程下一個也是通知的話就合併新舊排序
  443. if (saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay === 'flow4' && saNewCheckFlows[iCurOder + 1].SignedWay === saNewCheckFlows[saNewCheckOrderPush.length - 1].SignedWay) {
  444. _flow.Order--;
  445. }
  446. }
  447. }
  448. });
  449. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  450. if (data.SignedDecision === 'O' && data.NoreTurn) {
  451. oNewCurFlow.Order = oNewCurFlow.Order + saNewCheckOrderPush.length + 1;
  452. oNewCurFlow.FlowId = guid();
  453. saAdds.push(oNewCurFlow);
  454. }
  455. }
  456. else {
  457. if (data.HandleDecision === 'O' && saCheckOrder_Push.length === 0) {
  458. showMsg(i18next.t("message.CheckOrderPush_required")); // ╠message.CheckOrderPush_required⇒請選擇加簽人員╣
  459. return false;
  460. }
  461. let NewCurOrder = saNewCheckFlows[saNewCheckFlows.length - 1].Order;//如果是签辦的話當前順序就是原本流程的最大順序
  462. iCurOder = parseInt(NewCurOrder);
  463. $.each(saNewHandleFlows, function (idx, _flow) {
  464. if (sCurHandleFlowId === _flow.FlowId) {
  465. _flow.SignedDecision = data.HandleDecision;
  466. _flow.SignedOpinion = data.HnadleOpinion;
  467. _flow.SignedDate = newDate();
  468. if (data.HandleDecision === 'O') {
  469. _flow.SignedPush = saCheckOrder_Push;
  470. }
  471. if (data.HandleDecision === 'Y') {
  472. _flow.SignedPush = null;
  473. }
  474. }
  475. });
  476. if (data.HandleDecision === 'O') {
  477. $.each(saNewCheckOrderPush, function (idx, _push) {
  478. _push.Order = idx + parseInt(saNewCheckFlows[saNewCheckFlows.length - 1].Order) + 1;
  479. });
  480. saAdds = fnCheckFlows({ CheckOrder: saNewCheckOrderPush }, false, false, saUsers);
  481. }
  482. }
  483. saNewCheckFlows = saNewCheckFlows.concat(saAdds);
  484. saNewCheckFlows = Enumerable.From(saNewCheckFlows).OrderBy("$.Order").ToArray();
  485. var _List = Enumerable.From(saNewCheckFlows).GroupBy("$.Order").ToArray();
  486. saNewCheckFlows = [];
  487. $.each(_List, function (idx, _list) {
  488. //找到要通知的人
  489. var sSignedWay = _list.source[0].SignedWay;
  490. var LastOne = iCurOder >= _List.length
  491. if (idx === iCurOder && !LastOne ) {
  492. switch (sSignedWay) {
  493. case "flow1":
  494. case "flow2":
  495. case "flow3":
  496. {
  497. saNextUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  498. saNextSignedWays.push(sSignedWay);
  499. }
  500. break;
  501. case "flow4":
  502. { //不能算通知到
  503. $.each(_list.source, function (i, _source) {
  504. _source.SignedDecision = 'T';
  505. _source.SignedDate = newDate();
  506. });
  507. saTipsUsers = Enumerable.From(_list.source).Select("$.SignedId").ToArray();
  508. saNextSignedWays.push(sSignedWay);
  509. ++iCurOder
  510. }
  511. break;
  512. default:
  513. break;
  514. }
  515. }
  516. saNewCheckFlows = saNewCheckFlows.concat(_list.source);
  517. });
  518. //Flow => Handle => END
  519. if (action != 'Handle') {
  520. var CheckNextUser = saNextUsers.length === 0;
  521. if (CheckNextUser && iCurOder === _List.length) {
  522. sHandlePerson = saNewHandleFlows[0].SignedId;
  523. saNextSignedWays.push("flow5");
  524. }
  525. }
  526. g_api.ConnectLite(sEditPrgId, 'InvoiceApplyForCustomerAudit', {
  527. Guid: oCurData.Guid,
  528. Action: action,
  529. GoNext: bGoNext ? 'Y' : 'N',
  530. HandlePerson: sHandlePerson,
  531. NextSignedWays: JSON.stringify(saNextSignedWays),
  532. NextUsers: JSON.stringify(saNextUsers),
  533. TipsUsers: JSON.stringify(saTipsUsers),
  534. CheckFlows: JSON.stringify(saNewCheckFlows),
  535. HandleFlows: JSON.stringify(saNewHandleFlows),
  536. SignedDecision: data.SignedDecision,
  537. HandleDecision: data.HandleDecision
  538. }, function (res) {
  539. if (res.RESULT) {
  540. showMsgAndGo(i18next.t('message.' + action + '_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  541. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  542. }
  543. else {
  544. showMsg(i18next.t('message.' + action + '_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  545. }
  546. }, function () {
  547. showMsg(i18next.t('message.' + action + '_Failed'), 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  548. });
  549. },
  550. /*
  551. * 提交決定謙和所有人(該使用者之前)
  552. */
  553. fnSubmitDecisionForAll = function () {
  554. var data = getFormSerialize(oForm);
  555. g_api.ConnectLite(sEditPrgId, 'InvoiceApplyForCustomerAuditAll', {
  556. Guid: oCurData.Guid,
  557. AutoSignedDecision: data.AutoSignedDecision,
  558. AutoSignedOpinion: data.AutoSignedOpinion
  559. }, function (res) {
  560. var action = 'SubmitDecisionForAll'
  561. if (res.RESULT) {
  562. showMsgAndGo(i18next.t('message.' + action + '_Success'), sProgramId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.Void_Success⇒作廢成功╣
  563. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  564. }
  565. else {
  566. showMsg(i18next.t('message.' + action + '_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  567. }
  568. }, function () {
  569. showMsg(i18next.t('message.' + action + '_Failed'), 'error'); // ╠message.Signed_Failed⇒簽核失敗╣ ╠message.Handle_Failed⇒簽辦失敗╣
  570. });
  571. },
  572. /**
  573. * 上傳附件
  574. * @param {Array} files 上傳的文件
  575. */
  576. fnUpload = function (files) {
  577. var option = {};
  578. option.input = $('#fileInput1');
  579. option.theme = 'dragdropbox';
  580. option.folder = 'InvoiceApplyForCustomer';
  581. option.type = 'list';
  582. option.parentid = sCurAuditFlowId;
  583. if (files) {
  584. option.files = files;
  585. }
  586. fnUploadRegister(option);
  587. option.input = $('#fileInput2');
  588. option.parentid = sCurHandleFlowId;
  589. fnUploadRegister(option);
  590. },
  591. /**
  592. * 抓取客訴編號
  593. * @param {string} Guid
  594. */
  595. fnGetComplaintNumber = function (o) {
  596. g_api.ConnectLite('CrmCom', 'GetComplaintNumber', {
  597. Guid: o.Guid || ''
  598. }, function (res) {
  599. if (res.RESULT) {
  600. var oRes = res.DATA.rel;
  601. if (o.CallBack && typeof o.CallBack === 'function') {
  602. o.CallBack(oRes);
  603. }
  604. }
  605. });
  606. },
  607. /**
  608. * 連接到帳單明細
  609. */
  610. fnGoToBillInfo = function (billno) {
  611. return CallAjax(ComFn.W_Com, ComFn.GetOne, {
  612. Type: '',
  613. Params: {
  614. billinfo: {
  615. OrgID: parent.OrgID,
  616. BillNO: billno
  617. }
  618. }
  619. }, function (res) {
  620. if (res.d) {
  621. var oRes = $.parseJSON(res.d),
  622. sPrgId = oRes.BillType,
  623. sId = oRes.ParentId,
  624. sBillNO = oRes.BillNO,
  625. sIdName = 'ImportBillNO',
  626. sGoTab = '2';
  627. if (sPrgId === 'ExhibitionImport_Upd') {
  628. sGoTab = oRes.IsRetn === 'N' ? '3' : '9';
  629. }
  630. else if (sPrgId === 'ExhibitionExport_Upd') {
  631. sIdName = 'ExportBillNO';
  632. sGoTab = oRes.IsRetn === 'N' ? '3' : '5';
  633. }
  634. else if (sPrgId === 'OtherExhibitionTG_Upd') {
  635. sIdName = 'Guid';
  636. sGoTab = '3';
  637. }
  638. parent.openPageTab(sPrgId, '?Action=Upd&GoTab=' + sGoTab + '&' + sIdName + '=' + sId + '&BillNO=' + sBillNO);
  639. }
  640. });
  641. },
  642. /**
  643. * ToolBar 按鈕事件 function
  644. * @param {Object}inst 按鈕物件對象
  645. * @param {Object} e 事件對象
  646. */
  647. fnButtonHandler = function (inst, e) {
  648. var sId = inst.id;
  649. switch (sId) {
  650. case "Toolbar_Qry":
  651. break;
  652. case "Toolbar_Save":
  653. break;
  654. case "Toolbar_ReAdd":
  655. break;
  656. case "Toolbar_Clear":
  657. clearPageVal();
  658. break;
  659. case "Toolbar_Leave":
  660. pageLeave();
  661. break;
  662. case "Toolbar_Add":
  663. break;
  664. case "Toolbar_Upd":
  665. break;
  666. case "Toolbar_Copy":
  667. fnRefreshFlowsThenCopy(oCurData, fnCopy);
  668. break;
  669. case "Toolbar_Void":
  670. fnVoid();
  671. break;
  672. case "Toolbar_ReEdit":
  673. // ╠message.CheckReEdit⇒確定要抽單嗎?╣ ╠common.Tips⇒提示╣
  674. layer.confirm(i18next.t('message.CheckReEdit'), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  675. fnReEdit();
  676. layer.close(index);
  677. });
  678. break;
  679. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  680. break;
  681. case "Toolbar_Print":
  682. fnPrePrint($(".panel-info"));
  683. break;
  684. default:
  685. alert("No handle '" + sId + "'");
  686. break;
  687. }
  688. },
  689. /**
  690. * 初始化 function
  691. */
  692. init = function () {
  693. var saCusBtns = null;
  694. if (sAction === 'Upd') {
  695. saCusBtns = [
  696. {
  697. id: 'Toolbar_ReEdit',
  698. value: 'common.ReEdit'// ╠common.ReEdit⇒抽單╣
  699. },
  700. {
  701. id: 'Toolbar_Copy',
  702. value: 'common.Toolbar_Copy'// ╠common.Toolbar_Copy⇒複製╣
  703. }];
  704. }
  705. commonInit({
  706. PrgId: sProgramId,
  707. ButtonHandler: fnButtonHandler,
  708. Buttons: saCusBtns,
  709. GoTop: true
  710. });
  711. $.whenArray([
  712. fnSetUserDrop([
  713. {
  714. CallBack: function (data) {
  715. saUsers = data;
  716. }
  717. }
  718. ]),
  719. fnSetArgDrop([
  720. {
  721. ArgClassID: 'Currency',
  722. CallBack: function (data) {
  723. sOptionHtml_Currency = createOptions(data, 'id', 'id');
  724. $('#RemittanceInformation_TotalCurrencyTW,#RemittanceInformation_TotalCurrency').html(sOptionHtml_Currency)[0].remove(0);
  725. }
  726. }
  727. ]),
  728. fnGetComplaintNumber({
  729. CallBack: function (data) {
  730. sOptionHtml_ComplaintNumber = createOptions(data, 'ComplaintNumber', 'ComplaintNumber');
  731. }
  732. })
  733. ])
  734. .done(function () {
  735. fnGet();
  736. });
  737. $("#jsGrid").jsGrid({
  738. width: "100%",
  739. height: "auto",
  740. autoload: true,
  741. filtering: false,
  742. pageLoading: true,
  743. pageIndex: 1,
  744. pageSize: 10000,
  745. fields: [
  746. {
  747. name: "FeeItemName", title: 'common.FeeItemName', width: 300, type: "text"
  748. },
  749. {
  750. name: "BillNO", title: 'common.BillNO', width: 100, type: "text",
  751. itemTemplate: function (val, item) {
  752. return $('<a>', {
  753. html: val,
  754. class: 'a-url',
  755. click: function () {
  756. fnGoToBillInfo(val);
  757. }
  758. });
  759. }
  760. },
  761. {
  762. name: "ComplaintNumber", title: '客訴編號', width: 140, type: "text",
  763. itemTemplate: function (val, item) {
  764. return val;
  765. }
  766. },
  767. {
  768. name: "PrjName", title: 'common.PrjCode', width: 260, type: "text",
  769. itemTemplate: function (val, item) {
  770. return item.PrjCode + (!val ? '' : '(' + val + ')');
  771. }
  772. },
  773. {
  774. name: "Currency", title: 'common.Financial_Currency', width: 80, align: "center", type: "text"
  775. },
  776. {
  777. name: "Amount", title: 'common.Financial_Amount', width: 100, type: "text", align: "right",
  778. itemTemplate: function (val, item) {
  779. return val.toString().toMoney();
  780. }
  781. }
  782. ],
  783. controller: {
  784. loadData: function (args) {
  785. return {
  786. data: oCurData.PayeeInfo,
  787. itemsCount: oCurData.PayeeInfo.length //data.length
  788. };
  789. }
  790. }
  791. });
  792. $("#jsGrid1").jsGrid({
  793. width: "100%",
  794. height: "auto",
  795. autoload: true,
  796. pageLoading: true,
  797. pageIndex: 1,
  798. pageSize: 10000,
  799. rowClass: function (item, itemIndex) {
  800. var sRowClass = '';
  801. if (oCurData.CheckFlows.length !== itemIndex + 1) {
  802. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  803. }
  804. else {
  805. sRowClass = 'last-cell';
  806. }
  807. return sRowClass;
  808. },
  809. fields: [
  810. {
  811. type: "Icon", width: 50, align: "center",
  812. itemTemplate: function (val, item) {
  813. var oIcon = {
  814. flow2: '<img src="../../images/flow2_View.gif">',
  815. flow3: '<img src="../../images/flow3_View.gif">',
  816. flow4: '<img src="../../images/flow4.gif">'
  817. };
  818. return item.Icon ? oIcon[item.SignedWay] || '' : '';
  819. }
  820. },
  821. {
  822. name: "Order", title: 'common.Order', width: 50, align: "center",
  823. itemTemplate: function (val, item) {
  824. return val < 10 ? '0' + val : val;
  825. }
  826. },
  827. {
  828. name: "SignedMember", title: 'common.SignedMember', width: 150,
  829. itemTemplate: function (val, item) {
  830. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  831. }
  832. },
  833. {
  834. name: "SignedDecision", title: 'common.Decision', width: 100,
  835. itemTemplate: function (val, item) {
  836. var sVal = val;
  837. if (val === 'Y') {
  838. sVal = i18next.t("common.Agree");// ╠common.Agree⇒同意╣
  839. }
  840. else if (val === 'N') {
  841. sVal = i18next.t("common.NotAgree");// ╠common.NotAgree⇒不同意╣
  842. }
  843. else if (val === 'O') {
  844. sVal = i18next.t("common.AddOther");// ╠common.AddOther⇒先加簽╣
  845. }
  846. else if (val === 'T') {
  847. sVal = i18next.t("common.HasNotice");// ╠common.HasNotice⇒已通知╣
  848. }
  849. else if (val === 'R') {
  850. sVal = i18next.t("common.HasRead");// ╠common.HasRead⇒已閱讀╣
  851. }
  852. return $('<a>', { html: sVal });
  853. }
  854. },
  855. {
  856. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  857. itemTemplate: function (val, item) {
  858. var saVal = [],
  859. oDiv = $('<div>');
  860. if (item.SignedPush) {
  861. var saFlowsPush = item.SignedPush,
  862. saFlowsPushText = [],
  863. sFlowsPushText = '';
  864. $.each(saFlowsPush, function (idx, flow) {
  865. var sFlowType = i18next.t('common.' + flow.SignedWay);
  866. if (flow.SignedWay !== 'flow1') {
  867. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  868. }
  869. else {
  870. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  871. }
  872. });
  873. sFlowsPushText = saFlowsPushText.join(' → ');
  874. saVal.push($('<a>', { html: sFlowsPushText }));
  875. saVal.push('<br />');
  876. }
  877. if (val) {
  878. saVal.push(val);
  879. saVal.push('<br />');
  880. }
  881. fnGetFiles(oDiv.append(saVal), item.FlowId);
  882. return oDiv;
  883. }
  884. },
  885. {
  886. name: "SignedDate", title: 'common.SignedDate', width: 120,
  887. itemTemplate: function (val, item) {
  888. return val;
  889. }
  890. }
  891. ],
  892. controller: {
  893. loadData: function (args) {
  894. return {
  895. data: oCurData.CheckFlows,
  896. itemsCount: oCurData.CheckFlows.length //data.length
  897. };
  898. }
  899. }
  900. });
  901. $("#jsGrid2").jsGrid({
  902. width: "100%",
  903. height: "auto",
  904. autoload: true,
  905. pageLoading: true,
  906. pageIndex: 1,
  907. pageSize: 10000,
  908. rowClass: function (item, itemIndex) {
  909. var sRowClass = '';
  910. if (oCurData.HandleFlows.length !== itemIndex + 1) {
  911. sRowClass = item.Line ? 'grid-cuscell first-cell' : 'grid-cuscell';
  912. }
  913. else {
  914. sRowClass = 'last-cell';
  915. }
  916. return sRowClass;
  917. },
  918. fields: [
  919. {
  920. name: "SignedMember", title: 'common.HandleMembers', width: 150,
  921. itemTemplate: function (val, item) {
  922. return $('<a>', { html: item.Department + ' ' + item.Jobtitle + '<br>' + item.SignedMember + (item.ParentId == '0' ? '(' + i18next.t("common.AgentPerson") + ')' : '') });// ╠common.CheckReEdit⇒代理人╣
  923. }
  924. },
  925. {
  926. name: "SignedDecision", title: 'common.Status', width: 100,
  927. itemTemplate: function (val, item) {
  928. var sVal = val;
  929. if (val === 'Y') {
  930. sVal = i18next.t("common.Hashandle");// ╠common.Hashandle⇒已經辦╣
  931. }
  932. else if (val === 'N') {
  933. sVal = i18next.t("common.Nothandle");// ╠common.Nothandle⇒未處理╣
  934. }
  935. else if (val === 'O') {
  936. sVal = i18next.t("common.AddOtherAudit");// ╠common.AddOtherAudit⇒轉呈其它主管審批╣
  937. }
  938. return $('<a>', { html: sVal });
  939. }
  940. },
  941. {
  942. name: "SignedOpinion", title: 'common.SignedOpinion', width: 450,
  943. itemTemplate: function (val, item) {
  944. var saVal = [],
  945. oDiv = $('<div>');
  946. if (item.SignedPush) {
  947. var saFlowsPush = item.SignedPush,
  948. saFlowsPushText = [],
  949. sFlowsPushText = '';
  950. $.each(saFlowsPush, function (idx, flow) {
  951. var sFlowType = i18next.t('common.' + flow.SignedWay);
  952. if (flow.SignedWay !== 'flow1') {
  953. saFlowsPushText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  954. }
  955. else {
  956. saFlowsPushText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  957. }
  958. });
  959. sFlowsPushText = saFlowsPushText.join(' → ');
  960. saVal.push($('<a>', { html: sFlowsPushText }));
  961. saVal.push('<br />');
  962. }
  963. if (val) {
  964. saVal.push(val);
  965. saVal.push('<br />');
  966. }
  967. fnGetFiles(oDiv.append(saVal), item.FlowId);
  968. return oDiv;
  969. }
  970. },
  971. {
  972. name: "SignedDate", title: 'common.HandleDate', width: 120,
  973. itemTemplate: function (val, item) {
  974. return val;
  975. }
  976. }
  977. ],
  978. controller: {
  979. loadData: function (args) {
  980. return {
  981. data: oCurData.HandleFlows,
  982. itemsCount: oCurData.HandleFlows.length //data.length
  983. };
  984. }
  985. }
  986. });
  987. $.each([3, 4], function (idx, _grididx) {
  988. fnRegisterAddFlows(_grididx);
  989. $("#jsGrid" + _grididx).jsGrid({
  990. width: "100%",
  991. height: "auto",
  992. autoload: true,
  993. filtering: false,
  994. pageLoading: true,
  995. pageIndex: 1,
  996. pageSize: 10000,
  997. fields: [
  998. {
  999. name: "Order", title: 'common.Order', width: 50, align: "center",
  1000. itemTemplate: function (val, item) {
  1001. return val < 10 ? '0' + val : val;
  1002. }
  1003. },
  1004. {
  1005. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  1006. itemTemplate: function (val, item) {
  1007. return i18next.t('common.' + val);
  1008. }
  1009. },
  1010. {
  1011. type: "Icon", width: 50, align: "center",
  1012. itemTemplate: function (val, item) {
  1013. var oIcon = {
  1014. flow1: '<img src="../../images/flow_check.gif">',
  1015. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  1016. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  1017. flow4: '<img src="../../images/flow4.gif">'
  1018. },
  1019. sIcon = oIcon[item.SignedWay];
  1020. if (item.Order !== saCheckOrder_Push.length) {
  1021. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  1022. }
  1023. return sIcon;
  1024. }
  1025. },
  1026. {
  1027. name: "SignedMember", title: 'common.SignedMember', width: 500,
  1028. itemTemplate: function (val, item) {
  1029. return Enumerable.From(val).ToString(",", "$.name");
  1030. }
  1031. },
  1032. {
  1033. type: "control", title: 'common.Action', width: 200,
  1034. itemTemplate: function (val, item) {
  1035. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1036. class: 'glyphicon glyphicon-pencil',
  1037. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  1038. click: function () {
  1039. var oOption = {};
  1040. oOption.SignedWay = item.SignedWay;
  1041. oOption.SignedMember = item.SignedMember;
  1042. oOption.Callback = function (data) {
  1043. if (data.Users.length > 0) {
  1044. var oFlow = {};
  1045. if (data.FlowType === 'flow1') {
  1046. $.each(data.Users, function (idx, user) {
  1047. var oFlow = {};
  1048. oFlow.id = guid();
  1049. oFlow.Order = item.Order + idx;
  1050. oFlow.SignedWay = data.FlowType;
  1051. oFlow.SignedMember = [{
  1052. id: user.id,
  1053. name: user.name,
  1054. deptname: user.deptname,
  1055. jobname: user.jobname
  1056. }];
  1057. saCheckOrder_Push.insert(item.Order + idx, oFlow);
  1058. });
  1059. }
  1060. else {
  1061. var saSignedMembers = [];
  1062. $.each(data.Users, function (idx, user) {
  1063. saSignedMembers.push({
  1064. id: user.id,
  1065. name: user.name,
  1066. deptname: user.deptname,
  1067. jobname: user.jobname
  1068. });
  1069. });
  1070. oFlow.id = guid();
  1071. oFlow.Order = item.Order;
  1072. oFlow.SignedWay = data.FlowType;
  1073. oFlow.SignedMember = saSignedMembers;
  1074. saCheckOrder_Push.insert(item.Order, oFlow);
  1075. }
  1076. var iOrder = 1;
  1077. $.each(saCheckOrder_Push, function (idx, _data) {
  1078. if (item.id !== _data.id) {
  1079. _data.Order = iOrder;
  1080. iOrder++;
  1081. }
  1082. });
  1083. saCheckOrder_Push = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  1084. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  1085. $("#jsGrid" + _grididx).jsGrid("loadData");
  1086. }
  1087. };
  1088. oPenUserListPop(oOption);
  1089. }
  1090. })),
  1091. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1092. class: 'glyphicon glyphicon-trash',
  1093. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  1094. click: function () {
  1095. var saNewList = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id !== item.id; }).ToArray();
  1096. saCheckOrder_Push = saNewList;
  1097. $.each(saCheckOrder_Push, function (idx, _data) {
  1098. _data.Order = idx + 1;
  1099. });
  1100. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  1101. $("#jsGrid" + _grididx).jsGrid("loadData");
  1102. }
  1103. }))];
  1104. if (saCheckOrder_Push.length !== item.Order) {
  1105. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1106. class: 'glyphicon glyphicon-arrow-down',
  1107. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  1108. click: function () {
  1109. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  1110. iOrder = sOrder * 1;
  1111. $.each(saCheckOrder_Push, function (idx, _data) {
  1112. if (iOrder === _data.Order) {
  1113. _data.Order++;
  1114. }
  1115. else if ((iOrder + 1) === _data.Order) {
  1116. _data.Order--;
  1117. }
  1118. });
  1119. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  1120. $("#jsGrid" + _grididx).jsGrid("loadData");
  1121. }
  1122. })));
  1123. }
  1124. else {
  1125. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  1126. }
  1127. if (1 !== item.Order) {
  1128. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1129. class: 'glyphicon glyphicon-arrow-up',
  1130. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  1131. click: function () {
  1132. var sOrder = Enumerable.From(saCheckOrder_Push).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  1133. iOrder = sOrder * 1;
  1134. $.each(saCheckOrder_Push, function (idx, _data) {
  1135. if (iOrder === _data.Order) {
  1136. _data.Order--;
  1137. }
  1138. else if ((iOrder - 1) === _data.Order) {
  1139. _data.Order++;
  1140. }
  1141. });
  1142. saCheckOrder_Push = releaseGridList(saCheckOrder_Push);
  1143. $("#jsGrid" + _grididx).jsGrid("loadData");
  1144. }
  1145. })));
  1146. }
  1147. return oBtns;
  1148. }
  1149. }
  1150. ],
  1151. controller: {
  1152. loadData: function (args) {
  1153. return {
  1154. data: saCheckOrder_Push,
  1155. itemsCount: saCheckOrder_Push.length //data.length
  1156. };
  1157. }
  1158. }
  1159. });
  1160. });
  1161. };
  1162. init();
  1163. };
  1164. require(['base', 'jsgrid', 'jqprint', 'filer', 'common_eip', 'util'], fnPageInit);