|
@@ -0,0 +1,254 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+const Ledger = require('../lib/ledger');
|
|
|
+const PayCalculator = require('../lib/pay_calc');
|
|
|
+
|
|
|
+const auditConst = require('../const/audit');
|
|
|
+const payConst = require('../const/deal_pay');
|
|
|
+
|
|
|
+const moment = require('moment');
|
|
|
+
|
|
|
+const indexPre = 'id_';
|
|
|
+
|
|
|
+
|
|
|
+const gatherUtils = {
|
|
|
+ completeStageSumData: function (datas, completeDatas) {
|
|
|
+ for (const data of datas) {
|
|
|
+ for (const cd of completeDatas) {
|
|
|
+ data[cd.prefix + 'order'] = cd.order;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ gatherStage: function (tender, gatherNode, sourceNode, prefix, helper) {
|
|
|
+ gatherNode[prefix + 'id'] = tender.id;
|
|
|
+ gatherNode[prefix + 'name'] = tender.name;
|
|
|
+
|
|
|
+ gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
|
|
|
+ gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
|
|
|
+
|
|
|
+ gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
|
|
|
+ gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
|
|
|
+
|
|
|
+ gatherNode[prefix + "contract_qty"] = helper.add(gatherNode[prefix + "contract_qty"], sourceNode.contract_qty);
|
|
|
+ gatherNode[prefix + "contract_tp"] = helper.add(gatherNode[prefix + "contract_tp"], sourceNode.contract_tp);
|
|
|
+ gatherNode[prefix + "qc_qty"] = helper.add(gatherNode[prefix + "qc_qty"], sourceNode.qc_qty);
|
|
|
+ gatherNode[prefix + "qc_tp"] = helper.add(gatherNode[prefix + "qc_tp"], sourceNode.qc_tp);
|
|
|
+ gatherNode[prefix + "gather_qty"] = helper.add(gatherNode[prefix + "gather_qty"], sourceNode.gather_qty);
|
|
|
+ gatherNode[prefix + "gather_tp"] = helper.add(gatherNode[prefix + "gather_tp"], sourceNode.gather_tp);
|
|
|
+
|
|
|
+ gatherNode[prefix + "pre_contract_qty"] = helper.add(gatherNode[prefix + "pre_contract_qty"], sourceNode.pre_contract_qty);
|
|
|
+ gatherNode[prefix + "pre_contract_tp"] = helper.add(gatherNode[prefix + "pre_contract_tp"], sourceNode.pre_contract_tp);
|
|
|
+ gatherNode[prefix + "pre_qc_qty"] = helper.add(gatherNode[prefix + "pre_qc_qty"], sourceNode.pre_qc_qty);
|
|
|
+ gatherNode[prefix + "pre_qc_tp"] = helper.add(gatherNode[prefix + "pre_qc_tp"], sourceNode.pre_qc_tp);
|
|
|
+ gatherNode[prefix + "pre_gather_qty"] = helper.add(gatherNode[prefix + "pre_gather_qty"], sourceNode.pre_gather_qty);
|
|
|
+ gatherNode[prefix + "pre_gather_tp"] = helper.add(gatherNode[prefix + "pre_gather_tp"], sourceNode.pre_gather_tp);
|
|
|
+
|
|
|
+ gatherNode[prefix + "end_contract_qty"] = helper.add(gatherNode[prefix + "end_contract_qty"], sourceNode.end_contract_qty);
|
|
|
+ gatherNode[prefix + "end_contract_tp"] = helper.add(gatherNode[prefix + "end_contract_tp"], sourceNode.end_contract_tp);
|
|
|
+ gatherNode[prefix + "end_qc_qty"] = helper.add(gatherNode[prefix + "end_qc_qty"], sourceNode.end_qc_qty);
|
|
|
+ gatherNode[prefix + "end_qc_tp"] = helper.add(gatherNode[prefix + "end_qc_tp"], sourceNode.end_qc_tp);
|
|
|
+ gatherNode[prefix + "end_gather_qty"] = helper.add(gatherNode[prefix + "end_gather_qty"], sourceNode.end_gather_qty);
|
|
|
+ gatherNode[prefix + "end_gather_tp"] = helper.add(gatherNode[prefix + "end_gather_tp"], sourceNode.end_gather_tp);
|
|
|
+
|
|
|
+ gatherNode[prefix + "deal_dgn_qty1"] = helper.add(gatherNode[prefix + "deal_dgn_qty1"], sourceNode.deal_dgn_qty1);
|
|
|
+ gatherNode[prefix + "deal_dgn_qty2"] = helper.add(gatherNode[prefix + "deal_dgn_qty2"], sourceNode.deal_dgn_qty2);
|
|
|
+ gatherNode[prefix + "c_dgn_qty1"] = helper.add(gatherNode[prefix + "c_dgn_qty1"], sourceNode.c_dgn_qty1);
|
|
|
+ gatherNode[prefix + "c_dgn_qty2"] = helper.add(gatherNode[prefix + "c_dgn_qty2"], sourceNode.c_dgn_qty2);
|
|
|
+
|
|
|
+ gatherNode['s_' + "qty"] = helper.add(gatherNode['s_' + "qty"], sourceNode.quantity);
|
|
|
+ gatherNode['s_' + "tp"] = helper.add(gatherNode['s_' + "tp"], sourceNode.total_price);
|
|
|
+
|
|
|
+ gatherNode['s_' + "contract_qty"] = helper.add(gatherNode['s_' + "contract_qty"], sourceNode.contract_qty);
|
|
|
+ gatherNode['s_' + "contract_tp"] = helper.add(gatherNode['s_' + "contract_tp"], sourceNode.contract_tp);
|
|
|
+ gatherNode['s_' + "qc_qty"] = helper.add(gatherNode['s_' + "qc_qty"], sourceNode.qc_qty);
|
|
|
+ gatherNode['s_' + "qc_tp"] = helper.add(gatherNode['s_' + "qc_tp"], sourceNode.qc_tp);
|
|
|
+ gatherNode['s_' + "gather_qty"] = helper.add(gatherNode['s_' + "gather_qty"], sourceNode.gather_qty);
|
|
|
+ gatherNode['s_' + "gather_tp"] = helper.add(gatherNode['s_' + "gather_tp"], sourceNode.gather_tp);
|
|
|
+
|
|
|
+ gatherNode['s_' + "pre_contract_qty"] = helper.add(gatherNode['s_' + "pre_contract_qty"], sourceNode.pre_contract_qty);
|
|
|
+ gatherNode['s_' + "pre_contract_tp"] = helper.add(gatherNode['s_' + "pre_contract_tp"], sourceNode.pre_contract_tp);
|
|
|
+ gatherNode['s_' + "pre_qc_qty"] = helper.add(gatherNode['s_' + "pre_qc_qty"], sourceNode.pre_qc_qty);
|
|
|
+ gatherNode['s_' + "pre_qc_tp"] = helper.add(gatherNode['s_' + "pre_qc_tp"], sourceNode.pre_qc_tp);
|
|
|
+ gatherNode['s_' + "pre_gather_qty"] = helper.add(gatherNode['s_' + "pre_gather_qty"], sourceNode.pre_gather_qty);
|
|
|
+ gatherNode['s_' + "pre_gather_tp"] = helper.add(gatherNode['s_' + "pre_gather_tp"], sourceNode.pre_gather_tp);
|
|
|
+
|
|
|
+ gatherNode['s_' + "end_contract_qty"] = helper.add(gatherNode['s_' + "end_contract_qty"], sourceNode.end_contract_qty);
|
|
|
+ gatherNode['s_' + "end_contract_tp"] = helper.add(gatherNode['s_' + "end_contract_tp"], sourceNode.end_contract_tp);
|
|
|
+ gatherNode['s_' + "end_qc_qty"] = helper.add(gatherNode['s_' + "end_qc_qty"], sourceNode.end_qc_qty);
|
|
|
+ gatherNode['s_' + "end_qc_tp"] = helper.add(gatherNode['s_' + "end_qc_tp"], sourceNode.end_qc_tp);
|
|
|
+ gatherNode['s_' + "end_gather_qty"] = helper.add(gatherNode['s_' + "end_gather_qty"], sourceNode.end_gather_qty);
|
|
|
+ gatherNode['s_' + "end_gather_tp"] = helper.add(gatherNode['s_' + "end_gather_tp"], sourceNode.end_gather_tp);
|
|
|
+ },
|
|
|
+ gatherZone: function (tender, gatherNode, sourceNode, prefix, helper) {
|
|
|
+ gatherNode[prefix + 'id'] = tender.id;
|
|
|
+ gatherNode[prefix + 'name'] = tender.name;
|
|
|
+
|
|
|
+ gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
|
|
|
+ gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
|
|
|
+
|
|
|
+ gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
|
|
|
+ gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
|
|
|
+
|
|
|
+ gatherNode[prefix + "contract_qty"] = helper.add(gatherNode[prefix + "contract_qty"], sourceNode.contract_qty);
|
|
|
+ gatherNode[prefix + "contract_tp"] = helper.add(gatherNode[prefix + "contract_tp"], sourceNode.contract_tp);
|
|
|
+ gatherNode[prefix + "qc_qty"] = helper.add(gatherNode[prefix + "qc_qty"], sourceNode.qc_qty);
|
|
|
+ gatherNode[prefix + "qc_tp"] = helper.add(gatherNode[prefix + "qc_tp"], sourceNode.qc_tp);
|
|
|
+ gatherNode[prefix + "gather_qty"] = helper.add(gatherNode[prefix + "gather_qty"], sourceNode.gather_qty);
|
|
|
+ gatherNode[prefix + "gather_tp"] = helper.add(gatherNode[prefix + "gather_tp"], sourceNode.gather_tp);
|
|
|
+
|
|
|
+ gatherNode[prefix + "deal_dgn_qty1"] = helper.add(gatherNode[prefix + "deal_dgn_qty1"], sourceNode.deal_dgn_qty1);
|
|
|
+ gatherNode[prefix + "deal_dgn_qty2"] = helper.add(gatherNode[prefix + "deal_dgn_qty2"], sourceNode.deal_dgn_qty2);
|
|
|
+ gatherNode[prefix + "c_dgn_qty1"] = helper.add(gatherNode[prefix + "c_dgn_qty1"], sourceNode.c_dgn_qty1);
|
|
|
+ gatherNode[prefix + "c_dgn_qty2"] = helper.add(gatherNode[prefix + "c_dgn_qty2"], sourceNode.c_dgn_qty2);
|
|
|
+
|
|
|
+ gatherNode['s_' + "qty"] = helper.add(gatherNode['s_' + "qty"], sourceNode.quantity);
|
|
|
+ gatherNode['s_' + "tp"] = helper.add(gatherNode['s_' + "tp"], sourceNode.total_price);
|
|
|
+
|
|
|
+ gatherNode['s_' + "contract_qty"] = helper.add(gatherNode['s_' + "contract_qty"], sourceNode.contract_qty);
|
|
|
+ gatherNode['s_' + "contract_tp"] = helper.add(gatherNode['s_' + "contract_tp"], sourceNode.contract_tp);
|
|
|
+ gatherNode['s_' + "qc_qty"] = helper.add(gatherNode['s_' + "qc_qty"], sourceNode.qc_qty);
|
|
|
+ gatherNode['s_' + "qc_tp"] = helper.add(gatherNode['s_' + "qc_tp"], sourceNode.qc_tp);
|
|
|
+ gatherNode['s_' + "gather_qty"] = helper.add(gatherNode['s_' + "gather_qty"], sourceNode.gather_qty);
|
|
|
+ gatherNode['s_' + "gather_tp"] = helper.add(gatherNode['s_' + "gather_tp"], sourceNode.gather_tp);
|
|
|
+ },
|
|
|
+ gatherLedger: function (tender, gatherNode, sourceNode, prefix, helper) {
|
|
|
+ gatherNode[prefix + 'id'] = tender.id;
|
|
|
+ gatherNode[prefix + 'name'] = tender.name;
|
|
|
+
|
|
|
+ gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
|
|
|
+ gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
|
|
|
+
|
|
|
+ gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
|
|
|
+ gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
|
|
|
+
|
|
|
+ gatherNode['s_' + "qty"] = helper.add(gatherNode['s_' + "qty"], sourceNode.quantity);
|
|
|
+ gatherNode['s_' + "tp"] = helper.add(gatherNode['s_' + "tp"], sourceNode.total_price);
|
|
|
+ },
|
|
|
+ gatherSpecial: function (gatherNode, sourceNode, prefix, helper) {
|
|
|
+ gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
|
|
|
+ gatherNode[prefix + "tp"] = helper.add(gatherNode[prefix + "tp"], sourceNode.total_price);
|
|
|
+
|
|
|
+ gatherNode[prefix + "dgn_qty1"] = helper.add(gatherNode[prefix + "dgn_qty1"], sourceNode.dgn_qty1);
|
|
|
+ gatherNode[prefix + "dgn_qty2"] = helper.add(gatherNode[prefix + "dgn_qty2"], sourceNode.dgn_qty2);
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+ class RptStageSumMemory extends app.BaseService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局context
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getStageSumBills(tid, memFieldKeys, gsDefine, gsCustom) {
|
|
|
+ const self = this;
|
|
|
+ if (!gsDefine || !gsDefine.enable) return [];
|
|
|
+ if (!gsCustom || !gsCustom.stages || gsCustom.stages.length === 0) return [];
|
|
|
+
|
|
|
+ await this.ctx.service.tender.checkTender(tid);
|
|
|
+ const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
|
|
|
+ const calcFields = ['deal_tp', 'total_price'], calcPrefix = [];
|
|
|
+
|
|
|
+ const gsSetting = JSON.parse(gsDefine.setting);
|
|
|
+ for (const s of gsCustom.stages) {
|
|
|
+ const stage = await this.db.get(this.ctx.service.stage.tableName, { tid: this.ctx.tender.id, order: s });
|
|
|
+ if (!stage) continue;
|
|
|
+ await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+
|
|
|
+ const prefix = 's_' + stage.order + '_';
|
|
|
+ calcFields.push(prefix + 'contract_tp');
|
|
|
+ calcFields.push(prefix + 'qc_tp');
|
|
|
+ calcFields.push(prefix + 'gather_tp');
|
|
|
+ calcPrefix.push(prefix);
|
|
|
+
|
|
|
+ const curStage = stage.readOnly
|
|
|
+ ? await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
+ : await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, stage.id);
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp'], prefix: prefix, relaId: 'lid'}
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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: calcFields,
|
|
|
+ calc: function (node) {
|
|
|
+ for (const prefix of calcPrefix) {
|
|
|
+ if (node.children && node.children.length === 0) {
|
|
|
+ node[prefix + 'gather_qty'] = self.ctx.helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
|
|
|
+ }
|
|
|
+ node[prefix + 'gather_tp'] = self.ctx.helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ billsTree.loadDatas(billsData);
|
|
|
+ billsTree.calculateAll();
|
|
|
+ return billsTree.getDefaultDatas();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同支付
|
|
|
+ */
|
|
|
+
|
|
|
+ async _checkStagePayCalc(tender, stage, dealPay) {
|
|
|
+ if (!stage.readOnly) {
|
|
|
+ // 计算 本期金额
|
|
|
+ const payCalculator = new PayCalculator(this.ctx, stage, tender.info);
|
|
|
+ await payCalculator.calculateAll(dealPay);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _gatherStagePay(tender, stage, payData) {
|
|
|
+ if (stage) {
|
|
|
+ await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+
|
|
|
+ const dealPay = await this.ctx.service.stagePay.getStagePays(stage);
|
|
|
+ await this._checkStagePayCalc(tender, stage, dealPay);
|
|
|
+ this.ctx.helper.assignRelaData(billsData, [
|
|
|
+ {data: dealPay, fields: ['tp'], prefix: 's_' + stage.order + '_', relaId: 'pid'}
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async getStageSumPay(tid, memFieldKeys, gsDefine, gsCustom) {
|
|
|
+ if (!gsDefine || !gsDefine.enable) return [];
|
|
|
+ if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
|
|
|
+
|
|
|
+ await this.ctx.service.tender.checkTender(tid);
|
|
|
+ const payData = await this.ctx.service.pay.getAllDataByCondition({
|
|
|
+ where: {tid: tid},
|
|
|
+ order: [['order', 'ASC']],
|
|
|
+ });
|
|
|
+
|
|
|
+ const gsSetting = JSON.parse(gsDefine.setting);
|
|
|
+ for (const s of gsCustom.stages) {
|
|
|
+ const stage = this.getSelectStage(gsSetting, s);
|
|
|
+ await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ await this._gatherStagePay(this.ctx.tender, stage, payData);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return RptStageSumMemory;
|
|
|
+};
|