|
@@ -19,6 +19,8 @@ const stageImTzBills = 'mem_stage_im_tz_bills';
|
|
|
const stageImZl = 'mem_stage_im_zl';
|
|
|
const stageImVersion = '1.0';
|
|
|
|
|
|
+const Ledger = require('../lib/ledger');
|
|
|
+
|
|
|
module.exports = app => {
|
|
|
class ReportMemory extends app.BaseService {
|
|
|
|
|
@@ -30,7 +32,45 @@ module.exports = app => {
|
|
|
*/
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
+ const self = this;
|
|
|
this.tableName = 'report_memory';
|
|
|
+ // 基础数据类
|
|
|
+ // 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', 'gather_tp'],
|
|
|
+ calc: function (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_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.add(node.contract_tp, node.qc_tp);
|
|
|
+ node.end_contract_tp = self.ctx.helper.add(node.pre_contract_tp, node.contract_tp);
|
|
|
+ node.end_qc_tp = self.ctx.helper.add(node.pre_qc_tp, node.qc_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', 'postil'],
|
|
|
+ calc: function (p) {
|
|
|
+ p.pre_gather_qty = ctx.helper.add(p.pre_contract_qty, p.pre_qc_qty);
|
|
|
+ p.gather_qty = 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_gather_qty = self.ctx.helper.add(p.pre_gather_qty, p.gather_qty);
|
|
|
+ }
|
|
|
+ });
|
|
|
// 需要缓存的数据
|
|
|
this.stageImData = null;
|
|
|
}
|
|
@@ -236,6 +276,72 @@ module.exports = app => {
|
|
|
}
|
|
|
return monthProgress;
|
|
|
}
|
|
|
+
|
|
|
+ async getStageBillsData(tid, sid, fields) {
|
|
|
+ await this.ctx.service.tender.checkTender(tid);
|
|
|
+ await this.ctx.service.stage.checkStage(sid);
|
|
|
+
|
|
|
+
|
|
|
+ const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
|
|
|
+ if (this.ctx.stage.readOnly) {
|
|
|
+ const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
|
|
|
+ this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
|
|
|
+
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
|
|
|
+ ]);
|
|
|
+ this.billsTree.loadDatas(billsData);
|
|
|
+ this.billsTree.calculateAll();
|
|
|
+
|
|
|
+ return this.billsTree.getDatas([
|
|
|
+ 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
|
|
|
+ 'code', 'b_code', 'name', 'unit', 'unit_price',
|
|
|
+ 'deal_qty', 'deal_tp',
|
|
|
+ 'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
|
|
|
+ 'dgn_qty1', 'dgn_qty2',
|
|
|
+ 'drawing_code', 'memo', 'node_type', 'is_tp',
|
|
|
+ 'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil',
|
|
|
+ 'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp',
|
|
|
+ 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getStagePosData(tid, sid, fields) {
|
|
|
+ await this.ctx.service.tender.checkTender(tid);
|
|
|
+ await this.ctx.service.stage.checkStage(sid);
|
|
|
+
|
|
|
+ const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
|
|
|
+ if (this.ctx.stage.readOnly) {
|
|
|
+ const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
|
|
|
+ this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
|
|
|
+ this.ctx.helper.assignRelaData(posData, [
|
|
|
+ {data: curPosStage, fields: ['contract_qty', 'qc_qty'], prefix: '', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ 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: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ this.pos.loadDatas(posData);
|
|
|
+ this.pos.calculateAll();
|
|
|
+
|
|
|
+ return this.pos.getDatas();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ReportMemory;
|