Pārlūkot izejas kodu

决策大屏及调差增加沥青

laiguoran 2 gadi atpakaļ
vecāks
revīzija
dde2b311e9

+ 1 - 0
app/const/material.js

@@ -22,6 +22,7 @@ const m_type = [
     { text: '水泥', value: 5 },
     { text: '半成品', value: 6 },
     { text: '砂石料', value: 8 },
+    { text: '沥青', value: 9 },
     { text: '其他', value: 7 },
 ];
 // 指数调差类型

+ 1 - 1
app/controller/datacollect_controller.js

@@ -115,7 +115,7 @@ module.exports = app => {
 
                     if (t.ledger_status === auditConst.ledger.status.checked) {
                         t.lastStage = await ctx.service.stage.getLastestStage(t.id);
-                        if (t.lastStage) await ctx.service.stage.checkStageGatherData(t.lastStage, true);
+                        if (t.lastStage) await ctx.service.stage.checkStageGatherDataByDataCollect(t.lastStage, true);
                         t.completeStage = await ctx.service.stage.getLastestCompleteStage(t.id);
                         if ((!bCalcTp) && t.measure_type === measureType.gcl.value) {
                             bCalcTp = t.lastStage && t.lastStage.status !== auditConst.stage.status.checked && !t.lastStage.readOnly;

+ 67 - 1
app/service/stage.js

@@ -763,10 +763,17 @@ module.exports = app => {
 
         async getStageByDataCollect(tenderId) {
             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 },
                 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) {
                 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);
@@ -775,6 +782,65 @@ module.exports = app => {
             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) {
             const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
             return lastStage ? lastStage.id === sid : false;