1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const Ledger = require('./ledger');
- const imType = require('../const/tender').imType;
- const mergeChar = ';';
- const version = '1.0';
- class StageIm {
- constructor(ctx) {
- const self = this;
- this.ctx = ctx;
- this._ = this.ctx.helper._;
- // mainData
- this.billsTree = new Ledger.billsTree(this.ctx, {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tender_id', 'ledger_id'],
- stageId: 'id',
- calcFields: ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'gather_tp'],
- calc(node) {
- if (node.children && node.children.length === 0) {
- node.pre_gather_qty = self.ctx.helper.add(node.pre_contract_qty, node.pre_qc_qty);
- node.gather_qty = self.ctx.helper.add(node.contract_qty, node.qc_qty);
- node.end_contract_qty = self.ctx.helper.add(node.pre_contract_qty, node.contract_qty);
- node.end_qc_qty = self.ctx.helper.add(node.pre_qc_qty, node.qc_qty);
- node.end_qc_minus_qty = self.ctx.helper.add(node.pre_qc_minus_qty, node.qc_minus_qty);
- node.end_gather_qty = self.ctx.helper.add(node.pre_gather_qty, node.gather_qty);
- }
- node.pre_gather_tp = self.ctx.helper.add(node.pre_contract_tp, node.pre_qc_tp);
- node.gather_tp = self.ctx.helper.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
- node.end_contract_tp = self.ctx.helper.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
- node.end_qc_tp = self.ctx.helper.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
- node.end_gather_tp = self.ctx.helper.add(node.pre_gather_tp, node.gather_tp);
- },
- });
- this.pos = new Ledger.pos({
- id: 'id', ledgerId: 'lid',
- updateFields: ['contract_qty', 'qc_qty', 'qc_minus_qty', 'postil'],
- calc(p) {
- p.pre_gather_qty = self.ctx.helper.add(p.pre_contract_qty, p.pre_qc_qty);
- p.gather_qty = self.ctx.helper.add(p.contract_qty, p.qc_qty);
- p.end_contract_qty = self.ctx.helper.add(p.pre_contract_qty, p.contract_qty);
- p.end_qc_qty = self.ctx.helper.add(p.pre_qc_qty, p.qc_qty);
- p.end_qc_minus_qty = self.ctx.helper.add(p.pre_qc_minus_qty, p.qc_minus_qty);
- p.end_gather_qty = self.ctx.helper.add(p.pre_gather_qty, p.gather_qty);
- },
- });
- // relaData
- this.change = null;
- this.details = null;
- // result
- this.ImData = [];
- this.ImBillsData = [];
- //
- this.imFields = ['uuid', 'doc_code', 'peg', 'bw', 'xm', 'drawing_code', 'calc_memo', 'calc_memo_org', 'calc_img_remark', 'calc_img', 'position', 'jldy'];
- this.splitChar = '-';
- }
- // 加载数据
- async _loadMainData() {
- const billsData = this.ctx.stage.ledgerHis
- ? await this.ctx.helper.loadLedgerDataFromOss(this.ctx.stage.ledgerHis.bills_file)
- : await this.ctx.service.ledger.getData(this.ctx.tender.id);
- const curStage = this.ctx.stage.readOnly
- ? await this.ctx.service.stageBills.getAuditorStageData2(this.ctx.tender.id,
- this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder)
- : await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
- const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
- const bpcStage = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: this.ctx.stage.id } });
- this.ctx.helper.assignRelaData(billsData, [
- { data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty'], prefix: '', relaId: 'lid' },
- { data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty'], prefix: 'pre_', relaId: 'lid' },
- { data: bpcStage, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'org_price'], prefix: '', relaId: 'lid' },
- ]);
- this.billsTree.loadDatas(billsData);
- this.billsTree.calculateAll();
- const posData = this.ctx.stage.ledgerHis
- ? await this.ctx.helper.loadLedgerDataFromOss(this.ctx.stage.ledgerHis.pos_file)
- : await this.ctx.service.pos.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
- const curPosStage = this.ctx.stage.readOnly
- ? await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
- this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder)
- : await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
- const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
- this.ctx.helper.assignRelaData(posData, [
- { data: curPosStage, fields: ['contract_qty', 'qc_qty', 'qc_minus_qty'], prefix: '', relaId: 'pid' },
- { data: prePosStage, fields: ['contract_qty', 'qc_qty', 'qc_minus_qty'], prefix: 'pre_', relaId: 'pid' },
- ]);
- this.pos.loadDatas(posData);
- this.pos.calculateAll();
- }
- async _loadRelaData() {
- if (this.ctx.stage.readOnly) {
- this.details = await this.ctx.service.stageDetail.getAuditorStageData(this.ctx.tender.id, this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
- } else {
- this.details = await this.ctx.service.stageDetail.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
- }
- if (this.ctx.stage.readOnly) {
- this.changes = await this.ctx.service.stageChange.getAuditorAllStageData(this.ctx.tender.id, this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
- } else {
- this.changes = await this.ctx.service.stageChange.getLastestAllStageData(this.ctx.tender.id, this.ctx.stage.id);
- }
- this.import_changes = await this.ctx.service.stageImportChange.getStageImportData(this.ctx.stage);
- }
- // 检查汇总节点
- async _checkGather() {
- const gatherNodes = this.stage.im_gather_node ? this.stage.im_gather_node.split(',') : [];
- for (const node of this.billsTree.datas) {
- node.check = gatherNodes.indexOf(node.id) !== -1;
- }
- }
- // 辅助取值方法
- _getNumberFormat(num, length) {
- let s = '0000000000';
- s = s + num;
- return s.substr(s.length - length);
- }
- _getNodeByLevel(node, level) {
- let cur = node;
- while (cur && cur.level > level) {
- cur = this.billsTree.getParent(cur);
- }
- return cur;
- }
- _checkPeg(text) {
- const pegReg = /[a-zA-Z]*[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
- return pegReg.test(text);
- }
- _getPegStr(text) {
- const pegReg1 = /[a-zA-Z]*[kK][0-9]+[++][0-9]{3}([.][0-9]+)?[~~—][a-zA-Z]*[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
- const result1 = text.match(pegReg1);
- if (result1) {
- return result1[0];
- }
- const pegReg2 = /[a-zA-Z]*[kK][0-9]+[++][0-9]{3}([.][0-9]+)?-[a-zA-Z]*[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
- const result2 = text.match(pegReg2);
- if (result2) {
- return result2[0];
- }
- const pegReg3 = /[a-zA-Z]*[kK][0-9]+[++][0-9]{3}([.][0-9]+)?/;
- const result3 = text.match(pegReg3);
- return result3 ? result3[0] : '';
- }
- _getPegNode(node) {
- if (node) {
- if (this._checkPeg(node.name)) {
- return node;
- }
- const parent = this.billsTree.getParent(node);
- return parent ? this._getPegNode(parent) : null;
- }
- }
- _getDrawingCode(node) {
- if (!node) {
- return '';
- } else if (node.drawing_code) {
- return node.drawing_code;
- }
- const parent = this.billsTree.getParent(node);
- return parent ? this._getDrawingCode(parent) : '';
- }
- _getZlNormalBw(node, peg) {
- if (peg) {
- const subPeg1 = this._getNodeByLevel(node, peg.level + 1);
- const subPeg2 = this._getNodeByLevel(node, peg.level + 2);
- let result = peg.name;
- if (subPeg1 && subPeg1.id !== peg.id && subPeg1.id !== node.id) {
- result = result + mergeChar + subPeg1.name;
- if (subPeg2 && subPeg2.id !== subPeg1.id && subPeg2.id !== node.id) {
- result = result + mergeChar + subPeg2.name;
- }
- }
- return result;
- }
- if (node.level === 2 || node.level === 3) {
- return node.name;
- } else if (node.level >= 4) {
- let parent = this.billsTree.getParent(node),
- result = parent.name;
- while (parent.level > 3 && parent) {
- parent = this._getNodeByLevel(node, parent.level - 1);
- result = parent.name + mergeChar + result;
- }
- return result;
- }
- return '';
- }
- _getZlGatherBw(node, peg) {
- if (peg) {
- const subPeg1 = this._getNodeByLevel(node, peg.level + 1);
- let result = peg.name;
- if (subPeg1 && subPeg1.id !== peg.id) {
- result = result + mergeChar + subPeg1.name;
- }
- return result;
- }
- if (node.level < 3) {
- return node.name;
- }
- let parent = node,
- result = parent.name;
- while (parent.level > 3 && parent) {
- parent = this._getNodeByLevel(node, parent.level - 1);
- result = parent.name + mergeChar + result;
- }
- return result;
- }
- _getBwBillsBw(node) {
- if (node.level < 3) {
- return '';
- } else {
- let parent = node, result = parent.name;
- while (parent.level > 3 && parent) {
- parent = this._getNodeByLevel(node, parent.level - 1);
- result = parent.name + mergeChar + result;
- }
- return result;
- }
- }
- /**
- * 获取 单位工程
- *
- * @param xmj - 计量单元(最底层项目节)
- * @returns {string}
- */
- _getDwgc(peg, xmj) {
- if (peg) {
- return peg.name;
- } else {
- const node = this._getNodeByLevel(xmj, 2);
- return node ? node.name : '';
- }
- }
- /**
- * 获取 分部工程
- *
- * @param peg - 桩号节点
- * @param xmj - 计量单元(最底层项目节)
- * @returns {string}
- */
- _getFbgc(peg, xmj) {
- if (peg && peg.id !== xmj.id) {
- const node = this._getNodeByLevel(xmj, peg.level + 1);
- return node ? node.name : '';
- } else {
- const node = this._getNodeByLevel(xmj, 3);
- return node ? node.name : '';
- }
- }
- /**
- * 获取 分项工程
- *
- * @param peg - 桩号节点
- * @param xmj - 计量单元(最底层项目节)
- * @returns {string}
- */
- _getFxgc(peg, xmj) {
- if (!peg) {
- const node = this._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 = this._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 = this._getNodeByLevel(xmj, level);
- value = value === '' ? node.name : value + mergeChar + node.name;
- }
- return value;
- } else {
- return '';
- }
- }
- }
- _checkCustomDetail(im) {
- const self = this;
- let cd;
- switch (this.stage.im_type) {
- case imType.tz.value:
- cd = this._.find(this.details, function (d) {
- return im.lid === d.lid &&
- (!im.code || im.code === d.code) &&
- (!im.name || im.name === d.name) &&
- (!im.unit || im.unit === d.unit) &&
- ((!im.pid && !d.pid) || im.pid === d.pid) &&
- ((!im.pos_name && !d.pos_name) || im.pos_name === d.pos_name);
- });
- break;
- case imType.zl.value:
- cd = this._.find(this.details, function (d) {
- return im.lid === d.lid &&
- (!im.code || im.code === d.code) &&
- (!im.name || im.name === d.name) &&
- (!im.unit || im.unit === d.unit) &&
- self.ctx.helper.checkZero(self.ctx.helper.sub(im[self.up_field], d[self.up_field])) &&
- ((!im.pid && !d.pid) || im.pid === d.pid) &&
- ((!im.pos_name && !d.pos_name) || im.pos_name === d.pos_name);
- });
- break;
- case imType.bw.value:
- cd = this._.find(this.details, function (d) {
- return im.lid === d.lid &&
- (!im.code || im.code === d.code) &&
- (!im.name || im.name === d.name) &&
- (!im.unit || im.unit === d.unit) &&
- self.ctx.helper.checkZero(self.ctx.helper.sub(im[self.up_field], d[self.up_field])) &&
- ((!im.pid && !d.pid) || im.pid === d.pid) &&
- ((!im.pos_name && !d.pos_name) || im.pos_name === d.pos_name);
- });
- break;
- case imType.bb.value:
- cd = this._.find(this.details, function (d) {
- return im.lid === d.lid &&
- (!im.name || im.name === d.name) &&
- (!im.unit || im.unit === d.unit) &&
- ((!im.pid && !d.pid) || im.pid === d.pid) &&
- ((!im.pos_name && !d.pos_name) || im.pos_name === d.pos_name);
- });
- break;
- }
- if (cd) {
- im.custom_define = im.custom_define !== null ? (cd.custom_define ? cd.custom_define.split(',') : []) : this.imFields;
- this._.assignInWith(im, cd, function(oV, sV, key) { return im.custom_define.indexOf(key) > -1 ? sV : oV; });
- }
- }
- _getCalcMemo(im) {
- if (im.gclBills && im.gclBills.length > 0) {
- const self = this;
- im.gclBills.sort(function (x, y) {
- return self.ctx.helper.compareCode(x.b_code, y.b_code);
- });
- for (const b of im.gclBills) {
- b.imid = im.id;
- this.ImBillsData.push(b);
- }
- }
- if (im.calc_memo !== undefined && im.calc_memo !== null && im.calc_memo !== '') return;
- if (im.leafXmjs && im.leafXmjs.length > 0) {
- const memo = ['本期计量:' + (im.jl || 0) + (im.qc_minus_jl ? (` (不计价 ${im.qc_minus_jl}) `) : ' ') + im.unit];
- for (const lx of im.leafXmjs) {
- for (const p of lx.pos) {
- memo.push(p.name + ':' + (p.jl || 0) + (p.qc_minus_jl ? (` (不计价 ${p.qc_minus_jl}) `) : ' ') + im.unit);
- }
- }
- im.calc_memo = memo.join('\n');
- } else if (im.gclBills && im.gclBills.length > 0) {
- const memo = [];
- for (const [i, b] of im.gclBills.entries()) {
- if (b.pos && b.pos.length > 0) {
- memo.push('清单' + (i + 1) + ':' + b.b_code + ' ' + b.name);
- for (const p of b.pos) {
- memo.push(p.name + ':' + (p.jl || 0) + (p.qc_minus_jl ? (` (不计价 ${p.qc_minus_jl}) `) : ' ') + b.unit);
- }
- } else {
- memo.push('清单' + (i+1) + ':' + b.b_code + ' ' + b.name + ':' + (b.jl || 0) + (b.qc_minus_jl ? (` (不计价 ${b.qc_minus_jl}) `) : ' ') + b.unit);
- }
- }
- im.calc_memo = memo.join('\n');
- } else {
- im.calc_memo = '';
- }
- }
- _getChangeInfo(im) {
- if (im.changes && im.changes.length > 0) {
- const code = this._.uniq(this._.map(im.changes, 'c_code'));
- if (!im.bgl_code || im.bgl_code === '') im.bgl_code = code.join(';');
- const new_code = this._.uniq(this._.map(im.changes, 'c_new_code'));
- if (!im.bgl_drawing_code || im.bgl_drawing_code === '') im.bgl_drawing_code = new_code.join(';');
- }
- }
- _generateTzPosData(node, gclBills) {
- if (!gclBills.pos) {
- gclBills.pos = [];
- }
- const posRange = this.pos.getLedgerPos(node.id);
- if (!posRange) { return; }
- for (const p of posRange) {
- if (this.ctx.helper.checkZero(p.contract_qty) && this.ctx.helper.checkZero(p.contract_qty)) { continue; }
- let lp = this._.find(gclBills.pos, { name: p.name });
- if (!lp) {
- lp = { name: p.name };
- gclBills.pos.push(lp);
- }
- lp.jl = this.ctx.helper.add(lp.jl, p.gather_qty);
- lp.contract_jl = this.ctx.helper.add(lp.contract_jl, p.contract_qty);
- lp.qc_jl = this.ctx.helper.add(lp.qc_jl, p.qc_qty);
- lp.qc_minus_jl = this.ctx.helper.add(lp.qc_minus_jl, p.qc_minus_qty);
- }
- }
- _recursiveGenerateTzGclBills(node, im) {
- for (const p of node.children) {
- if (p.children && p.children.length > 0) {
- this._recursiveGenerateTzGclBills(p, im);
- } else {
- if ((!p.b_code || p.b_code === '') || (p.children && p.children.length > 0)) continue;
- if (this.ctx.helper.checkZero(p.contract_qty) && this.ctx.helper.checkZero(p.contract_tp) &&
- this.ctx.helper.checkZero(p.qc_qty) && this.ctx.helper.checkZero(p.qc_tp) && this.ctx.helper.checkZero(p.qc_minus_qty)) {
- continue;
- }
- let b = this._.find(im.gclBills, { bid: p.id });
- if (!b) {
- b = { imid: im.id, bid: p.id, b_code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price };
- im.gclBills.push(b);
- }
- b.quantity = this.ctx.helper.add(b.quantity, p.quantity);
- b.total_price = this.ctx.helper.add(b.total_price, p.total_price);
- b.jl = this.ctx.helper.add(b.jl, p.gather_qty);
- b.contract_jl = this.ctx.helper.add(b.contract_jl, p.contract_qty);
- b.qc_jl = this.ctx.helper.add(b.qc_jl, p.qc_qty);
- b.qc_minus_jl = this.ctx.helper.add(b.qc_minus_jl, p.qc_minus_qty);
- b.tp = this.ctx.helper.add(b.tp, p.gather_tp);
- b.contract_tp = this.ctx.helper.add(b.contract_tp, p.contract_tp);
- b.qc_tp = this.ctx.helper.add(b.qc_tp, p.qc_tp);
- b.pre_jl = this.ctx.helper.add(b.pre_jl, p.pre_gather_qty);
- b.pre_contract_jl = this.ctx.helper.add(b.pre_contract_jl, p.pre_contract_qty);
- b.pre_qc_jl = this.ctx.helper.add(b.pre_qc_jl, p.pre_qc_qty);
- b.pre_qc_minus_jl = this.ctx.helper.add(b.pre_qc_minus_jl, p.pre_qc_minus_qty);
- b.pre_tp = this.ctx.helper.add(b.pre_tp, p.pre_gather_tp);
- b.pre_contract_tp = this.ctx.helper.add(b.pre_contract_tp, p.pre_contract_tp);
- b.pre_qc_tp = this.ctx.helper.add(b.pre_qc_tp, p.pre_qc_tp);
- b.end_jl = this.ctx.helper.add(b.end_jl, p.end_gather_qty);
- b.end_contract_jl = this.ctx.helper.add(b.end_contract_jl, p.end_contract_qty);
- b.end_qc_jl = this.ctx.helper.add(b.end_qc_jl, p.end_qc_qty);
- b.end_qc_minus_jl = this.ctx.helper.add(b.end_qc_minus_jl, p.end_qc_minus_qty);
- b.end_tp = this.ctx.helper.add(b.end_tp, p.end_gather_tp);
- b.end_contract_tp = this.ctx.helper.add(b.end_contract_tp, p.end_contract_tp);
- b.end_qc_tp = this.ctx.helper.add(b.end_qc_tp, p.end_qc_tp);
- this._generateTzPosData(p, b);
- }
- }
- }
- _generateTzGclBillsData(node, im) {
- if (!im.gclBills) {
- im.gclBills = [];
- }
- this._recursiveGenerateTzGclBills(node, im);
- }
- _generateTzChangeData(node, im) {
- if (!im.changes) {
- im.changes = [];
- }
- const posterity = this.billsTree.getPosterity(node);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) {
- continue;
- }
- const posRange = this.pos.getLedgerPos(p.id);
- if (!posRange) {
- for (const c of this.changes) {
- if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
- im.changes.push(c);
- }
- }
- this.import_changes.forEach(x => { if (x.lid === p.id) im.changes.push(x) });
- } else {
- for (const pp of posRange) {
- for (const c of this.changes) {
- if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
- im.changes.push(c);
- }
- }
- }
- }
- }
- }
- _checkUsed(node) {
- const helper = this.ctx.helper;
- if (node.children && node.children.length > 0) {
- const posterity = this.billsTree.getPosterity(node);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) continue;
- if (!helper.checkZero(p.contract_qty) || !helper.checkZero(p.contract_tp) ||
- !helper.checkZero(p.qc_qty) || !helper.checkZero(p.qc_tp) || !helper.checkZero(p.qc_minus_qty))
- return true;
- const pPos = this.pos.getLedgerPos(p.id);
- if (!pPos || pPos.length === 0) continue;
- for (const pp of pPos) {
- if (!helper.checkZero(pp.contract_qty) || !helper.checkZero(pp.qc_qty) || !helper.checkZero(pp.qc_minus_qty)) return true;
- }
- }
- return false;
- } else {
- if (!helper.checkZero(node.contract_qty) || !helper.checkZero(node.contract_tp) ||
- !helper.checkZero(node.qc_qty) || !helper.checkZero(node.qc_tp) || !helper.checkZero(node.qc_minus_qty))
- return true;
- const pPos = this.pos.getLedgerPos(node.id);
- if (!pPos || pPos.length === 0) return false;
- for (const pp of pPos) {
- if (!helper.checkZero(pp.contract_qty) || !helper.checkZero(pp.qc_qty) || !helper.checkZero(pp.qc_minus_qty)) return true;
- }
- }
- }
- /**
- * 生成 0号台账 中间计量数据
- * @param {Object} node - 生成中间计量表的节点
- */
- _generateTzImData(node) {
- if (!this._checkUsed(node)) return;
- const nodeIndex = this.billsTree.getNodeSerialNo(node);
- const peg = this._getPegNode(node);
- const im = {
- id: this.ImData.length + 1,
- lid: node.id, pid: '', code: node.code,
- jl: node.gather_tp, contract_jl: node.contract_tp, qc_jl: node.qc_tp, qc_minus_jl: 0,
- pre_jl: node.pre_gather_tp, pre_contract_jl: node.pre_contract_tp, pre_qc_jl: node.pre_qc_tp,
- end_jl: node.end_gather_tp, end_contract_jl: node.end_contract_tp, end_qc_jl: node.end_qc_tp,
- peg: peg ? this._getPegStr(peg.name) : '', drawing_code: this._getDrawingCode(node),
- dwgc: this._getDwgc(peg, node), fbgc: this._getFbgc(peg, node), fxgc: this._getFxgc(peg, node),
- position: '',
- lIndex: nodeIndex,
- };
- if (this.stage.im_gather && node.check) {
- im.bw = this._getZlGatherBw(node, peg);
- im.xm = '';
- } else {
- im.bw = this._getZlNormalBw(node, peg);
- im.xm = node.name;
- }
- im.check = this.stage.im_gather && node.check;
- this._generateTzGclBillsData(node, im);
- this.ImData.push(im);
- this._generateTzChangeData(node, im);
- }
- _addBwBillsGclBills(im, bills, pos) {
- const helper = this.ctx.helper;
- const tp_decimal = this.ctx.tender.info.decimal.tp;
- if (!im.gclBills) im.gclBills = [];
- let gcl = im.gclBills.find(function (x) {
- return (!bills.b_code || bills.b_code === x.b_code) &&
- (!bills.name || bills.name === x.name) &&
- (!bills.unit || bills.unit === x.unit) &&
- helper.checkZero(helper.sub(bills.unit_price, x.unit_price));
- });
- if (!gcl) {
- gcl = { b_code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.unit_price, org_price: bills.org_price };
- im.gclBills.push(gcl);
- }
- if (pos) {
- gcl.quantity = helper.add(gcl.quantity, pos.quantity);
- gcl.total_price = helper.mul(gcl.unit_price, gcl.quantity, tp_decimal);
- gcl.jl = helper.add(gcl.jl, pos.gather_qty);
- gcl.contract_jl = helper.add(gcl.contract_jl, pos.contract_qty);
- gcl.qc_jl = helper.add(gcl.qc_jl, pos.qc_qty);
- gcl.qc_minus_jl = helper.add(gcl.qc_minus_jl, pos.qc_minus_qty);
- gcl.tp = helper.mul(gcl.unit_price, gcl.jl, tp_decimal);
- gcl.contract_tp = helper.mul(gcl.unit_price, gcl.contract_jl, tp_decimal);
- gcl.qc_tp = helper.mul(gcl.unit_price, gcl.qc_jl, tp_decimal);
- gcl.pre_jl = helper.add(gcl.pre_jl, pos.pre_gather_qty);
- gcl.pre_contract_jl = helper.add(gcl.pre_contract_jl, pos.pre_contract_qty);
- gcl.pre_qc_jl = helper.add(gcl.pre_qc_jl, pos.pre_qc_qty);
- gcl.pre_qc_minus_jl = helper.add(gcl.pre_qc_minus_jl, pos.pre_qc_minus_qty);
- gcl.pre_tp = helper.mul(gcl.unit_price, gcl.pre_jl, tp_decimal);
- gcl.pre_contract_tp = helper.mul(gcl.unit_price, gcl.pre_contract_jl, tp_decimal);
- gcl.pre_qc_tp = helper.mul(gcl.unit_price, gcl.pre_qc_jl, tp_decimal);
- gcl.end_jl = helper.add(gcl.end_jl, pos.end_gather_qty);
- gcl.end_contract_jl = helper.add(gcl.end_contract_jl, pos.end_contract_qty);
- gcl.end_qc_jl = helper.add(gcl.end_qc_jl, pos.end_qc_qty);
- gcl.end_qc_minus_jl = helper.add(gcl.end_qc_minus_jl, pos.end_qc_minus_qty);
- gcl.end_tp = helper.mul(gcl.unit_price, gcl.end_jl, tp_decimal);
- gcl.end_contract_tp = helper.mul(gcl.unit_price, gcl.end_contract_jl, tp_decimal);
- gcl.end_qc_tp = helper.mul(gcl.unit_price, gcl.end_qc_jl, tp_decimal);
- } else {
- gcl.quantity = helper.add(gcl.quantity, bills.quantity);
- gcl.total_price = helper.add(gcl.total_price, bills.total_price);
- gcl.jl = helper.add(gcl.jl, bills.gather_qty);
- gcl.contract_jl = helper.add(gcl.contract_jl, bills.contract_qty);
- gcl.qc_jl = helper.add(gcl.qc_jl, bills.qc_qty);
- gcl.qc_minus_jl = helper.add(gcl.qc_minus_jl, bills.qc_minus_qty);
- gcl.tp = helper.add(gcl.tp, bills.gather_tp);
- gcl.contract_tp = helper.add(gcl.contract_tp, bills.contract_tp);
- gcl.qc_tp = helper.add(gcl.qc_tp, bills.qc_tp);
- gcl.pre_jl = helper.add(gcl.pre_jl, bills.pre_gather_qty);
- gcl.pre_contract_jl = helper.add(gcl.pre_contract_jl, bills.pre_contract_qty);
- gcl.pre_qc_jl = helper.add(gcl.pre_qc_jl, bills.pre_qc_qty);
- gcl.pre_qc_minus_jl = helper.add(gcl.pre_qc_minus_jl, bills.pre_qc_minus_qty);
- gcl.pre_tp = helper.add(gcl.pre_tp, bills.pre_gather_tp);
- gcl.pre_contract_tp = helper.add(gcl.pre_contract_tp, bills.pre_contract_tp);
- gcl.pre_qc_tp = helper.add(gcl.pre_qc_tp, bills.pre_qc_tp);
- gcl.end_jl = helper.add(gcl.end_jl, bills.end_gather_qty);
- gcl.end_contract_jl = helper.add(gcl.end_contract_jl, bills.end_contract_qty);
- gcl.end_qc_jl = helper.add(gcl.end_qc_jl, bills.end_qc_qty);
- gcl.end_qc_minus_jl = helper.add(gcl.end_qc_minus_jl, bills.end_qc_minus_qty);
- gcl.end_tp = helper.add(gcl.end_tp, bills.end_gather_tp);
- gcl.end_contract_tp = helper.add(gcl.end_contract_tp, bills.end_contract_tp);
- gcl.end_qc_tp = helper.add(gcl.end_qc_tp, bills.end_qc_tp);
- }
- }
- _calculateBwBillsIm(im) {
- const helper = this.ctx.helper;
- const tp_decimal = this.ctx.tender.info.decimal.tp;
- im.contract_jl = 0;
- im.qc_jl = 0;
- im.qc_minus_jl = 0;
- for (const b of im.gclBills) {
- im.contract_jl = this.ctx.helper.add(im.contract_jl, this.ctx.helper.mul(b.contract_jl, b.unit_price, tp_decimal));
- im.pre_contract_jl = this.ctx.helper.add(im.pre_contract_jl, this.ctx.helper.mul(b.pre_contract_jl, b.unit_price, tp_decimal));
- im.end_contract_jl = this.ctx.helper.add(im.end_contract_jl, this.ctx.helper.mul(b.end_contract_jl, b.unit_price, tp_decimal));
- im.qc_jl = this.ctx.helper.add(im.qc_jl, this.ctx.helper.mul(b.qc_jl, b.unit_price, tp_decimal));
- im.pre_qc_jl = this.ctx.helper.add(im.pre_qc_jl, this.ctx.helper.mul(b.pre_qc_jl, b.unit_price, tp_decimal));
- im.end_qc_jl = this.ctx.helper.add(im.end_qc_jl, this.ctx.helper.mul(b.end_qc_jl, b.unit_price, tp_decimal));
- const priceDiff = b.org_price ? helper.sub(b.unit_price, b.org_price) : 0;
- if (priceDiff) {
- const contract_pc_tp = helper.sub(helper.mul(b.unit_price, b.pre_contract_jl, tp_decimal), helper.mul(b.org_price, b.pre_contract_jl, tp_decimal));
- const qc_pc_tp = helper.sub(helper.mul(b.unit_price, b.pre_qc_jl, tp_decimal), helper.mul(b.org_price, b.pre_qc_jl, tp_decimal));
- const pc_tp = helper.add(contract_pc_tp, qc_pc_tp);
- im.contract_pc_jl = helper.add(contract_pc_tp, im.contract_pc_jl);
- im.qc_pc_jl = helper.add(qc_pc_tp, im.qc_pc_jl);
- im.pc_jl = helper.add(pc_tp, im.pc_jl);
- im.end_contract_jl = helper.add(contract_pc_tp, im.end_contract_jl);
- im.end_qc_jl = helper.add(qc_pc_tp, im.end_qc_jl);
- }
- }
- im.jl = this.ctx.helper.sum([im.contract_jl, im.qc_jl, im.pc_jl]);
- im.pre_jl = this.ctx.helper.add(im.pre_contract_jl, im.pre_qc_jl);
- im.end_jl = this.ctx.helper.add(im.end_contract_jl, im.end_qc_jl);
- }
- _getBwBillsIm(node, peg, index, bw) {
- const im = {
- lid: node.id, pid: '', code: node.code, name: node.name, pos_name: '',
- peg: peg ? this._getPegStr(peg.name) : '',
- drawing_code: this._getDrawingCode(node),
- position: '',
- lIndex: index,
- bw: bw, jldy: node.name,
- changes: [], gclBills: [],
- dwgc: this._getDwgc(peg, node), fbgc: this._getFbgc(peg, node), fxgc: this._getFxgc(peg, node),
- };
- return im;
- }
- _getBwBillsPosIm(imArr, node, peg, index, bw, posName) {
- let im = imArr.find(function (d) {
- return d.lid === node.id && d.pos_name === posName;
- });
- if (!im) {
- im = {
- lid: node.id, pid: '',
- code: node.code + '-' + (imArr.length + 1), name: node.name, pos_name: posName,
- peg: this._checkPeg(posName) ? posName : (peg ? this._getPegStr(peg.name) : ''),
- drawing_code: [], position: [],
- lIndex: index,
- bw: bw, jldy: posName,
- changes: [], gclBills: [],
- };
- imArr.push(im);
- }
- return im;
- }
- _generateBwBillsImData (node) {
- if (!this._checkUsed(node)) return;
- const nodeIndex = this.billsTree.getNodeSerialNo(node);
- const peg = this._getPegNode(node);
- const nodeImData = [], posterity = this.billsTree.getPosterity(node);
- const bw = this._getBwBillsBw(node);
- const imDefault = this._getBwBillsIm(node, peg, nodeIndex, bw);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) continue;
- if (!p.b_code || p.b_code === '') continue;
- if (!this._checkUsed(p)) continue;
- const pPos = this.pos.getLedgerPos(p.id);
- if (pPos && pPos.length > 0) {
- for (const pp of pPos) {
- if (!pp.gather_qty && !pp.contract_qty && !pp.qc_qty && !pp.qc_minus_qty) continue;
- const im = this._getBwBillsPosIm(nodeImData, node, peg, nodeIndex, bw, pp.name);
- this._addBwBillsGclBills(im, p, pp);
- for (const c of this.changes) {
- if (c.lid === p.id && c.pid == pp.id && c.qty && c.qty !== 0) {
- im.changes.push(c);
- }
- }
- if (pp.drawing_code && im.drawing_code instanceof Array) im.drawing_code.push(pp.drawing_code);
- if (pp.position && im.position instanceof Array) im.position.push(pp.position);
- }
- } else {
- for (const c of this.changes) {
- if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
- imDefault.changes.push(c);
- }
- }
- this.import_changes.forEach(x => { if (x.lid === p.id) imDefault.changes.push(x) });
- imDefault.contract_jl = this.ctx.helper.add(imDefault.contract_jl, p.contract_qty);
- imDefault.qc_jl = this.ctx.helper.add(imDefault.qc_jl, p.qc_qty);
- imDefault.qc_minus_jl = this.ctx.helper.add(imDefault.qc_minus_jl, p.qc_minus_qty);
- imDefault.pre_contract_jl = this.ctx.helper.add(imDefault.pre_contract_jl, p.pre_contract_qty);
- imDefault.pre_qc_jl = this.ctx.helper.add(imDefault.pre_qc_jl, p.pre_qc_qty);
- imDefault.pre_qc_minus_jl = this.ctx.helper.add(imDefault.pre_qc_minus_jl, p.pre_qc_minus_qty);
- imDefault.end_contract_jl = this.ctx.helper.add(imDefault.end_contract_jl, p.end_contract_qty);
- imDefault.end_qc_jl = this.ctx.helper.add(imDefault.end_qc_jl, p.end_qc_qty);
- imDefault.end_qc_minus_jl = this.ctx.helper.add(imDefault.end_qc_minus_jl, p.end_qc_minus_qty);
- imDefault.used = true;
- this._addBwBillsGclBills(imDefault, p);
- }
- }
- if (imDefault.used) {
- imDefault.jl = this.ctx.helper.add(imDefault.contract_jl, imDefault.qc_jl);
- imDefault.pre_jl = this.ctx.helper.add(imDefault.pre_contract_jl, imDefault.pre_qc_jl);
- imDefault.end_jl = this.ctx.helper.add(imDefault.end_contract_jl, imDefault.end_qc_jl);
- imDefault.id = this.ImData.length + 1;
- this.ImData.push(imDefault);
- }
- for (const im of nodeImData) {
- this._calculateBwBillsIm(im);
- im.drawing_code = im.drawing_code instanceof Array
- ? this.ctx.helper._.uniq(im.drawing_code).join(mergeChar) : im.drawing_code;
- im.position = im.position instanceof Array
- ? this.ctx.helper._.uniq(im.position).join(mergeChar): im.position;
- im.id = this.ImData.length + 1;
- this.ImData.push(im);
- }
- }
- _generateZlPosData(node, lx) {
- if (!lx.pos) {
- lx.pos = [];
- }
- const posRange = this.pos.getLedgerPos(node.id);
- if (!posRange) { return; }
- for (const p of posRange) {
- if (!p.contract_qty && !p.qc_qty && !p.qc_minus_qty) { continue; }
- let lp = this._.find(lx.pos, { name: p.name });
- if (!lp) {
- lp = { name: p.name };
- lx.pos.push(lp);
- }
- lp.jl = this.ctx.helper.add(lp.jl, p.gather_qty);
- lp.contract_jl = this.ctx.helper.add(lp.contract_jl, p.contract_qty);
- lp.qc_jl = this.ctx.helper.add(lp.qc_jl, p.qc_qty);
- lp.qc_minus_jl = this.ctx.helper.add(lp.qc_minus_jl, p.qc_minus_qty);
- }
- }
- _generateZlLeafXmjData(node, im) {
- if (!im.leafXmjs) {
- im.leafXmjs = [];
- }
- const leafXmj = this.billsTree.getLeafXmjParent(node);
- if (!leafXmj) { return; }
- let lx = this._.find(im.leafXmjs, { lxid: leafXmj.id });
- if (!lx) {
- lx = {
- lxid: leafXmj.id,
- code: leafXmj.code,
- name: leafXmj.name,
- };
- im.leafXmjs.push(lx);
- }
- lx.jl = this.ctx.helper.add(lx.jl, node.gather_qty);
- lx.contract_jl = this.ctx.helper.add(lx.contract_jl, node.contract_qty);
- lx.qc_jl = this.ctx.helper.add(lx.qc_jl, node.qc_qty);
- lx.qc_minus_jl = this.ctx.helper.add(lx.qc_minus_jl, node.qc_minus_qty);
- this._generateZlPosData(node, lx);
- }
- _generateZlChangeData(node, im) {
- if (!im.changes) {
- im.changes = [];
- }
- const posRange = this.pos.getLedgerPos(node.id);
- if (!posRange) {
- for (const c of this.changes) {
- if (c.lid === node.id && c.pid == -1 && c.qty && c.qty !== 0) {
- im.changes.push(c);
- }
- }
- this.import_changes.forEach(x => { if (x.lid === node.id) im.changes.push(x) });
- } else {
- for (const p of posRange) {
- for (const c of this.changes) {
- if (c.lid === node.id && c.pid === p.id && c.qty && c.qty !== 0) {
- im.changes.push(c);
- }
- }
- }
- }
- }
- /**
- * 生成 总量控制 中间计量数据
- * @param {Object} node - 生成中间计量表的节点
- */
- _generateZlImData(node) {
- const self = this;
- const nodeImData = [], posterity = this.billsTree.getPosterity(node);
- const nodeIndex = this.billsTree.getNodeSerialNo(node);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) { continue; }
- if (!p.b_code || p.b_code === '') { continue; }
- if (!this._checkUsed(p)) { continue; }
- // if (this.ctx.helper.checkZero(p.contract_qty) && this.ctx.helper.checkZero(p.qc_qty)) { continue; }
- let im = nodeImData.find(function(d) {
- return d.lid === node.id &&
- d.code === p.b_code && p.name === d.name && p.unit === d.unit &&
- self.ctx.helper.checkZero(self.ctx.helper.sub(p[self.up_field], d[self.up_field]));
- });
- if (!im) {
- const peg = this._getPegNode(node);
- im = {
- id: this.ImData.length + 1,
- lid: node.id, pid: '', code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, org_unit_price: p.org_unit_price,
- quantity: 0, total_price: 0,
- jl: 0, contract_jl: 0, qc_jl: 0, qc_minus_jl: 0,
- pre_jl: 0, pre_contract_jl: 0, pre_qc_jl: 0, pre_qc_minus_jl: 0,
- end_jl: 0, end_contract_jl: 0, end_qc_jl: 0, end_qc_minus_jl: 0,
- tp: 0, contract_tp: 0, qc_tp: 0,
- pre_tp: 0, pre_contract_tp: 0, pre_qc_tp: 0,
- end_tp: 0, end_contract_tp: 0, end_qc_tp: 0,
- peg: peg ? this._getPegStr(peg.name) : '',
- position: '',
- lIndex: nodeIndex,
- dwgc: this._getDwgc(peg, node), fbgc: this._getFbgc(peg, node), fxgc: this._getFxgc(peg, node),
- };
- if (this.stage.im_gather && node.check) {
- im.check = true;
- im.bw = this._getZlGatherBw(node, peg);
- im.xm = '';
- im.drawing_code = this._getDrawingCode(node);
- } else {
- im.check = false;
- im.bw = this._getZlNormalBw(node, peg);
- im.xm = node.name;
- im.drawing_code = this._getDrawingCode(p);
- }
- nodeImData.push(im);
- this.ImData.push(im);
- }
- // if (!this.stage.im_gather || !node.check) {
- this._generateZlLeafXmjData(p, im, 'gather_qty');
- // }
- this._generateZlChangeData(p, im);
- im.quantity = this.ctx.helper.add(im.quantity, p.quantity);
- im.total_price = this.ctx.helper.add(im.total_price, p.total_price);
- im.jl = this.ctx.helper.add(im.jl, p.gather_qty);
- im.contract_jl = this.ctx.helper.add(im.contract_jl, p.contract_qty);
- im.qc_jl = this.ctx.helper.add(im.qc_jl, p.qc_qty);
- im.qc_minus_jl = this.ctx.helper.add(im.qc_minus_jl, p.qc_minus_qty);
- im.tp = this.ctx.helper.add(im.tp, p.gather_tp);
- im.contract_tp = this.ctx.helper.add(im.contract_tp, p.contract_tp);
- im.qc_tp = this.ctx.helper.add(im.qc_tp, p.qc_tp);
- im.pre_jl = this.ctx.helper.add(im.pre_jl, p.pre_gather_qty);
- im.pre_contract_jl = this.ctx.helper.add(im.pre_contract_jl, p.pre_contract_qty);
- im.pre_qc_jl = this.ctx.helper.add(im.pre_qc_jl, p.pre_qc_qty);
- im.pre_qc_minus_jl = this.ctx.helper.add(im.pre_qc_minus_jl, p.pre_qc_minus_qty);
- im.pre_tp = this.ctx.helper.add(im.pre_tp, p.pre_gather_tp);
- im.pre_contract_tp = this.ctx.helper.add(im.pre_contract_tp, p.pre_contract_tp);
- im.pre_qc_tp = this.ctx.helper.add(im.pre_qc_tp, p.pre_qc_tp);
- im.end_jl = this.ctx.helper.add(im.end_jl, p.end_gather_qty);
- im.end_contract_jl = this.ctx.helper.add(im.end_contract_jl, p.end_contract_qty);
- im.end_qc_jl = this.ctx.helper.add(im.end_qc_jl, p.end_qc_qty);
- im.end_qc_minus_jl = this.ctx.helper.add(im.end_qc_minus_jl, p.end_qc_minus_qty);
- im.end_tp = this.ctx.helper.add(im.end_tp, p.end_gather_tp);
- im.end_contract_tp = this.ctx.helper.add(im.end_contract_tp, p.end_contract_tp);
- im.end_qc_tp = this.ctx.helper.add(im.end_qc_tp, p.end_qc_tp);
- }
- }
- _generateBwImData(node) {
- const tp_decimal = this.ctx.tender.info.decimal.tp;
- const posterity = this.billsTree.getPosterity(node);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) { continue; }
- if (!p.b_code || p.b_code === '') { continue; }
- const peg = this._getPegNode(node);
- const pPos = this.pos.getLedgerPos(p.id);
- const bw = this._getZlNormalBw(node, peg);
- if (pPos && pPos.length > 0) {
- const nodeIndex = this.billsTree.getNodeSerialNo(node);
- for (const pp of pPos) {
- if (this.ctx.helper.checkZero(pp.contract_qty) && this.ctx.helper.checkZero(pp.qc_qty) && this.ctx.helper.checkZero(pp.qc_minus_qty)) { continue; }
- const im = {
- id: this.ImData.length + 1,
- lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, org_unit_price: p.org_unit_price, pid: pp.id,
- quantity: pp.quantity,
- jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty, qc_minus_jl: pp.qc_minus_qty,
- pre_jl: pp.pre_gather_qty, pre_contract_jl: pp.pre_contract_qty, pre_qc_jl: pp.pre_qc_qty, pre_qc_minus_jl: pp.pre_qc_minus_qty,
- end_jl: pp.end_gather_qty, end_contract_jl: pp.end_contract_qty, end_qc_jl: pp.end_qc_qty, end_qc_minus_jl: pp.end_qc_minus_qty,
- bw,
- peg: this._checkPeg(pp.name) ? this._getPegStr(pp.name) : (peg ? this._getPegStr(peg.name) : ''),
- dwgc: this._getDwgc(peg, node), fbgc: this._getFbgc(peg, node), fxgc: this._getFxgc(peg, node),
- xm: pp.name, jldy: pp.name,
- drawing_code: pp.drawing_code,
- changes: [],
- position: pp.position,
- lIndex: nodeIndex * 1000 + pp.porder,
- };
- im.total_price = this.ctx.helper.mul(im.quantity, im.unit_price, tp_decimal);
- im.tp = this.ctx.helper.mul(im.jl, im.unit_price, tp_decimal);
- im.contract_tp = this.ctx.helper.mul(im.contract_jl, im.unit_price, tp_decimal);
- im.qc_tp = this.ctx.helper.mul(im.qc_jl, im.unit_price, tp_decimal);
- im.pre_tp = this.ctx.helper.mul(im.pre_jl, im.unit_price, tp_decimal);
- im.pre_contract_tp = this.ctx.helper.mul(im.pre_contract_jl, im.unit_price, tp_decimal);
- im.pre_qc_tp = this.ctx.helper.mul(im.pre_qc_jl, im.unit_price, tp_decimal);
- im.end_tp = this.ctx.helper.mul(im.end_jl, im.unit_price, tp_decimal);
- im.end_contract_tp = this.ctx.helper.mul(im.end_contract_jl, im.unit_price, tp_decimal);
- im.end_qc_tp = this.ctx.helper.mul(im.end_qc_jl, im.unit_price, tp_decimal);
- im.calc_memo = '本期计量:' + (this.ctx.helper.checkZero(im.jl) ? 0 : im.jl) + (im.qc_minus_jl ? (` (不计价 ${im.qc_minus_jl}) `) : ' ') + im.unit;
- this.ImData.push(im);
- for (const c of this.changes) {
- if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
- im.changes.push(c);
- }
- }
- }
- } else {
- if (this.ctx.helper.checkZero(p.gather_qty) && this.ctx.helper.checkZero(p.gather_tp) && this.ctx.helper.checkZero(p.qc_minus_qty)) { continue; }
- const im = {
- id: this.ImData.length + 1,
- lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, org_unit_price: p.org_unit_price, pid: '',
- quantity: p.quantity, total_price: p.total_price,
- jl: p.gather_qty, contract_jl: p.contract_qty, qc_jl: p.qc_qty, qc_minus_jl: p.qc_minus_qty,
- pre_jl: p.pre_gather_qty, pre_contract_jl: p.pre_contract_qty, pre_qc_jl: p.pre_qc_qty, pre_qc_minus_jl: p.pre_qc_minus_qty,
- end_jl: p.end_gather_qty, end_contract_jl: p.end_contract_qty, end_qc_jl: p.end_qc_qty, end_qc_minus_jl: p.end_qc_minus_qty,
- tp: p.gather_tp, contract_tp: p.contract_tp, qc_tp: p.qc_tp,
- pre_tp: p.pre_gather_tp, pre_contract_tp: p.pre_contract_tp, pre_qc_tp: p.pre_qc_tp,
- end_tp: p.end_gather_tp, end_contract_tp: p.end_contract_tp, end_qc_tp: p.end_qc_tp,
- bw,
- peg: peg ? this._getPegStr(peg.name) : '',
- dwgc: this._getDwgc(peg, node), fbgc: this._getFbgc(peg, node), fxgc: this._getFxgc(peg, node),
- xm: node.name,
- drawing_code: this._getDrawingCode(p),
- changes: [],
- position: '',
- lIndex: this.billsTree.getNodeSerialNo(node),
- };
- im.calc_memo = '本期计量:' + (this.ctx.helper.checkZero(im.jl) ? 0 : im.jl) + (im.qc_minus_jl ? (` (不计价 ${im.qc_minus_jl}) `) : ' ') + im.unit;
- this.ImData.push(im);
- for (const c of this.changes) {
- if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
- im.changes.push(c);
- }
- }
- this.import_changes.forEach(x => { if (x.lid === p.id) im.changes.push(x) });
- }
- }
- }
- /**
- * 递归 生成中间计量表
- * @param {Array} nodes
- */
- _recursiveBuildImData(nodes) {
- if (!nodes || nodes.length === 0) { return; }
- for (const node of nodes) {
- if (this.billsTree.isLeafXmj(node) ||
- ((this.stage.im_type !== imType.bw.value && this.stage.im_type !== imType.bb.value) && this.stage.im_gather && node.check)
- ) {
- if (this.stage.im_type === imType.tz.value) {
- this._generateTzImData(node);
- } else if (this.stage.im_type === imType.zl.value) {
- this._generateZlImData(node);
- } else if (this.stage.im_type === imType.bw.value) {
- this._generateBwImData(node);
- } else if (this.stage.im_type === imType.bb.value) {
- this._generateBwBillsImData(node);
- }
- } else {
- this._recursiveBuildImData(node.children);
- }
- }
- }
- // 生成中间计量数据
- async buildImData() {
- this.up_field = 'unit_price';
- const self = this;
- this.stage = this.ctx.stage;
- // 初始化
- await this._loadMainData();
- await this._loadRelaData();
- if (this.stage.im_gather) {
- this._checkGather();
- }
- // 生成数据
- this._recursiveBuildImData(this.billsTree.children);
- // 排序
- if (this.stage.im_type !== imType.tz.value) {
- this.ImData.sort(function(x, y) {
- const iCode = self.ctx.helper.compareCode(x.code, y.code);
- return iCode === 0 ? x.lIndex - y.lIndex : iCode;
- });
- }
- // 生成数据(需要缓存,并清理缓存)
- const pre = (this.stage.im_pre && this.stage.im_pre !== '') ? this.stage.im_pre + this.splitChar : '';
- for (const [i, im] of this.ImData.entries()) {
- im.im_code = pre + this._getNumberFormat(this.stage.order, 2) + this.splitChar + this._getNumberFormat(i + this.stage.im_start_num, 3);
- if (im.gclBills) {
- for (const b of im.gclBills) {
- b.im_code = im.im_code;
- }
- }
- this._getCalcMemo(im);
- this._checkCustomDetail(im);
- delete im.leafXmjs;
- delete im.gclBills;
- this._getChangeInfo(im);
- delete im.changes;
- }
- }
- buildRelaStageIm(stage, billsTree, pos, details, changes) {
- this.up_field = 'org_unit_price';
- this.billsTree = billsTree;
- this.pos = pos;
- this.stage = stage;
- this.details = details;
- this.changes = changes;
- this.import_changes = [];
- const self = this;
- // 初始化
- if (stage.im_gather) this._checkGather();
- // 生成数据
- this._recursiveBuildImData(this.billsTree.children);
- // 排序
- if (this.stage.im_type !== imType.tz.value) {
- this.ImData.sort(function(x, y) {
- const iCode = self.ctx.helper.compareCode(x.code, y.code);
- return iCode === 0 ? x.lIndex - y.lIndex : iCode;
- });
- }
- // 生成数据(需要缓存,并清理缓存)
- const pre = (this.stage.im_pre && this.stage.im_pre !== '') ? this.stage.im_pre + this.splitChar : '';
- for (const [i, im] of this.ImData.entries()) {
- im.im_code = pre + this._getNumberFormat(this.stage.order, 2) + this.splitChar + this._getNumberFormat(i + this.stage.im_start_num, 3);
- if (im.gclBills) {
- for (const b of im.gclBills) {
- b.im_code = im.im_code;
- }
- }
- this._getCalcMemo(im);
- this._checkCustomDetail(im);
- delete im.leafXmjs;
- delete im.gclBills;
- this._getChangeInfo(im);
- delete im.changes;
- }
- }
- }
- module.exports = StageIm;
|