浏览代码

期未上报、审批退回未重新上报时,修改金额小数位数时,重算计量台账所有金额

MaiXinRong 4 年之前
父节点
当前提交
f56a329570
共有 1 个文件被更改,包括 41 次插入0 次删除
  1. 41 0
      app/service/tender_info.js

+ 41 - 0
app/service/tender_info.js

@@ -244,6 +244,43 @@ module.exports = app => {
             }
             return changeBills;
         }
+
+        async _reCalcStageBills(tenderId, newDecimal, oldDecimal) {
+            let updateStageBills = [], insertStageBills = [];
+            const stage = await this.ctx.service.stage.getLastestStage(tenderId, true);
+            if (!stage || stage.status === auditConst.stage.status.checking ||
+                stage.status === auditConst.stage.status.checked || newDecimal.tp === oldDecimal.tp)
+                return [updateStageBills, insertStageBills];
+
+            const stageBills = await this.ctx.service.stageBills.getLastestStageData2(stage.tid, stage.id);
+            const bills = await this.ctx.service.ledger.getAllDataByCondition({
+                columns: ['id', 'unit_price'],
+                where: { tender_id: tenderId, is_leaf: true },
+            });
+            for (const sb of stageBills) {
+                const b = bills.find(x => {return x.id === sb.lid});
+                const contract_tp = this.ctx.helper.mul(b.unit_price, sb.contract_qty, newDecimal.tp);
+                const qc_tp = this.ctx.helper.mul(b.unit_price, sb.qc_qty, newDecimal.tp);
+                if (contract_tp == sb.contract_tp && qc_tp === sb.qc_tp) continue;
+
+                //if (sb.)
+                if (sb.times === stage.times && sb.order === 0) {
+                    updateStageBills.push({
+                        id: sb.id, contract_tp, qc_tp
+                    });
+                } else {
+                    insertStageBills.push({
+                        tid: stage.tid, lid: sb.lid, sid: stage.id, said: this.ctx.session.sessionUser.accountId,
+                        times: stage.times, order: 0,
+                        contract_qty: sb.contract_qty, contract_expr: sb.contract_expr, contract_tp,
+                        qc_qty: sb.qc_qty, qc_tp,
+                        postil: sb.postil,
+                    });
+                }
+            }
+            return [updateStageBills, insertStageBills];
+        }
+
         async _reCalcStageExtra(tenderId, newDecimal, oldDecimal) {
             let changeSj = [], changeSb = [], changeSo = [];
             const stage = await this.ctx.service.stage.getLastestStage(tenderId, true);
@@ -309,15 +346,19 @@ module.exports = app => {
             const [billsService] = await this._getLedgerService();
 
             const changeBills = await this._reCalcLedger(tenderId, billsService, newDecimal, oldDecimal);
+            const [updateStageBills, insertStageBills] = await this._reCalcStageBills(tenderId, newDecimal, oldDecimal);
             const [changeSj, changeSb, changeSo] = await this._reCalcStageExtra(tenderId, newDecimal, oldDecimal);
             if (changeBills.length > 0 ||
                 changeAdvanceBills.length > 0 ||
+                updateStageBills.length > 0 || insertStageBills.length > 0 ||
                 changeSj.length > 0 || changeSb.length > 0 || changeSo.length > 0) {
                 const transaction = await this.db.beginTransaction();
                 try {
                     await transaction.update(this.tableName,
                         { decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
                     if (changeBills.length > 0) await transaction.updateRows(billsService.tableName, changeBills);
+                    if (updateStageBills.length > 0) await transaction.updateRows(this.ctx.service.stageBills.tableName, updateStageBills);
+                    if (insertStageBills.length > 0) await transaction.insert(this.ctx.service.stageBills.tableName, insertStageBills);
                     if (changeSj.length > 0) await transaction.updateRows(this.ctx.service.stageJgcl.tableName, changeSj);
                     if (changeSb.length > 0) await transaction.updateRows(this.ctx.service.stageBonus.tableName, changeSb);
                     if (changeSo.length > 0) await transaction.updateRows(this.ctx.service.stageOther.tableName, changeSo);