laiguoran пре 2 година
родитељ
комит
b0713d8840
1 измењених фајлова са 6 додато и 4 уклоњено
  1. 6 4
      app/service/material_bills.js

+ 6 - 4
app/service/material_bills.js

@@ -617,6 +617,8 @@ module.exports = app => {
                     const updateStageBillsList = [];
                     for (const ms of materialStageList) {
                         const msb = await transaction.get(this.ctx.service.materialStageBills.tableName, { mid: this.ctx.material.id, mb_id: mb.id, ms_id: ms.id });
+                        msb.m_up_risk = mb.m_up_risk;
+                        msb.m_down_risk = mb.m_down_risk;
                         const updateStageBillData = {
                             id: msb.id,
                         };
@@ -636,7 +638,7 @@ module.exports = app => {
                             msb.msg_tp = newmsg_tp;
                             const newbasic_price = this.ctx.helper.round(mb.basic_price, newDecimalUp);
                             const [newmsg_spread, newm_spread] = await this.getSpread(msb, msb.msg_tp, newDecimalUp, newbasic_price);
-                            mb.m_spread = newm_spread;
+                            msb.m_spread = newm_spread;
                             updateStageBillData.msg_tp = newmsg_tp;
                             updateStageBillData.msg_spread = newmsg_spread;
                             updateStageBillData.m_spread = newm_spread;
@@ -650,13 +652,13 @@ module.exports = app => {
                         const newbasic_price = this.ctx.helper.round(mb.basic_price, newDecimalUp);
                         updateData.basic_price = newbasic_price;
                     }
+                    if (updateStageBillsList.length > 0) await transaction.updateRows(this.ctx.service.materialStageBills.tableName, updateStageBillsList);
                     const sql = 'SELECT SUM(`m_tp`) as total_price, SUM(IF(`m_tax_tp` is null, `m_tp`, `m_tax_tp`)) as tax_total_price FROM ' + this.ctx.service.materialStageBills.tableName + ' WHERE `tid` = ? AND `mid` = ? AND `mb_id` = ? AND `is_summary` = 1';
                     const sqlParam = [this.ctx.tender.id, this.ctx.material.id, mb.id];
                     const tp = await transaction.queryOne(sql, sqlParam);
                     updateData.m_tp = this.ctx.helper.round(tp.total_price, newDecimalTp);
                     updateData.m_tax_tp = this.ctx.helper.round(tp.tax_total_price, newDecimalTp);
                     updateList.push(updateData);
-                    if (updateStageBillsList.length > 0) await transaction.updateRows(this.ctx.service.materialStageBills.tableName, updateStageBillsList);
                 } else {
                     if (newDecimalUp !== this.ctx.material.decimal.up) {
                         let newmsg_tp = this.ctx.helper.round(mb.msg_tp, newDecimalUp);
@@ -703,13 +705,13 @@ module.exports = app => {
                     updateList.push(updateData);
                 }
             }
+            if (updateMonthList.length > 0) await transaction.updateRows(this.ctx.service.materialMonth.tableName, updateMonthList);
+            if (updateList.length > 0) await transaction.updateRows(this.tableName, updateList);
             if (this.ctx.material.is_stage_self) {
                 for (const ms of materialStageList) {
                     await this.ctx.service.materialStage.updateMtp(transaction, ms.id);
                 }
             }
-            if (updateMonthList.length > 0) await transaction.updateRows(this.ctx.service.materialMonth.tableName, updateMonthList);
-            if (updateList.length > 0) await transaction.updateRows(this.tableName, updateList);
         }
     }