123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const ledgerCheckType = {
- sibling: {value: 1, text: '项目节、清单同层'},
- empty_code: {value: 2, text: '项目节、清单编号同时为空'},
- calc: {value: 3, text: '清单数量不等于计量单元之和'},
- zero: {value: 4, text: '清单数量或单价为0'},
- tp: {value: 5, text: '清单金额≠数量×单价'},
- over: {value: 6, text: '超计'},
- };
- const ledgerCheckUtil = {
- checkSibling: function (ledgerTree) {
- const error = [];
- for (const node of ledgerTree.nodes) {
- if (!node.children || node.children.length === 0) continue;
- let hasXmj, hasGcl;
- for (const child of node.children) {
- if (child.b_code) hasXmj = true;
- if (!child.b_code) hasGcl = true;
- }
- if (hasXmj && hasGcl) error.push(node);
- }
- return error;
- },
- checkCodeEmpty: function (ledgerTree) {
- const error = [];
- const checkNodeCode = function (node) {
- if ((!node.code || node.code === '') && (!node.b_code || node.b_code === '')) error.push(node);
- if (node.children && node.children.length > 0) {
- for (const child of node.children) {
- checkNodeCode(child);
- }
- }
- }
- for (const topLevel of ledgerTree.children) {
- if (topLevel.node_type !== 1) continue;
- checkNodeCode(topLevel);
- }
- return error;
- },
- checkCalc: function (ledgerTree, ledgerPos, option) {
- const error = [];
- for (const node of ledgerTree.nodes) {
- if (node.children && node.children.length > 0) continue;
- const nodePos = ledgerPos.getLedgerPos(node.id);
- if (!nodePos || nodePos.length === 0) continue;
- const checkData = {}, calcData = {};
- for (const f of option.fields) {
- checkData[f] = node[f] || 0;
- calcData[f] = 0;
- }
- for (const np of nodePos) {
- for (const f of option.fields) {
- calcData[f] = ZhCalc.add(calcData[f], np[f]) || 0;
- }
- }
- if (!_.isMatch(checkData, calcData)) error.push(node);
- }
- return error;
- },
- checkZero: function (ledgerTree) {
- const error = [];
- for (const node of ledgerTree.nodes) {
- if ((!node.b_code || node.b_code === '')) continue;
- if (node.children && node.children.length > 0) continue;
- if ((checkZero(node.sgfh_qty) && checkZero(node.qtcl_qty) && checkZero(node.sjcl_qty)
- && checkZero(node.deal_qty) && checkZero(node.quantity))
- || checkZero(node.unit_price)) error.push(node);
- }
- return error;
- },
- checkTp: function (ledgerTree, decimal, option) {
- const error = [];
- for (const node of ledgerTree.nodes) {
- if (node.children && node.children.length > 0) continue;
- if (option.filter && option.filter(node)) continue;
- const checkData = {}, calcData = {};
- for (const f of option.fields) {
- checkData[f.tp] = node[f.tp] || 0;
- calcData[f.tp] = ZhCalc.mul(node.unit_price, node[f.qty], decimal.tp) || 0;
- }
- if (!_.isMatch(checkData, calcData)) error.push(node);
- }
- return error;
- },
- checkOver: function(ledgerTree, ledgerPos, option) {
- const error = [];
- for (const node of ledgerTree.nodes) {
- if (node.children && node.children.length > 0) continue;
- if (option.isTz) {
- const posRange = ledgerPos.getLedgerPos(node.id) || [];
- if (posRange.length > 0) {
- for (const p of posRange) {
- if (p.end_contract_qty > p.quantity) {
- error.push(node);
- continue;
- }
- }
- }
- }
- if (node.is_tp) {
- if (option.isTz) {
- if (node.end_contract_tp > node.total_price) error.push(node);
- } else {
- if (node.end_contract_tp > node.deal_tp) error.push(node);
- }
- } else {
- if (option.isTz) {
- if (node.end_contract_qty > node.quantity) error.push(node);
- } else {
- if (node.end_contract_qty > node.deal_qty) error.push(node);
- }
- }
- }
- return error;
- },
- };
- const ledgerCheck2 = function (setting) {
- const ledger = setting.ledgerTree, ledgerPos = setting.ledgerPos, decimal = setting.decimal;
- const checkOption = setting.checkOption;
- const assignWarningData = function (nodes, checkType, warningData) {
- for (const node of nodes) {
- warningData.push({
- type: checkType,
- ledger_id: node.ledger_id,
- code: node.code,
- b_code: node.b_code,
- name: node.name,
- })
- }
- };
- const checkData = {
- check_time: new Date(),
- warning_data: [],
- };
- const progressData = [];
- if (checkOption.sibling.enable) {
- const sibling = ledgerCheckUtil.checkSibling(ledger, checkOption.sibling) || [];
- assignWarningData(sibling, ledgerCheckType.sibling.value, checkData.warning_data);
- progressData.push({key: 'sibling', caption: ledgerCheckType.sibling.text, error: sibling.length});
- }
- if (checkOption.empty_code.enable) {
- const empty_code = ledgerCheckUtil.checkCodeEmpty(ledger, checkOption.empty_code) || [];
- assignWarningData(empty_code, ledgerCheckType.empty_code.value, checkData.warning_data);
- progressData.push({key: 'empty_code', caption: ledgerCheckType.empty_code.text, error: empty_code.length});
- }
- if (checkOption.calc.enable) {
- const calc = ledgerCheckUtil.checkCalc(ledger, ledgerPos, checkOption.calc) || [];
- assignWarningData(calc, ledgerCheckType.calc.value, checkData.warning_data);
- progressData.push({key: 'calc', caption: ledgerCheckType.calc.text, error: calc.length});
- }
- if (checkOption.zero.enable) {
- const zero = ledgerCheckUtil.checkZero(ledger, checkOption.zero) || [];
- assignWarningData(zero, ledgerCheckType.zero.value, checkData.warning_data);
- progressData.push({key: 'zero', caption: ledgerCheckType.zero.text, error: zero.length});
- }
- if (checkOption.tp.enable) {
- const tp = ledgerCheckUtil.checkTp(ledger, decimal, checkOption.tp) || [];
- assignWarningData(tp, ledgerCheckType.tp.value, checkData.warning_data);
- progressData.push({key: 'tp', caption: ledgerCheckType.tp.text, error: tp.length});
- }
- if (checkOption.over && checkOption.over.enable) {
- const over = ledgerCheckUtil.checkOver(ledger, ledgerPos, checkOption.over) || [];
- assignWarningData(over, ledgerCheckType.over.value, checkData.warning_data);
- progressData.push({key: 'over', caption: ledgerCheckType.over.text, error: over.length});
- }
- setting.checkList.clearCheckData();
- if (checkData.warning_data.length > 0) {
- setting.checkList.loadCheckData(checkData);
- } else {
- setting.checkList.hide();
- }
- return progressData;
- };
- const getCheckType = function (option) {
- const result = {};
- for (const o in option) {
- if (option[o].enable) {
- result[o] = ledgerCheckType[o];
- }
- }
- return result;
- };
|