|
@@ -763,10 +763,17 @@ module.exports = app => {
|
|
|
|
|
|
async getStageByDataCollect(tenderId) {
|
|
async getStageByDataCollect(tenderId) {
|
|
const stages = await this.db.select(this.tableName, {
|
|
const stages = await this.db.select(this.tableName, {
|
|
- columns: ['s_time', 'contract_tp', 'qc_tp', 'pc_tp', 'pre_contract_tp', 'pre_qc_tp'],
|
|
|
|
|
|
+ columns: ['id', 'times', 'status', 's_time', 'contract_tp', 'qc_tp', 'pc_tp', 'pre_contract_tp', 'pre_qc_tp', 'tp_history'],
|
|
where: { tid: tenderId },
|
|
where: { tid: tenderId },
|
|
orders: [['order', 'desc']],
|
|
orders: [['order', 'desc']],
|
|
});
|
|
});
|
|
|
|
+ if (stages.length === 0) return stages;
|
|
|
|
+ if (stages.length > 0 && stages[0].status === auditConst.status.uncheck) {
|
|
|
|
+ stages.splice(0, 1);
|
|
|
|
+ }
|
|
|
|
+ // 最新一期计量(未审批完成),取上一个人的期详细数据,应实时计算
|
|
|
|
+ const stage = stages[0];
|
|
|
|
+ await this.checkStageGatherDataByDataCollect(stage);
|
|
for (const s of stages) {
|
|
for (const s of stages) {
|
|
s.tp = this.ctx.helper.sum([s.contract_tp, s.qc_tp, s.pc_tp]);
|
|
s.tp = this.ctx.helper.sum([s.contract_tp, s.qc_tp, s.pc_tp]);
|
|
s.pre_tp = this.ctx.helper.add(s.pre_contract_tp, s.pre_qc_tp);
|
|
s.pre_tp = this.ctx.helper.add(s.pre_contract_tp, s.pre_qc_tp);
|
|
@@ -775,6 +782,65 @@ module.exports = app => {
|
|
return stages;
|
|
return stages;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async doCheckStageByDataCollect(stage) {
|
|
|
|
+ const status = auditConst.status;
|
|
|
|
+ await this.loadStageUser(stage);
|
|
|
|
+ if (stage.status === status.checkNo) {
|
|
|
|
+ stage.readOnly = false;
|
|
|
|
+ const checkNoAudit = await this.service.stageAudit.getDataByCondition({
|
|
|
|
+ sid: stage.id, times: stage.times - 1, status: status.checkNo,
|
|
|
|
+ });
|
|
|
|
+ stage.curTimes = stage.times - 1;
|
|
|
|
+ stage.curOrder = checkNoAudit.order;
|
|
|
|
+ } else if (stage.status === status.checked) {
|
|
|
|
+ stage.readOnly = true;
|
|
|
|
+ stage.curTimes = stage.times;
|
|
|
|
+ stage.curOrder = _.max(_.map(stage.auditors, 'order'));
|
|
|
|
+ } else {
|
|
|
|
+ stage.readOnly = false;
|
|
|
|
+ stage.curTimes = stage.times;
|
|
|
|
+ stage.curOrder = stage.curAuditor.order - 1;
|
|
|
|
+ }
|
|
|
|
+ return stage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async checkStageGatherDataByDataCollect(stage) {
|
|
|
|
+ // 最新一期计量(未审批完成),当前操作人的期详细数据,应实时计算
|
|
|
|
+ if (stage.status !== auditConst.status.checked) {
|
|
|
|
+ await this.doCheckStageByDataCollect(stage);
|
|
|
|
+ if (!stage.readOnly && stage.check_calc) {
|
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(stage);
|
|
|
|
+ const pcSum = await this.ctx.service.stageBillsPc.getSumTotalPrice(stage);
|
|
|
|
+ stage.contract_tp = tpData.contract_tp;
|
|
|
|
+ stage.qc_tp = tpData.qc_tp;
|
|
|
|
+ stage.positive_qc_tp = tpData.positive_qc_tp;
|
|
|
|
+ stage.negative_qc_tp = tpData.negative_qc_tp;
|
|
|
|
+ stage.contract_pc_tp = pcSum.contract_pc_tp;
|
|
|
|
+ stage.qc_pc_tp = pcSum.qc_pc_tp;
|
|
|
|
+ stage.pc_tp = pcSum.pc_tp;
|
|
|
|
+ stage.positive_qc_pc_tp = pcSum.positive_qc_pc_tp;
|
|
|
|
+ stage.negative_qc_pc_tp = pcSum.negative_qc_pc_tp;
|
|
|
|
+ stage.tp = this.ctx.helper.sum([stage.contract_tp, stage.qc_tp, stage.pc_tp]);
|
|
|
|
+ const tp = await this.ctx.service.stagePay.getSpecialTotalPrice(stage);
|
|
|
|
+ stage.yf_tp = tp.yf;
|
|
|
|
+ stage.sf_tp = tp.sf;
|
|
|
|
+ stage.end_tp = this.ctx.helper.add(stage.pre_tp, stage.tp);
|
|
|
|
+ } else if (stage.tp_history) {
|
|
|
|
+ const his = this.ctx.helper._.find(stage.tp_history, { times: stage.curTimes, order: stage.curOrder });
|
|
|
|
+ if (his) {
|
|
|
|
+ stage.contract_tp = his.contract_tp;
|
|
|
|
+ stage.qc_tp = his.qc_tp;
|
|
|
|
+ stage.positive_qc_tp = his.positive_qc_tp;
|
|
|
|
+ stage.negative_qc_tp = his.negative_qc_tp;
|
|
|
|
+ stage.yf_tp = his.yf_tp;
|
|
|
|
+ stage.sf_tp = his.sf_tp;
|
|
|
|
+ stage.tp = this.ctx.helper.sum([stage.contract_tp, stage.qc_tp, stage.pc_tp]);
|
|
|
|
+ stage.end_tp = this.ctx.helper.add(stage.pre_tp, stage.tp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
async isLastStage(tid, sid) {
|
|
async isLastStage(tid, sid) {
|
|
const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
|
|
const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
|
|
return lastStage ? lastStage.id === sid : false;
|
|
return lastStage ? lastStage.id === sid : false;
|