'use strict'; /** * * 清单汇总(需使用 decimal.min.js, zh_calc.js, path_tree.js, lodash.js) * * @author Mai * @date * @version */ const gclGatherModel = (function () { // 需要汇总计算的字段 let ledgerGatherFields = ['quantity', 'total_price', 'deal_qty', 'deal_tp', 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_qc_minus_qty', 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_qc_minus_qty']; let posGatherFields = ['quantity', 'contract_qty', 'qc_qty', 'gather_qty','qc_minus_qty', 'pre_contract_qty', 'pre_qc_qty', 'pre_gather_qty', 'pre_qc_minus_qty', 'end_contract_qty', 'end_qc_qty', 'end_gather_qty', 'end_qc_minus_qty']; let ancillaryGclGatherFields = ['quantity']; // 初始化 清单树 const gsTreeSetting = { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'tender_id', 'ledger_id'], stageId: 'id', }; gsTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'qc_minus_qty']; const gsTree = createNewPathTree('stage', gsTreeSetting); // 初始化 部位明细 const posSetting = { id: 'id', ledgerId: 'lid', updateFields: ['contract_qty', 'qc_qty', 'qc_minus_qty'], }; const gsPos = new StagePosData(posSetting); const gsAncGcl = createAncillaryGcl({ id: 'id', masterId: 'lid', sort: [['g_order', 'asc']] }); let deal = [], change; const gclList = [], leafXmjs = []; const mergeChar = ';'; let tpDecimal = 0; function loadDecimal(decimal) { tpDecimal = decimal.tp; } function loadGatherField(ledger, pos) { if (ledger) ledgerGatherFields = ledger; if (pos) posGatherFields = pos; } /** * 将所有数据加载至树结构 * * @param ledger - 台账数据 * @param curStage - 当期计量数据 * @param preStage - 截止上期计量数据 * @param bgl - 变更令数据 */ function loadLedgerData (ledger, curStage, preStage) { // 加载树结构数据 gsTree.loadDatas(ledger); // 加载本期计量数据 if (curStage) { gsTree.loadCurStageData(curStage); } if (preStage) { gsTree.loadPreStageData(preStage); } } function loadPosData(pos, curPos, prePos) { gsPos.loadDatas(pos); gsPos.loadCurStageData(curPos); gsPos.loadPreStageData(prePos); } function loadAncillaryGclData(datas) { gsAncGcl.loadDatas(datas); } function loadDealBillsData(dealBills) { deal = dealBills; } function loadChangeData(data) { change = data; } function loadStageChangeData(cur, pre) { const gatherDatas = function(datas, field) { for (const d of datas) { const c = change.find(x => { return x.cid === d.cid; }); if (!c) continue; const cb = c.bills.find(x => { return x.id === d.cbid; }); if (!cb) continue; if (d.no_value) { cb[field + '_minus'] = ZhCalc.add(cb[field + '_minus'], d.qty); } else { cb[field] = ZhCalc.add(cb[field], d.qty); } } }; gatherDatas(cur, 'cur_qty'); gatherDatas(pre, 'pre_qty'); } function gatherfields(obj, src, fields) { if (obj && src) { if (fields instanceof Array) { for (const f of fields) { obj[f] = ZhCalc.add(obj[f], src[f]); } } else if (typeof fields === "function") { for (const prop in src) { if (fields(prop)) { obj[prop] = ZhCalc.add(obj[prop], src[prop]); } } } } } /** * 新建 清单汇总节点 * @param node - 最底层 工程量清单节点 * @returns {{b_code: *|string[], name, unit, unit_price: *|string[], leafXmjs: Array}} */ function newGclNode(node) { const gcl = { b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price, org_price: node.org_price, leafXmjs: [], ancGcl: [], change: [], }; gclList.push(gcl); return gcl; } /** * 获取清单汇总节点 * * @param node - 最底层清单节点 * @returns {*} */ function getGclNode(node) { const gcl = gclList.find(function (g) { return g.b_code === node.b_code && (g.name || node.name ? g.name === node.name : true) && (g.unit || node.unit ? g.unit === node.unit : true) && checkZero(ZhCalc.sub(g.unit_price, node.unit_price)); // && (g.org_price && node.org_price ? g.org_price === node.org_price : true); }); if (gcl) { if (node.org_price) gcl.org_price = node.org_price; return gcl; } else { return newGclNode(node); } } /** * 检查 text 是否是Peg * e.g. K123+000(true) Kab+123(false) K123.234+234(false) K12+324.234(true) * * @param text * @returns {*} * @constructor */ function CheckPeg(text) { const pegReg = /[a-zA-Z]*[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/; return pegReg.test(text); } /** * 获取 桩号节点 * @param node - 检索起始节点 * @returns {*} */ function getPegNode (node) { if (node) { if (CheckPeg(node.name)) { return node; } else { const parent = gsTree.getParent(node); return parent ? getPegNode(parent) : null; } } } /** * 获取节点的第N层父节点 * * @param node - 节点(检索起点) * @param level - 第N层 * @returns {*} */ function getNodeByLevel(node, level) { let cur = node; while (cur && cur.level > level) { cur = gsTree.getParent(cur); } return cur; } /** * 获取 单位工程 * * @param xmj - 计量单元(最底层项目节) * @returns {string} */ function getDwgc(peg, xmj) { if (peg) { return peg.name; } else { const node = getNodeByLevel(xmj, 2); return node ? node.name : ''; } } /** * 获取 分部工程 * * @param peg - 桩号节点 * @param xmj - 计量单元(最底层项目节) * @returns {string} */ function getFbgc(peg, xmj) { if (peg && peg.id !== xmj.id) { const node = getNodeByLevel(xmj, peg.level + 1); return node ? node.name : ''; } else { const node = getNodeByLevel(xmj, 3); return node ? node.name : ''; } } /** * 获取 分项工程 * * @param peg - 桩号节点 * @param xmj - 计量单元(最底层项目节) * @returns {string} */ function getFxgc(peg, xmj) { if (!peg) { const node = getNodeByLevel(xmj, 4); return node ? node.name : ''; } else if (peg.id === xmj.id) { if (xmj.level > 4) { let value = ''; for (let level = 4; level < xmj.level; level++) { const node = getNodeByLevel(xmj, level); value = value === '' ? node.name : value + mergeChar + node.name; } return value; } else { return ''; } } else { if (peg.level + 2 < xmj.level) { let value = ''; for (let level = peg.level + 2; level < xmj.level; level++) { const node = getNodeByLevel(xmj, level); value = value === '' ? node.name : value + mergeChar + node.name; } return value; } else { return ''; } } } /** * 新建 最底层项目节 缓存数据 * @param leafXmj * @returns {{id, code: *|string[], jldy, fbgc: string, fxgc: string, dwgc: string, bwmx: string, drawing_code: string}} */ function newCacheLeafXmj(leafXmj) { const peg = getPegNode(leafXmj); const cacheLX = { id: leafXmj.id, code: leafXmj.code, jldy: leafXmj.name, fbgc: getFbgc(peg, leafXmj), fxgc: getFxgc(peg, leafXmj), dwgc: getDwgc(peg, leafXmj), drawing_code: leafXmj.drawing_code, }; leafXmjs.push(cacheLX); return cacheLX; } /** * 获取缓存的最底层项目节数据 * * @param leafXmj - 最底层项目节 * @returns {*} */ function getCacheLeafXmj(leafXmj) { const cacheLX = leafXmjs.find(function (lx) { return lx.id === leafXmj.id; }); if (!cacheLX) { return newCacheLeafXmj(leafXmj); } else { return cacheLX; } } function gatherAncGclData(node, gcl, cacheLeafXmj) { const gclPart = gsAncGcl.getPartData(node.id); if (!gclPart || gclPart.length === 0) return; for (const ag of gclPart) { const condition = _.assign({ is_aux: ag.is_aux, name: ag.name, unit: ag.unit }, cacheLeafXmj); let nag = _.find(gcl.ancGcl, condition); if (!nag) { nag = condition; gcl.ancGcl.push(condition); } gatherfields(nag, ag, ancillaryGclGatherFields); } } /** * 汇总节点 * @param node - 最底层 工程量清单 节点 * @param leafXmj - 所属 最底层 项目节 */ function loadGatherGclNode(node, leafXmj) { const gcl = getGclNode(node); gatherfields(gcl, node, ledgerGatherFields); const cacheLeafXmj = getCacheLeafXmj(leafXmj); const posRange = gsPos.getLedgerPos(node.id); const detail = posRange && posRange.length > 0 ? posRange : [node]; for (const d of detail) { const dx = _.assign({}, cacheLeafXmj); gatherfields(dx, d, posGatherFields); dx.gcl_id = node.id; if (d.name !== node.name) { dx.bwmx = d.name; dx.mx_id = d.id; } else if (dx.gcl_id !== d.id) { dx.mx_id = d.id; } if (d.drawing_code) { dx.drawing_code = d.drawing_code; } dx.settle_status = (posRange && posRange.length > 0 ? d.settle_status : node.settle_status) || 0 ; gcl.leafXmjs.push(dx); } gatherAncGclData(node, gcl, cacheLeafXmj); } /** * (递归)汇总树节点 * @param nodes - 汇总节点列表 * @param leafXmj - 汇总节点所属的底层项目节 */ function recursiveGatherGclData(nodes, leafXmj) { for (const node of nodes) { if (node.b_code) { if (node.children.length > 0) { // const gcl = getGclNode(node); recursiveGatherGclData(node.children, leafXmj); } else { loadGatherGclNode(node, leafXmj); } } else if (node.children.length > 0) { recursiveGatherGclData(node.children, node); } } } function gatherDealBillsData() { if (deal && deal.length > 0) { for (const node of deal) { node.b_code = node.code; const gcl = getGclNode(node); if (!node.quantity || !node.unit_price) continue; gcl.deal_bills_qty = ZhCalc.add(gcl.deal_bills_qty, node.quantity); gcl.deal_bills_tp = ZhCalc.add(gcl.deal_bills_tp, node.total_price); } } } function gatherChangeData() { if (!change || change.length === 0) return; for (const c of change) { const decimal = c.tp_decimal || tpDecimal; for (const cb of c.bills) { cb.b_code = cb.code; const gcl = getGclNode(cb); gcl.change_bills_qty = ZhCalc.add(gcl.change_bills_qty, cb.checked_amount); gcl.change_bills_tp = ZhCalc.add(gcl.change_bills_tp, cb.checked_price); let gcb = gcl.change.find(x => { return x.cid === cb.cid && x.is_valuation === cb.is_valuation; }); if (!gcb) { gcb = { cid: c.cid, code: c.code, name: c.name, is_valuation: cb.is_valuation }; gcl.change.push(gcb); } gcb.org_qty = ZhCalc.add(gcb.org_qty, cb.oamount2); gcb.org_tp = ZhCalc.add(gcb.org_tp, ZhCalc.mul(cb.oamount2, gcl.unit_price, decimal)); gcb.c_qty = ZhCalc.add(gcb.c_qty, cb.checked_amount); gcb.c_tp = ZhCalc.add(gcb.c_tp, cb.checked_price); gcb.cur_qty = ZhCalc.add(gcb.cur_qty, cb.cur_qty); gcb.cur_qty_minus = ZhCalc.add(gcb.cur_qty_minus, cb.cur_qty_minus); gcb.pre_qty = ZhCalc.add(gcb.pre_qty, cb.pre_qty); gcb.pre_qty_minus = ZhCalc.add(gcb.pre_qty_minus, cb.pre_qty_minus); } } } function calculateGatherData() { for (const gcl of gclList) { gcl.pre_gather_qty = ZhCalc.add(gcl.pre_contract_qty, gcl.pre_qc_qty); gcl.pre_gather_tp = ZhCalc.add(gcl.pre_contract_tp, gcl.pre_qc_tp); gcl.gather_qty = ZhCalc.add(gcl.contract_qty, gcl.qc_qty); gcl.end_contract_qty = ZhCalc.add(gcl.pre_contract_qty, gcl.contract_qty); gcl.end_qc_qty = ZhCalc.add(gcl.pre_qc_qty, gcl.qc_qty); gcl.end_gather_qty = ZhCalc.add(gcl.pre_gather_qty, gcl.gather_qty); gcl.end_qc_minus_qty = ZhCalc.add(gcl.pre_qc_minus_qty, gcl.qc_minus_qty); gcl.gather_tp = ZhCalc.sum([gcl.contract_tp, gcl.qc_tp, gcl.pc_tp]); gcl.end_contract_tp = ZhCalc.sum([gcl.pre_contract_tp, gcl.contract_tp, gcl.contract_pc_tp]); gcl.end_qc_tp = ZhCalc.sum([gcl.pre_qc_tp, gcl.qc_tp, gcl.qc_pc_tp]); gcl.end_gather_tp = ZhCalc.add(gcl.pre_gather_tp, gcl.gather_tp); gcl.dgn_price = ZhCalc.round(ZhCalc.div(gcl.total_price, gcl.dgn_qty1), 2); gcl.end_final_qty = ZhCalc.add(gcl.end_qc_qty, gcl.quantity); gcl.end_final_tp = ZhCalc.add(gcl.end_qc_tp, gcl.total_price); gcl.final_qty = ZhCalc.add(gcl.quantity, gcl.change_bills_qty); gcl.final_tp = ZhCalc.add(gcl.total_price, gcl.change_bills_tp); gcl.deal_final_qty = ZhCalc.add(gcl.deal_bills_qty, gcl.change_bills_qty); gcl.deal_final_tp = ZhCalc.add(gcl.deal_bills_tp, gcl.change_bills_tp); gcl.final_1_qty = ZhCalc.add(gcl.quantity, gcl.end_qc_minus_qty); gcl.final_1_tp = ZhCalc.mul(gcl.unit_price, gcl.final_1_qty, tpDecimal); gcl.deal_final_1_qty = ZhCalc.add(gcl.deal_bills_qty, gcl.end_qc_minus_qty); gcl.deal_final_1_tp = ZhCalc.add(gcl.unit_price, gcl.deal_final_1_qty, tpDecimal); gcl.end_final_1_qty = ZhCalc.add(gcl.final_1_qty, gcl.end_qc_qty); gcl.end_final_1_tp = ZhCalc.add(gcl.final_1_tp, gcl.end_qc_tp); gcl.end_gather_percent = gcl.end_gather_qty && gcl.end_final_qty ? ZhCalc.mul(ZhCalc.div(gcl.end_gather_qty, gcl.end_final_qty), 100, 2) : ZhCalc.mul(ZhCalc.div(gcl.end_gather_tp, gcl.end_final_tp), 100, 2); gcl.end_final_1_percent = gcl.end_gather_qty && gcl.end_final_1_qty ? ZhCalc.mul(ZhCalc.div(gcl.end_gather_qty, gcl.end_final_1_qty), 100, 2) : ZhCalc.mul(ZhCalc.div(gcl.end_gather_tp, gcl.end_final_1_tp), 100, 2); gcl.final_percent = gcl.final_qty && gcl.end_gather_qty ? ZhCalc.mul(ZhCalc.div(gcl.end_gather_qty, gcl.final_qty), 100, 2) : ZhCalc.mul(ZhCalc.div(gcl.end_gather_tp, gcl.final_tp), 100, 2); let settle_status = []; for (const xmj of gcl.leafXmjs) { if (settle_status.indexOf(xmj.settle_status) < 0) settle_status.push(xmj.settle_status); xmj.pre_gather_qty = ZhCalc.add(xmj.pre_contract_qty, xmj.pre_qc_qty); xmj.gather_qty = ZhCalc.add(xmj.contract_qty, xmj.qc_qty); xmj.end_contract_qty = ZhCalc.add(xmj.pre_contract_qty, xmj.contract_qty); xmj.end_qc_qty = ZhCalc.add(xmj.pre_qc_qty, xmj.qc_qty); xmj.end_gather_qty = ZhCalc.add(xmj.pre_gather_qty, xmj.gather_qty); xmj.end_final_qty = ZhCalc.add(xmj.end_qc_qty, xmj.quantity); xmj.end_qc_minus_qty = ZhCalc.add(xmj.pre_qc_minus_qty, xmj.qc_minus_qty); xmj.final_1_qty = ZhCalc.add(xmj.quantity, xmj.end_qc_minus_qty); xmj.end_final_1_qty = ZhCalc.add(xmj.final_1_qty, xmj.end_qc_qty); xmj.end_gather_percent = ZhCalc.mul(ZhCalc.div(xmj.end_gather_qty, xmj.end_final_qty), 100, 2); xmj.end_final_1_percent = ZhCalc.mul(ZhCalc.div(xmj.end_gather_qty, xmj.end_final_1_qty), 100, 2); } for (const c of gcl.change) { c.cur_tp = ZhCalc.mul(c.cur_qty, gcl.unit_price, tpDecimal); c.pre_tp = ZhCalc.mul(c.pre_qty, gcl.unit_price, tpDecimal); c.end_qty = ZhCalc.add(c.cur_qty, c.pre_qty); c.end_tp = ZhCalc.add(c.cur_tp, c.pre_tp); c.end_qty_minus = ZhCalc.add(c.cur_qty_minus, c.pre_qty_minus); } gcl.settle_status = settle_status.length === 1 ? settle_status[0] : 1; } } function compareCode(str1, str2, symbol = '-') { if (!str1) { return 1; } else if (!str2) { return -1; } function compareSubCode(code1, code2) { if (numReg.test(code1)) { if (numReg.test(code2)) { return parseInt(code1) - parseInt(code2); } else { return -1 } } else { if (numReg.test(code2)) { return 1; } else { return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1); //code1.localeCompare(code2); } } } const numReg = /^[0-9]+$/; const aCodes = str1.split(symbol), bCodes = str2.split(symbol); for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) { const iCompare = compareSubCode(aCodes[i], bCodes[i]); if (iCompare !== 0) { return iCompare; } } return aCodes.length - bCodes.length; } /** * 根据树结构 清单汇总 */ function gatherGclData() { // 清空旧数据 if (gclList.length > 0) { gclList.length = 0; //splice(0, gclList.length); } recursiveGatherGclData(gsTree.children, null); gatherDealBillsData(); gatherChangeData(); calculateGatherData(); gclList.sort(function (a, b) { return compareCode(a.b_code, b.b_code) || ZhCalc.sub(a.unit_price, b.unit_price); }); return gclList; } function checkDiffer(gclList) { for (const gcl of gclList) { gcl.differ = false; } for (const [i, gcl] of gclList.entries()) { if (i === gclList.length - 1) continue; const next = gclList[i+1]; if (gcl.b_code === next.b_code) { if (gcl.name !== next.name || gcl.unit !== next.unit || !checkZero(gcl.unit_price - next.unit_price)) { gcl.differ = true; next.differ = true; } } } } function _getCalcChapter(chapter, option) { const gclChapter = [], otherChapter = {}, gclChapterFilter = []; let serialNo = 1; for (const c of chapter) { const cc = { code: c.code, name: c.name, cType: 1 }; cc.serialNo = serialNo++; cc.filter = '^[^0-9]*([0-9]{0,2}-)?' + c.code.substr(0, c.code.length - 2) + '[0-9]{2}(-|$)'; gclChapter.push(cc); } gclChapter.push({ name: '未计入章节清单合计', cType: 21, serialNo: serialNo+1 }); otherChapter.hj = { name: '合计(C=A+B+Z)', cType: 41, serialNo: serialNo+5, deal_bills_tp: option.zlj.deal_bills_tp }; gclChapterFilter.push({node_type: option.jrg.value}); gclChapterFilter.push({field: 'name', part: option.jrg.text}); const zlChapter = { name: '暂列金额(Z)', cType: 32, serialNo: serialNo+4, deal_bills_tp: option.zlj.deal_bills_tp, match: [], matchPath: [] }; zlChapter.match.push({node_type: option.zlj.value}); zlChapter.match.push({field: 'name', part: option.zlj.text}); otherChapter.zlj = zlChapter; otherChapter.qd = { name: '清单小计(A)', cType: 11, serialNo: serialNo+2 }; otherChapter.fqd = { name: '非清单项费用(B)', cType: 31, serialNo: serialNo+3 }; return [gclChapter, otherChapter, gclChapterFilter]; } function _gatherChapterFields(chapter, data, fields) { for (const f of fields) { chapter[f] = ZhCalc.add(chapter[f], data[f]); } } function _getGclChapter(chapter, data) { for (const c of chapter) { if (c.filter) { const reg = new RegExp(c.filter); if (reg.test(data.b_code)) { return c; } } else { return c; } } } function _checkFilter(d, filter) { for (const f of filter) { if (f.node_type && f.node_type === d.node_type) return true; if (f.field) { if (f.part && d[f.field] && d[f.field].indexOf(f.part) >= 0) return true; if (f.all && d[f.all] && d[f.all] === f.all) return true; } } return false; } function gatherChapterData(chapter, option, fields) { const chapterFilterPath = []; const checkFilterPath = function (data, filterPath) { for (const fp of filterPath) { if (data.full_path.indexOf(fp + '-') === 0 || data.full_path === fp) return true; } return false; }; const [gclChapter, otherChapter, gclChapterFilter] = _getCalcChapter(chapter, option); for (const d of gsTree.nodes) { if (_checkFilter(d, gclChapterFilter)) chapterFilterPath.push(d.full_path); if (_checkFilter(d, otherChapter.zlj.match)) otherChapter.zlj.matchPath.push(d.full_path); if (d.children && d.children.length > 0) continue; if (checkFilterPath(d,otherChapter.zlj.matchPath)) { gatherfields(otherChapter.zlj, d, fields); gatherfields(otherChapter.hj, d, fields); } else { gatherfields(otherChapter.hj, d, fields); if (d.b_code) { gatherfields(otherChapter.qd, d, fields); } if (!d.b_code || d.b_code === '') { gatherfields(otherChapter.fqd, d, fields); } if (d.b_code) { const c = checkFilterPath(d, chapterFilterPath) ? gclChapter.find(x => { return x.cType === 21}) : _getGclChapter(gclChapter, d); gatherfields(c, d, fields); } } } for (const d of deal) { if (!d.quantity || !d.unit_price) continue; otherChapter.hj.deal_bills_tp = ZhCalc.add(otherChapter.hj.deal_bills_tp, d.total_price); otherChapter.qd.deal_bills_tp = ZhCalc.add(otherChapter.qd.deal_bills_tp, d.total_price); const c = _getGclChapter(gclChapter, d); c.deal_bills_tp = ZhCalc.add(c.deal_bills_tp, d.total_price); } const result = gclChapter.concat([otherChapter.hj, otherChapter.zlj, otherChapter.qd, otherChapter.fqd]); result.sort((x, y) => {return x.serialNo - y.serialNo}); return result; } function _gatherLeafXmj(gcl, fields = ['bwmx']) { gcl.gatherLeafXmjs = []; for (const lx of gcl.leafXmjs) { const condition = {}; for (const f of fields) { condition[f] = lx[f]; } let glx = _.find(gcl.gatherLeafXmjs, condition); if (!glx) { glx = JSON.parse(JSON.stringify(lx)); gcl.gatherLeafXmjs.push(glx); } else { gatherfields(glx, lx, posGatherFields); } } for (const xmj of gcl.gatherLeafXmjs) { xmj.pre_gather_qty = ZhCalc.add(xmj.pre_contract_qty, xmj.pre_qc_qty); xmj.gather_qty = ZhCalc.add(xmj.contract_qty, xmj.qc_qty); xmj.end_contract_qty = ZhCalc.add(xmj.pre_contract_qty, xmj.contract_qty); xmj.end_qc_qty = ZhCalc.add(xmj.pre_qc_qty, xmj.qc_qty); xmj.end_gather_qty = ZhCalc.add(xmj.pre_gather_qty, xmj.gather_qty); xmj.end_final_qty = ZhCalc.add(xmj.end_qc_qty, xmj.quantity); xmj.end_qc_minus_qty = ZhCalc.add(xmj.pre_qc_minus_qty, xmj.qc_minus_qty); xmj.final_1_qty = ZhCalc.add(xmj.quantity, xmj.end_qc_minus_qty); xmj.end_final_1_qty = ZhCalc.add(xmj.final_1_qty, xmj.end_qc_qty); xmj.end_gather_percent = ZhCalc.mul(ZhCalc.div(xmj.end_gather_qty, xmj.end_final_qty), 100, 2); xmj.end_final_1_percent = ZhCalc.mul(ZhCalc.div(xmj.end_gather_qty, xmj.end_final_1_qty), 100, 2); } } function reGatherLeafXmj(fields) { gclList.forEach(g => { _gatherLeafXmj(g, fields); }); } function _gatherAncillaryGcl(gcl, fields = ['jldy']) { fields.push('is_aux', 'name', 'unit'); gcl.gatherAncGcl = []; for (const lx of gcl.ancGcl) { const condition = {}; for (const f of fields) { condition[f] = lx[f]; } let glx = _.find(gcl.gatherAncGcl, condition); if (!glx) { glx = JSON.parse(JSON.stringify(lx)); gcl.gatherAncGcl.push(glx); } else { gatherfields(glx, lx, ancillaryGclGatherFields); } } gcl.gatherAncGcl.sort((a, b) => { if (a.is_aux === b.is_aux) { return a.name < b.name ? -1 : 1; } else { return a.is_aux - b.is_aux; } }); } function reGatherAncillaryGcl(fields) { gclList.forEach(g => { _gatherAncillaryGcl(g, fields); }); } return { loadGatherField, loadDecimal, loadLedgerData, loadPosData, loadAncillaryGclData, loadDealBillsData, loadChangeData, loadStageChangeData, gatherGclData, checkDiffer, gatherChapterData, reGatherLeafXmj, reGatherAncillaryGcl, }; })();