ソースを参照

调差期新建统计rate_tp

ellisran 1 年間 前
コミット
0a9d824142

+ 5 - 2
app/service/material.js

@@ -157,6 +157,7 @@ module.exports = app => {
                 is_stage_self: data.is_stage_self,
                 qty_source: data.qty_source,
                 is_new_qty: 1,
+                rate: 9,
             };
             const transaction = await this.db.beginTransaction();
             try {
@@ -215,10 +216,11 @@ module.exports = app => {
                     // 修改本期应耗数量值和有效价差,需要剔除不参与调差的清单数据,并返回总金额
                     let m_tp = null;
                     let m_tax_tp = null;
+                    let rate_tp = null;
                     if (data.is_stage_self) {
-                        [m_tp, m_tax_tp] = await this.ctx.service.materialStageBills.insertBills(transaction, this.ctx.tender.id, newMaterial.id, newMaterial.stage_id, insertMaterialStage, JSON.parse(newMaterial.decimal), preMaterial.is_stage_self, data.qty_source);
+                        [m_tp, m_tax_tp, rate_tp] = await this.ctx.service.materialStageBills.insertBills(transaction, this.ctx.tender.id, newMaterial.id, newMaterial.stage_id, insertMaterialStage, JSON.parse(newMaterial.decimal), preMaterial.is_stage_self, data.qty_source, newMaterial.rate);
                     } else {
-                        [m_tp, m_tax_tp] = await this.ctx.service.materialBills.updateNewMaterial(transaction, this.ctx.tender.id, newMaterial.id, this.ctx, newMaterial.stage_id, JSON.parse(newMaterial.decimal), preMaterial.is_stage_self, data.qty_source);
+                        [m_tp, m_tax_tp, rate_tp] = await this.ctx.service.materialBills.updateNewMaterial(transaction, this.ctx.tender.id, newMaterial.id, this.ctx, newMaterial.stage_id, JSON.parse(newMaterial.decimal), preMaterial.is_stage_self, data.qty_source, newMaterial.rate);
                     }
                     // 修改现行价格指数,并返回调差基数json
                     const ex_calc = await this.ctx.service.materialExponent.updateNewMaterial(transaction, newMaterial.id, this.ctx, newMaterial.stage_id, preMaterial.ex_calc, JSON.parse(newMaterial.decimal));
@@ -229,6 +231,7 @@ module.exports = app => {
                         id: newMaterial.id,
                         m_tp,
                         m_tax_tp,
+                        rate_tp,
                         ex_calc: JSON.stringify(ex_calc),
                         tp_data: JSON.stringify(tp_data),
                     };

+ 3 - 2
app/service/material_bills.js

@@ -584,7 +584,7 @@ module.exports = app => {
          * @param mid
          * @returns {Promise<number>}
          */
-        async updateNewMaterial(transaction, tid, mid, ctx, stage_id, decimal, pre_is_stage_self = 0, qty_source = 1) {
+        async updateNewMaterial(transaction, tid, mid, ctx, stage_id, decimal, pre_is_stage_self = 0, qty_source = 1, rate) {
             const materialBillsData = await this.getAllDataByCondition({ where: { tid } });
             let m_tp = 0;
             let m_tax_tp = 0;
@@ -594,7 +594,8 @@ module.exports = app => {
                 m_tp = this.ctx.helper.add(m_tp, one_tp);
                 m_tax_tp = this.ctx.helper.add(m_tax_tp, one_tax_tp);
             }
-            return [m_tp, m_tax_tp];
+            const rate_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(rate, 100))), decimal.tp);
+            return [m_tp, m_tax_tp, rate_tp];
         }
 
         /**

+ 4 - 2
app/service/material_stage_bills.js

@@ -25,9 +25,10 @@ module.exports = app => {
             super(ctx);
             this.tableName = 'material_stage_bills';
         }
-        async insertBills(transaction, tid, mid, stage_id, materialStageData, decimal, pre_is_stage_self = 0, qty_source = 1) {
+        async insertBills(transaction, tid, mid, stage_id, materialStageData, decimal, pre_is_stage_self = 0, qty_source = 1, rate) {
             let m_tp = 0;
             let m_tax_tp = 0;
+            let rate_tp = 0;
             // 复制工料表并生成
             const billsList = await transaction.select(this.ctx.service.materialBills.tableName, { where: { tid } });
             if (billsList.length > 0) {
@@ -88,10 +89,11 @@ module.exports = app => {
                         m_tax_tp: newTaxTp,
                     };
                     updateStageData.push(oneStageData);
+                    rate_tp = this.ctx.helper.add(rate_tp, this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(rate, 100))), decimal.tp));
                 }
                 await transaction.updateRows(this.ctx.service.materialStage.tableName, updateStageData);
             }
-            return [m_tp, m_tax_tp];
+            return [m_tp, m_tax_tp, rate_tp];
         }
 
         // 添加工料时同步生成