ledger_check.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ledgerCheckType = {
  10. sibling: {value: 1, text: '项目节、清单同层', fun: 'checkSibling', },
  11. empty_code: {value: 2, text: '项目节、清单编号同时为空', fun: 'checkCodeEmpty', },
  12. calc: {value: 3, text: '清单数量不等于计量单元之和', fun: 'checkCalc', },
  13. zero: {value: 4, text: '清单数量或单价为0', fun: 'checkZero', },
  14. tp: {value: 5, text: '清单金额≠数量×单价', fun: 'checkTp', },
  15. over: {value: 6, text: '超计', fun: 'checkOver', },
  16. same_code: {value: 7, text: '重复项目节', fun: 'checkSameCode', },
  17. };
  18. const ledgerCheckUtil = {
  19. checkSibling: function (ledgerTree, ledgerPos, decimal, option) {
  20. const error = [];
  21. for (const node of ledgerTree.nodes) {
  22. if (!node.children || node.children.length === 0) continue;
  23. let hasXmj, hasGcl;
  24. for (const child of node.children) {
  25. if (child.b_code) hasXmj = true;
  26. if (!child.b_code) hasGcl = true;
  27. }
  28. if (hasXmj && hasGcl) error.push(node);
  29. }
  30. return error;
  31. },
  32. checkCodeEmpty: function (ledgerTree, ledgerPos, decimal, option) {
  33. const error = [];
  34. const checkNodeCode = function (node) {
  35. if ((!node.code || node.code === '') && (!node.b_code || node.b_code === '')) error.push(node);
  36. if (node.children && node.children.length > 0) {
  37. for (const child of node.children) {
  38. checkNodeCode(child);
  39. }
  40. }
  41. };
  42. for (const topLevel of ledgerTree.children) {
  43. if ([1, 3, 4].indexOf(topLevel.node_type) < 0) continue;
  44. checkNodeCode(topLevel);
  45. }
  46. return error;
  47. },
  48. checkCalc: function (ledgerTree, ledgerPos, decimal, option) {
  49. const error = [];
  50. for (const node of ledgerTree.nodes) {
  51. if (node.children && node.children.length > 0) continue;
  52. const nodePos = ledgerPos.getLedgerPos(node.id);
  53. if (!nodePos || nodePos.length === 0) continue;
  54. const checkData = {}, calcData = {};
  55. for (const f of option.fields) {
  56. checkData[f] = node[f] || 0;
  57. calcData[f] = 0;
  58. }
  59. for (const np of nodePos) {
  60. for (const f of option.fields) {
  61. calcData[f] = ZhCalc.add(calcData[f], np[f]) || 0;
  62. }
  63. }
  64. if (!_.isMatch(checkData, calcData)) error.push(node);
  65. }
  66. return error;
  67. },
  68. checkZero: function (ledgerTree, ledgerPos, decimal, option) {
  69. const error = [];
  70. for (const node of ledgerTree.nodes) {
  71. if ((!node.b_code || node.b_code === '')) continue;
  72. if (node.children && node.children.length > 0) continue;
  73. if ((checkZero(node.sgfh_qty) && checkZero(node.qtcl_qty) && checkZero(node.sjcl_qty)
  74. && checkZero(node.deal_qty) && checkZero(node.quantity))
  75. || checkZero(node.unit_price)) error.push(node);
  76. }
  77. return error;
  78. },
  79. checkTp: function (ledgerTree, ledgerPos, decimal, option) {
  80. const error = [];
  81. for (const node of ledgerTree.nodes) {
  82. if (node.children && node.children.length > 0) continue;
  83. if (option.filter && option.filter(node)) continue;
  84. const checkData = {}, calcData = {};
  85. for (const f of option.fields) {
  86. checkData[f.tp] = node[f.tp] || 0;
  87. calcData[f.tp] = ZhCalc.mul(node.unit_price, node[f.qty], decimal.tp) || 0;
  88. }
  89. if (!_.isMatch(checkData, calcData)) error.push(node);
  90. }
  91. return error;
  92. },
  93. checkOver: function(ledgerTree, ledgerPos, decimal, option) {
  94. const error = [];
  95. for (const node of ledgerTree.nodes) {
  96. if (node.children && node.children.length > 0) continue;
  97. if (checkUtils.billsOver(node, option.isTz, ledgerPos)) error.push(node);
  98. }
  99. return error;
  100. },
  101. checkSameCode: function (ledgerTree, ledgerPos, decimal, option) {
  102. const error = [];
  103. let xmj = ledgerTree.nodes.filter(x => { return /^((GD*)|G)?[0-9]+/.test(x.code); });
  104. let check = null;
  105. while (xmj.length > 0) {
  106. [check, xmj] = _.partition(xmj, x => { return x.code === xmj[0].code; });
  107. if (check.length > 1) {
  108. error.push(...check);
  109. }
  110. }
  111. return error;
  112. }
  113. };
  114. const ledgerCheck2 = function (setting) {
  115. const ledger = setting.ledgerTree, ledgerPos = setting.ledgerPos, decimal = setting.decimal;
  116. const checkOption = setting.checkOption;
  117. const assignWarningData = function (nodes, checkType, warningData) {
  118. for (const node of nodes) {
  119. warningData.push({
  120. type: checkType,
  121. ledger_id: node.ledger_id,
  122. code: node.code,
  123. b_code: node.b_code,
  124. name: node.name,
  125. })
  126. }
  127. };
  128. const checkData = {
  129. check_time: new Date(),
  130. warning_data: [],
  131. };
  132. const progressData = [];
  133. for (const prop in ledgerCheckType) {
  134. if (!checkOption[prop] || !checkOption[prop].enable) continue;
  135. const errors = ledgerCheckUtil[ledgerCheckType[prop].fun](ledger, ledgerPos, decimal, checkOption[prop]) || [];
  136. assignWarningData(errors, ledgerCheckType[prop].value, checkData.warning_data);
  137. progressData.push({key: prop, caption: ledgerCheckType[prop].text, error: errors.length});
  138. }
  139. setting.checkList.clearCheckData();
  140. if (checkData.warning_data.length > 0) {
  141. setting.checkList.loadCheckData(checkData);
  142. } else {
  143. setting.checkList.hide();
  144. }
  145. return progressData;
  146. };
  147. const getCheckType = function (option) {
  148. const result = {};
  149. for (const o in option) {
  150. if (option[o].enable) {
  151. result[o] = ledgerCheckType[o];
  152. }
  153. }
  154. return result;
  155. };