|
@@ -231,14 +231,8 @@ module.exports = app => {
|
|
|
*/
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
- this.resultTree = new Ledger.gatherTree(ctx, {
|
|
|
- id: 'id',
|
|
|
- pid: 'pid',
|
|
|
- order: 'order',
|
|
|
- level: 'level',
|
|
|
- rootId: -1
|
|
|
- });
|
|
|
- this.resultPos = new Ledger.pos({ id: 'id', ledgerId: 'lid' });
|
|
|
+ this.resultTree = null;
|
|
|
+ this.resultPos = null;
|
|
|
this.resultTenderInfo = [];
|
|
|
this.resultDealPay = [];
|
|
|
this.resultDealBills = [];
|
|
@@ -313,63 +307,9 @@ module.exports = app => {
|
|
|
/**
|
|
|
* 台账数据
|
|
|
*/
|
|
|
- async _gatherStageData(completeData, tender, stage, hasPre) {
|
|
|
- const helper = this.ctx.helper;
|
|
|
- completeData.id = tender.id;
|
|
|
- completeData.name = tender.name;
|
|
|
- const 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', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
|
|
|
- calc: function (node) {
|
|
|
- if (node.children && node.children.length === 0) {
|
|
|
- node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
|
|
|
- node.gather_qty = helper.add(node.contract_qty, node.qc_qty);
|
|
|
- node.end_contract_qty = helper.add(node.pre_contract_qty, node.contract_qty);
|
|
|
- node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty);
|
|
|
- node.end_gather_qty = helper.add(node.pre_gather_qty, node.gather_qty);
|
|
|
- }
|
|
|
- node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
|
|
|
- node.gather_tp = helper.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
|
|
|
- node.end_contract_tp = helper.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
|
|
|
- node.end_qc_tp = helper.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
|
|
|
- node.end_gather_tp = helper.add(node.pre_gather_tp, node.gather_tp);
|
|
|
- }
|
|
|
- });
|
|
|
- const billsData = await this.ctx.service.ledger.getData(tender.id);
|
|
|
-
|
|
|
- const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(tender.id);
|
|
|
- for (const d of dgnData) {
|
|
|
- const l = this.ctx.helper._.find(billsData, {id: d.id});
|
|
|
- this.ctx.helper._.assignIn(l, d);
|
|
|
- }
|
|
|
-
|
|
|
- if (stage) {
|
|
|
- await this.ctx.service.stage.doCheckStage(stage);
|
|
|
- const curStage = stage.readOnly
|
|
|
- ? await this.ctx.service.stageBills.getAuditorStageData2(tender.id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
- : await this.ctx.service.stageBills.getLastestStageData2(tender.id, stage.id);
|
|
|
- const preStage = hasPre && stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(tender, stage.order - 1) : [];
|
|
|
- const bpcStage = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
- this.ctx.helper.assignRelaData(billsData, [
|
|
|
- { data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid' },
|
|
|
- { data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid' },
|
|
|
- { data: bpcStage, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp'], prefix: '', relaId: 'lid' },
|
|
|
- ]);
|
|
|
- }
|
|
|
- billsTree.loadDatas(billsData);
|
|
|
- billsTree.calculateAll();
|
|
|
- this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
|
|
|
- gatherUtils.gatherStage(tender, gatherNode, sourceNode, completeData.prefix, helper);
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
async _gatherStagesData(completeData, tender, stages) {
|
|
|
+ const resultPos = this.resultPos;
|
|
|
const helper = this.ctx.helper;
|
|
|
completeData.id = tender.id;
|
|
|
completeData.name = tender.name;
|
|
@@ -413,17 +353,21 @@ module.exports = app => {
|
|
|
}
|
|
|
});
|
|
|
const billsData = await this.ctx.service.ledger.getData(tender.id);
|
|
|
-
|
|
|
const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(tender.id);
|
|
|
for (const d of dgnData) {
|
|
|
const l = this.ctx.helper._.find(billsData, {id: d.id});
|
|
|
this.ctx.helper._.assignIn(l, d);
|
|
|
}
|
|
|
-
|
|
|
+ const pos = new Ledger.pos(this.ctx, { id: 'id', ledgerId: 'lid' });
|
|
|
+ const posData = await this.ctx.service.pos.getAllDataByCondition({ where: { tid: tender.id} });
|
|
|
let billsIndexData = {};
|
|
|
for (const bd of billsData) {
|
|
|
billsIndexData[indexPre + bd.id] = bd;
|
|
|
}
|
|
|
+ let posIndexData = {};
|
|
|
+ for (const p of posData) {
|
|
|
+ posIndexData[indexPre + p.id] = p;
|
|
|
+ }
|
|
|
|
|
|
for (const stage of stages) {
|
|
|
await this.ctx.service.stage.doCheckStage(stage);
|
|
@@ -435,49 +379,130 @@ module.exports = app => {
|
|
|
{data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'},
|
|
|
{ data: bpcStage, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp'], prefix: '', relaId: 'lid' },
|
|
|
]);
|
|
|
+ const curStagePos = stage.readOnly
|
|
|
+ ? await this.ctx.service.stagePos.getAuditorStageData2(tender.id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
+ : await this.ctx.service.stagePos.getLastestStageData2(tender.id, stage.id);
|
|
|
+ sumAssignRelaData(posIndexData, [
|
|
|
+ {data: curStagePos, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'},
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
billsTree.loadDatas(billsData);
|
|
|
billsTree.calculateAll();
|
|
|
+ pos.LoadDatas(posData);
|
|
|
this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
|
|
|
gatherUtils.gatherZone(tender, gatherNode, sourceNode, completeData.prefix, helper);
|
|
|
+ }, function (gatherNode, sourceNode) {
|
|
|
+ const posRange = pos.getLedgerPos(sourceNode.id);
|
|
|
+ if (!posRange || posRange.length === 0) return;
|
|
|
+ resultPos.loadGatherPos(gatherNode.id, posRange, (gatherPos, sourcePos) => {
|
|
|
+ gatherUtils.gatherZonePos(gatherPos, sourcePos, completeData.prefix, helper);
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
+ async _gatherZoneData(tender, completeData, zone) {
|
|
|
+ const stages = await this._getTimeZoneStages(tender, zone);
|
|
|
+ await this._gatherStagesData(completeData, tender, stages);
|
|
|
+ }
|
|
|
|
|
|
+ async _gatherStageData(completeData, tender, stage, hasPre) {
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ const resultPos = this.resultPos;
|
|
|
+ completeData.id = tender.id;
|
|
|
+ completeData.name = tender.name;
|
|
|
+
|
|
|
+ const 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', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
|
|
|
+ calc: function (node) {
|
|
|
+ if (node.children && node.children.length === 0) {
|
|
|
+ node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
|
|
|
+ node.gather_qty = helper.add(node.contract_qty, node.qc_qty);
|
|
|
+ node.end_contract_qty = helper.add(node.pre_contract_qty, node.contract_qty);
|
|
|
+ node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty);
|
|
|
+ node.end_gather_qty = helper.add(node.pre_gather_qty, node.gather_qty);
|
|
|
+ }
|
|
|
+ node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
|
|
|
+ node.gather_tp = helper.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
|
|
|
+ node.end_contract_tp = helper.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
|
|
|
+ node.end_qc_tp = helper.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
|
|
|
+ node.end_gather_tp = helper.add(node.pre_gather_tp, node.gather_tp);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const billsData = await this.ctx.service.ledger.getData(tender.id);
|
|
|
+ const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(tender.id);
|
|
|
+ for (const d of dgnData) {
|
|
|
+ const l = this.ctx.helper._.find(billsData, {id: d.id});
|
|
|
+ this.ctx.helper._.assignIn(l, d);
|
|
|
+ }
|
|
|
+ const pos = new Ledger.pos(this.ctx, { id: 'id', ledgerId: 'lid' });
|
|
|
+ const posData = await this.ctx.service.pos.getAllDataByCondition({ where: { tid: tender.id } });
|
|
|
+ if (stage) {
|
|
|
+ await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ const curStage = stage.readOnly
|
|
|
+ ? await this.ctx.service.stageBills.getAuditorStageData2(tender.id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
+ : await this.ctx.service.stageBills.getLastestStageData2(tender.id, stage.id);
|
|
|
+ const preStage = hasPre && stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(tender, stage.order - 1) : [];
|
|
|
+ const bpcStage = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ { data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid' },
|
|
|
+ { data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid' },
|
|
|
+ { data: bpcStage, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp'], prefix: '', relaId: 'lid' },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ const curStagePos = stage.readOnly
|
|
|
+ ? await this.ctx.service.stagePos.getAuditorStageData2(tender.id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
+ : await this.ctx.service.stagePos.getLastestStageData2(tender.id, stage.id);
|
|
|
+ const preStagePos = hasPre && stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(tender, stage.order - 1) : [];
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ { data: curStagePos, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid' },
|
|
|
+ { data: preStagePos, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid' },
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ billsTree.loadDatas(billsData);
|
|
|
+ billsTree.calculateAll();
|
|
|
+ pos.loadDatas(posData);
|
|
|
+
|
|
|
+ this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
|
|
|
+ gatherUtils.gatherStage(tender, gatherNode, sourceNode, completeData.prefix, helper);
|
|
|
+ }, function (gatherNode, sourceNode) {
|
|
|
+ const posRange = pos.getLedgerPos(sourceNode.id);
|
|
|
+ if (!posRange || posRange.length === 0) return;
|
|
|
+ resultPos.loadGatherPos(gatherNode.id, posRange, (gatherPos, sourcePos) => {
|
|
|
+ gatherUtils.gatherStagePos(gatherPos, sourcePos, completeData.prefix, helper);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
async _gatherMonthData(tender, completeData, month, hasPre) {
|
|
|
const stages = await this._getValidStages(tender.id);
|
|
|
const stage = this.ctx.helper._.find(stages, {s_time: month});
|
|
|
await this._gatherStageData(completeData, tender, stage, hasPre);
|
|
|
}
|
|
|
-
|
|
|
async _gatherIndexData(tender, completeData, index, hasPre) {
|
|
|
const stages = await this._getValidStages(tender.id);
|
|
|
const stage = this.ctx.helper._.find(stages, {order: index});
|
|
|
await this._gatherStageData(completeData, tender, stage, hasPre);
|
|
|
}
|
|
|
-
|
|
|
- async _gatherZoneData(tender, completeData, zone) {
|
|
|
- const stages = await this._getTimeZoneStages(tender, zone);
|
|
|
- await this._gatherStagesData(completeData, tender, stages);
|
|
|
- }
|
|
|
-
|
|
|
async _gatherIndexZoneData(tender, completeData, stageZone) {
|
|
|
const stages = await this._getOrderZoneStages(tender, stageZone);
|
|
|
await this._gatherStagesData(completeData, tender, stages);
|
|
|
}
|
|
|
-
|
|
|
async _gatherFinalData(tender, completeData, hasPre) {
|
|
|
const stages = await this._getValidStages(tender.id);
|
|
|
await this._gatherStageData(completeData, tender, stages[0], hasPre);
|
|
|
}
|
|
|
-
|
|
|
async _gatherCheckedFinalData(tender, completeData, hasPre) {
|
|
|
const stages = await this._getCheckedStages(tender.id);
|
|
|
await this._gatherStageData(completeData, tender, stages[0], hasPre);
|
|
|
}
|
|
|
|
|
|
- async _gatherLedgerData(tender, completeData) {
|
|
|
- const helper = this.ctx.helper;
|
|
|
+ async _loadGatherLedger(tender) {
|
|
|
const billsTree = new Ledger.billsTree(this.ctx, {
|
|
|
id: 'ledger_id',
|
|
|
pid: 'ledger_pid',
|
|
@@ -491,36 +516,58 @@ module.exports = app => {
|
|
|
const billsData = await this.ctx.service.ledger.getData(tender.id);
|
|
|
billsTree.loadDatas(billsData);
|
|
|
billsTree.calculateAll();
|
|
|
+ return billsTree;
|
|
|
+ }
|
|
|
+ async _loadGatherPos(tender) {
|
|
|
+ const pos = new Ledger.pos({ id: 'id', ledgerId: 'lid' });
|
|
|
+ const posData = await this.ctx.service.pos.getAllDataByCondition({ where: { tid: tender.id } });
|
|
|
+ pos.loadDatas(posData);
|
|
|
+ return pos;
|
|
|
+ }
|
|
|
+ async _gatherLedgerData(tender, completeData) {
|
|
|
+ const resultPos = this.resultPos;
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ const billsTree = await this._loadGatherLedger(tender);
|
|
|
+ const pos = await this._loadGatherPos(tender);
|
|
|
this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
|
|
|
gatherUtils.gatherLedger(tender, gatherNode, sourceNode, completeData.prefix, helper);
|
|
|
+ }, function (gatherNode, sourceNode) {
|
|
|
+ const posRange = pos.getLedgerPos(sourceNode.id);
|
|
|
+ if (!posRange || posRange.length === 0) return;
|
|
|
+ resultPos.loadGatherPos(posRange, (gatherPos, sourcePos) => {
|
|
|
+ gatherUtils.gatherPos(gatherPos, sourcePos, completeData.prefix, helper);
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
async _gatherSpecialData(tender, sKey) {
|
|
|
+ const resultPos = this.resultPos;
|
|
|
const helper = this.ctx.helper;
|
|
|
- const 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'],
|
|
|
- });
|
|
|
- const billsData = await this.ctx.service.ledger.getData(tender.id);
|
|
|
- billsTree.loadDatas(billsData);
|
|
|
- billsTree.calculateAll();
|
|
|
+ const billsTree = await this._loadGatherLedger(tender);
|
|
|
+ const pos = await this._loadGatherPos(tender);
|
|
|
this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) {
|
|
|
gatherUtils.gatherSpecial(gatherNode, sourceNode, 'ts_' + sKey + '_', helper);
|
|
|
+ }, function (gatherNode, sourceNode) {
|
|
|
+ const posRange = pos.getLedgerPos(sourceNode.id);
|
|
|
+ if (!posRange || posRange.length === 0) return;
|
|
|
+ resultPos.loadGatherPos(posRange, (gatherPos, sourcePos) => {
|
|
|
+ gatherUtils.gatherPos(gatherPos, sourcePos, 'ts_' + sKey + '_', helper);
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- async getGatherStageBills(memFieldKeys, gsDefine, gsCustom) {
|
|
|
- if (!gsDefine || !gsDefine.enable) return [];
|
|
|
- if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
|
|
|
+ async _doGatherStageData(memFieldKeys, gsDefine, gsCustom) {
|
|
|
+ if (!gsDefine || !gsDefine.enable) return;
|
|
|
+ if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return;
|
|
|
+
|
|
|
+ this.resultTree = new Ledger.gatherTree(this.ctx, {
|
|
|
+ id: 'id',
|
|
|
+ pid: 'pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1
|
|
|
+ });
|
|
|
+ this.resultPos = new Ledger.gatherPos(this.ctx, { id: 'id', ledgerId: 'lid' });
|
|
|
|
|
|
- this.resultTree.clear();
|
|
|
const gsSetting = JSON.parse(gsDefine.setting);
|
|
|
let commonIndex = 0;
|
|
|
const completeDatas = [];
|
|
@@ -563,7 +610,15 @@ module.exports = app => {
|
|
|
|
|
|
this.resultTree.resortChildrenDefault();
|
|
|
gatherUtils.completeGatherData(this.resultTree.nodes, completeDatas);
|
|
|
- return this.resultTree.getDefaultDatas();
|
|
|
+ }
|
|
|
+
|
|
|
+ async getGatherStageBills(memFieldKeys, gsDefine, gsCustom) {
|
|
|
+ await this._doGatherStageData(memFieldKeys, gsDefine, gsCustom);
|
|
|
+ return this.resultTree ? this.resultTree.getDefaultDatas() : [];
|
|
|
+ }
|
|
|
+ async getGatherStagePos(memFieldKeys, gsDefine, gsCustom) {
|
|
|
+ await this._doGatherStageData(memFieldKeys, gsDefine, gsCustom);
|
|
|
+ return this.resultPos ? this.resultPos.getDatas() : [];
|
|
|
}
|
|
|
|
|
|
/**
|