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.

1219 lines
62 KiB

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