'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', }, zeroPos: {value: 12, text: '计量单元数量为0', fun: 'checkZeroPos', }, pos_drawingCode: {value: 13, text: '计量单元图册号为空', fun: 'checkPosDrawingCode', }, tp: {value: 5, text: '清单金额≠数量×单价', fun: 'checkTp', }, over: {value: 6, text: '超计', fun: 'checkOver', }, same_code: {value: 7, text: '重复项目节', fun: 'checkSameCode', }, limit3f: { fun: 'check3fLimit', items: [ { value: 8, text: '违规计量(工序报验)', key: 'gxbyOver', type: 'gxby', }, { value: 9, text: '遗漏计量(工序报验)', key: 'gxbyLost', type: 'gxby', }, { value: 10, text: '违规计量(档案管理)', key: 'daglOver', type: 'dagl', }, { value: 11, text: '遗漏计量(档案管理)', key: 'daglLost', type: 'dagl', }, ] }, minus_cb: { value: 12, text: '负变更清单漏计', url: window.location.pathname + '/stageCheck?type=minus_cb' }, }; 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; }, checkZeroPos: 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; for (const np of nodePos) { if (checkZero(np.sgfh_qty) && checkZero(np.qtcl_qty) && checkZero(np.sjcl_qty) && checkZero(np.quantity)) { error.push(node); break; } } } return error; }, checkPosDrawingCode: 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; for (const np of nodePos) { if (!np.drawing_code) { error.push(node); break; } } } 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 xmj = []; const addXmjCheck = function (node) { if (/^((GD*)|G)?[0-9]+/.test(node.code)) xmj.push(node); for (const child of node.children) { addXmjCheck(child); } }; for (const topLevel of ledgerTree.children) { if ([1, 2, 3, 4].indexOf(topLevel.node_type) < 0) continue; addXmjCheck(topLevel); } const xmjPart = {}, xmjIndex = []; for (const x of xmj) { if (!xmjPart[x.code]) { xmjPart[x.code] = []; xmjIndex.push(x.code); } xmjPart[x.code].push(x); } for (const x of xmjIndex) { if (xmjPart[x].length > 1) error.push(...xmjPart[x]); } return error; }, check3fLimit: function (ledgerTree, ledgerPos, decimal, option) { const error = {}; for (const i of ledgerCheckType.limit3f.items) { error[i.key] = []; } if (option.checkType.length === 0) return error; const findPrecision = function (list, unit) { if (unit) { for (const p in list) { if (list[p].unit && list[p].unit === unit) { return list[p]; } } } return list.other; }; const getRatio = function (type, status) { const statusConst = type === 'gxby' ? option.status.gxby : option.status.dagl; const sc = statusConst.find(x => { return x.value === status }); return sc ? sc.ratio : null; }; const getValid = function (type, status, limit) { if (limit) { const statusConst = type === 'gxby' ? option.status.gxby : option.status.dagl; const sc = statusConst.find(x => { return x.value === status; }); return sc ? (sc.limit ? 1 : 0) : 0; } else { return -1; } }; const check3f = function (data, limit, ratio) { if (limit === 0) { if (data.contract_tp || data.pre_contract_tp) return 1; // 违规 } if (limit === 1) { if (ratio === 0) { if (!data.contract_tp && !data.pre_contract_tp) return 2; // 漏计 } else { const tp = ZhCalc.mul(data.final_1_tp, ZhCalc.div(ratio, 100, 4), this.ctx.tender.info.decimal.tp); const checkTp = ZhCalc.add(data.contract_tp, data.pre_contract_tp); if (tp > checkTp) return 1; // 违规 if (tp < checkTp) return 2; // 漏计 } } return 0; // 合法 }; const check3fQty = function (data, limit, ratio, unit) { if (limit === 0) { if (data.contract_qty || data.qc_qty || data.pre_contract_qty || data.pre_qc_qty) return 1; // 违规 } if (limit === 1) { if (!ratio || ratio === 0) { if (!data.contract_qty && !data.qc_qty && !data.pre_contract_qty && !data.pre_qc_qty) return 2; // 漏计 } else { const precision = findPrecision(tenderInfo.precision, unit); const checkQty = ZhCalc.mul(data.final_1_qty, ZhCalc.div(ratio, 100, 4), precision.value); const qty = ZhCalc.add(data.contract_qty, data.pre_contract_qty) || 0; if (qty > checkQty) return 1; // 违规 if (qty < checkQty) return 2; // 漏计 } } return 0; // 合法 }; const checkLeafBills3fLimit = function(bills, checkInfo) { const over = [], lost = []; const posRange = ledgerPos.getLedgerPos(bills.id); if (posRange && posRange.length > 0) { for (const p of posRange) { const posCheckInfo = _.assign({}, checkInfo); for (const ct of option.checkType) { if (p[ct + '_limit'] > 0) { posCheckInfo[ct + '_limit'] = p[ct + '_limit']; } } for (const ct of option.checkType) { const checkResult = check3fQty(p, getValid(ct, p[ct + '_status'], posCheckInfo[ct + '_limit']), getRatio(ct, p[ct + '_status']), bills.unit); if (checkResult === 1) { if (over.indexOf(ct) === -1) over.push(ct); } if (checkResult === 2) { if (lost.indexOf(ct) === -1) lost.push(ct); } } } } else { for (const ct of option.checkType) { const checkResult = bills.is_tp ? check3f(bills, getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), getRatio(ct, bills[ct + '_status'])) : check3fQty(bills, getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), getRatio(ct, bills[ct + '_status']), bills.unit); if (checkResult === 1) { if (over.indexOf(ct) === -1) over.push(ct); } if (checkResult === 2) { if (lost.indexOf(ct) === -1) lost.push(ct); } } } if (over.indexOf('gxby') >= 0) error.gxbyOver.push(bills); if (over.indexOf('dagl') >= 0) error.daglOver.push(bills); if (lost.indexOf('gxby') >= 0) error.gxbyLost.push(bills); if (lost.indexOf('dagl') >= 0) error.daglLost.push(bills); }; const recursiveCheckBills3fLimit = function (bills, parentCheckInfo) { const checkInfo = _.assign({}, parentCheckInfo); for (const ct of option.checkType) { if (bills[ct + '_limit'] > 0) { checkInfo[ct + '_limit'] = bills[ct + '_limit']; } } if (bills.children && bills.children.length > 0) { for (const c of bills.children) { recursiveCheckBills3fLimit(c, checkInfo); } } else { checkLeafBills3fLimit(bills, checkInfo); } }; for (const b of ledgerTree.children) { recursiveCheckBills3fLimit(b, {}); } return error; }, }; const ledgerCheck2 = async 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 checkInfo = ledgerCheckType[prop]; if (checkInfo.items) { const errors = ledgerCheckUtil[checkInfo.fun](ledger, ledgerPos, decimal, checkOption[prop]) || {}; for (const i of checkInfo.items) { if (checkOption[prop].checkType.indexOf(i.type) < 0) continue; assignWarningData(errors[i.key], i.value, checkData.warning_data); progressData.push({key: prop + i.key, caption: i.text, error: errors[i.key].length}); } } else if (checkInfo.url) { const errors = await postDataAsync(checkInfo.url, {}, false); if (errors && errors.minus_cb) { errors.minus_cb.forEach(mcb => { checkData.warning_data.push({ type: checkInfo.value, code: mcb.memo, b_code: mcb.b_code, name: mcb.name, }); }); } progressData.push({key: prop, caption: checkInfo.text, error: errors && errors.minus_cb ? errors.minus_cb.length : 0}); } else { const errors = ledgerCheckUtil[checkInfo.fun](ledger, ledgerPos, decimal, checkOption[prop]) || []; assignWarningData(errors, checkInfo.value, checkData.warning_data); progressData.push({key: prop, caption: checkInfo.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) { if (ledgerCheckType[o].items) { for (const i of ledgerCheckType[o].items) { result[o + i.key] = i; } } else { result[o] = ledgerCheckType[o]; } } } return result; };