'use strict'; /** * * * @author Mai * @date * @version */ const ledgerCheckType = { sibling: {value: 1, text: '项目节、清单同层', fun: 'checkSibling', }, empty_code: {value: 2, text: '项目节、清单编号同时为空', fun: 'checkCodeEmpty', }, calc: {value: 3, text: '清单数量不等于计量单元之和', fun: 'checkCalc', }, zero: {value: 4, text: '清单数量或单价为0', fun: 'checkZero', }, tp: {value: 5, text: '清单金额≠数量×单价', fun: 'checkTp', }, over: {value: 6, text: '超计', fun: 'checkOver', }, same_code: {value: 7, text: '重复项目节', fun: 'checkSameCode', }, }; const ledgerCheckUtil = { checkSibling: function (ledgerTree, ledgerPos, decimal, option) { 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, ledgerPos, decimal, option) { 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 ([1, 3, 4].indexOf(topLevel.node_type) < 0) continue; checkNodeCode(topLevel); } return error; }, checkCalc: function (ledgerTree, ledgerPos, decimal, 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, ledgerPos, decimal, option) { 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, ledgerPos, 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, decimal, option) { const error = []; for (const node of ledgerTree.nodes) { if (node.children && node.children.length > 0) continue; if (checkUtils.billsOver(node, option.isTz, ledgerPos)) error.push(node); } return error; }, checkSameCode: function (ledgerTree, ledgerPos, decimal, option) { const error = []; let xmj = ledgerTree.nodes.filter(x => { return /^((GD*)|G)?[0-9]+/.test(x.code); }); let check = null; while (xmj.length > 0) { [check, xmj] = _.partition(xmj, x => { return x.code === xmj[0].code; }); if (check.length > 1) { error.push(...check); } } 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 = []; for (const prop in ledgerCheckType) { if (!checkOption[prop] || !checkOption[prop].enable) continue; const errors = ledgerCheckUtil[ledgerCheckType[prop].fun](ledger, ledgerPos, decimal, checkOption[prop]) || []; assignWarningData(errors, ledgerCheckType[prop].value, checkData.warning_data); progressData.push({key: prop, caption: ledgerCheckType[prop].text, error: errors.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; };