浏览代码

修复bug

laiguoran 3 年之前
父节点
当前提交
23d0941324
共有 3 个文件被更改,包括 24 次插入24 次删除
  1. 2 2
      app/service/material.js
  2. 18 18
      app/service/material_bills.js
  3. 4 4
      app/service/material_exponent.js

+ 2 - 2
app/service/material.js

@@ -175,9 +175,9 @@ module.exports = app => {
                     // 复制调差清单工料关联表
                     // 复制调差清单工料关联表
                     await this.ctx.service.materialList.copyPreMaterialList(transaction, preMaterial, newMaterial);
                     await this.ctx.service.materialList.copyPreMaterialList(transaction, preMaterial, newMaterial);
                     // 修改本期应耗数量值和有效价差,需要剔除不参与调差的清单数据,并返回总金额
                     // 修改本期应耗数量值和有效价差,需要剔除不参与调差的清单数据,并返回总金额
-                    const [m_tp, m_tax_tp] = await this.ctx.service.materialBills.updateNewMaterial(transaction, this.ctx.tender.id, newMaterial.id, this.ctx, newMaterial.stage_id);
+                    const [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));
                     // 修改现行价格指数,并返回调差基数json
                     // 修改现行价格指数,并返回调差基数json
-                    const ex_calc = await this.ctx.service.materialExponent.updateNewMaterial(transaction, newMaterial.id, this.ctx, newMaterial.stage_id, preMaterial.ex_calc);
+                    const ex_calc = await this.ctx.service.materialExponent.updateNewMaterial(transaction, newMaterial.id, this.ctx, newMaterial.stage_id, preMaterial.ex_calc, JSON.parse(newMaterial.decimal));
                     // 计算得出本期总金额
                     // 计算得出本期总金额
                     const updateMaterialData = {
                     const updateMaterialData = {
                         id: newMaterial.id,
                         id: newMaterial.id,

+ 18 - 18
app/service/material_bills.js

@@ -222,13 +222,13 @@ module.exports = app => {
          * @param mid
          * @param mid
          * @returns {Promise<number>}
          * @returns {Promise<number>}
          */
          */
-        async updateNewMaterial(transaction, tid, mid, ctx, stage_id) {
+        async updateNewMaterial(transaction, tid, mid, ctx, stage_id, decimal) {
             const materialBillsData = await this.getAllDataByCondition({ where: { tid } });
             const materialBillsData = await this.getAllDataByCondition({ where: { tid } });
             let m_tp = 0;
             let m_tp = 0;
             let m_tax_tp = 0;
             let m_tax_tp = 0;
             const materialCalculator = new MaterialCalculator(ctx, stage_id, ctx.tender.info);
             const materialCalculator = new MaterialCalculator(ctx, stage_id, ctx.tender.info);
             for (const mb of materialBillsData) {
             for (const mb of materialBillsData) {
-                const [one_tp, one_tax_tp] = await this.calcQuantityByMB(transaction, mid, mb, materialCalculator);
+                const [one_tp, one_tax_tp] = await this.calcQuantityByMB(transaction, mid, mb, materialCalculator, decimal);
                 m_tp = this.ctx.helper.add(m_tp, one_tp);
                 m_tp = this.ctx.helper.add(m_tp, one_tp);
                 m_tax_tp = this.ctx.helper.add(m_tax_tp, one_tax_tp);
                 m_tax_tp = this.ctx.helper.add(m_tax_tp, one_tax_tp);
             }
             }
@@ -242,16 +242,16 @@ module.exports = app => {
          * @param mb
          * @param mb
          * @returns {Promise<*>}
          * @returns {Promise<*>}
          */
          */
-        async calcQuantityByMB(transaction, mid, mb, materialCalculator) {
-            const [newmsg_spread, newm_spread] = await this.getSpread(mb, null);
+        async calcQuantityByMB(transaction, mid, mb, materialCalculator, decimal) {
+            const [newmsg_spread, newm_spread] = await this.getSpread(mb, null, decimal.up);
             if (mb.t_type === materialConst.t_type[0].value) {
             if (mb.t_type === materialConst.t_type[0].value) {
                 const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
                 const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
                 const sqlParam = [mid, mb.id];
                 const sqlParam = [mid, mb.id];
                 const mb_quantity = await transaction.queryOne(sql, sqlParam);
                 const mb_quantity = await transaction.queryOne(sql, sqlParam);
                 console.log(mb_quantity);
                 console.log(mb_quantity);
                 // 取历史期记录获取截止上期调差金额,并清空本期单价和时间,来源地,重新计算价差和有效价差
                 // 取历史期记录获取截止上期调差金额,并清空本期单价和时间,来源地,重新计算价差和有效价差
-                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
-                const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), this.ctx.material.decimal.tp);
+                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, decimal.qty);
+                const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), decimal.tp);
                 const updateData = {
                 const updateData = {
                     id: mb.id,
                     id: mb.id,
                     quantity: newQuantity,
                     quantity: newQuantity,
@@ -261,33 +261,33 @@ module.exports = app => {
                     m_spread: newm_spread,
                     m_spread: newm_spread,
                     origin: null,
                     origin: null,
                     m_tp: newTp,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), this.ctx.material.decimal.tp) : mb.pre_tp,
-                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), this.ctx.material.decimal.tp) : mb.tax_pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
+                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
                 };
                 };
                 await transaction.update(this.tableName, updateData);
                 await transaction.update(this.tableName, updateData);
-                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), this.ctx.material.decimal.tp) : 0;
-                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp);
+                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), decimal.tp) : 0;
+                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp);
                 return [m_tp, m_tax_tp];
                 return [m_tp, m_tax_tp];
             } else if (mb.t_type === materialConst.t_type[1].value) {
             } else if (mb.t_type === materialConst.t_type[1].value) {
                 const quantity = await materialCalculator.calculateExpr(mb.expr);
                 const quantity = await materialCalculator.calculateExpr(mb.expr);
-                const newTp = quantity !== 0 && quantity !== null ? this.ctx.helper.round(this.ctx.helper.mul(this.ctx.helper.round(quantity, this.ctx.material.decimal.qty), newm_spread), this.ctx.material.decimal.tp) : null;
+                const newTp = quantity !== 0 && quantity !== null ? this.ctx.helper.round(this.ctx.helper.mul(this.ctx.helper.round(quantity, decimal.qty), newm_spread), decimal.tp) : null;
                 const updateData = {
                 const updateData = {
                     id: mb.id,
                     id: mb.id,
-                    quantity: quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, this.ctx.material.decimal.qty) : null,
+                    quantity: quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, decimal.qty) : null,
                     msg_tp: null,
                     msg_tp: null,
                     msg_times: null,
                     msg_times: null,
                     msg_spread: newmsg_spread,
                     msg_spread: newmsg_spread,
                     m_spread: newm_spread,
                     m_spread: newm_spread,
                     origin: null,
                     origin: null,
                     m_tp: newTp,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), this.ctx.material.decimal.tp) : mb.pre_tp,
-                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), this.ctx.material.decimal.tp) : mb.tax_pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), decimal.tp) : mb.pre_tp,
+                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp),
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), decimal.tp) : mb.tax_pre_tp,
                 };
                 };
                 await transaction.update(this.tableName, updateData);
                 await transaction.update(this.tableName, updateData);
-                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), this.ctx.material.decimal.tp) : 0;
-                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp);
+                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), decimal.tp) : 0;
+                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), decimal.tp);
                 return [m_tp, m_tax_tp];
                 return [m_tp, m_tax_tp];
             }
             }
         }
         }

+ 4 - 4
app/service/material_exponent.js

@@ -188,7 +188,7 @@ module.exports = app => {
         }
         }
 
 
         // 更改计算总指数金额并返回值和公式
         // 更改计算总指数金额并返回值和公式
-        async calcMaterialExTp(transaction, ex_calc = (this.ctx.material.ex_calc ? JSON.parse(this.ctx.material.ex_calc) : null), mid = null) {
+        async calcMaterialExTp(transaction, ex_calc = (this.ctx.material.ex_calc ? JSON.parse(this.ctx.material.ex_calc) : null), mid = null, decimal = (this.ctx.material.decimal ? this.ctx.material.decimal : materialConst.decimal)) {
             let basic_calc = 0;
             let basic_calc = 0;
             if (ex_calc) {
             if (ex_calc) {
                 for (const calc of ex_calc) {
                 for (const calc of ex_calc) {
@@ -213,7 +213,7 @@ module.exports = app => {
             }
             }
             expr += '-1]';
             expr += '-1]';
             expr = constant !== 0 ? expr : null;
             expr = constant !== 0 ? expr : null;
-            const ex_tp = constant !== 0 ? this.ctx.helper.round(this.ctx.helper.mul(basic_calc, this.ctx.helper.sub(this.ctx.helper.add(constant, sumByChange), 1)), this.ctx.material.decimal.tp) : null;
+            const ex_tp = constant !== 0 ? this.ctx.helper.round(this.ctx.helper.mul(basic_calc, this.ctx.helper.sub(this.ctx.helper.add(constant, sumByChange), 1)), decimal.tp) : null;
             await transaction.update(this.ctx.service.material.tableName, {
             await transaction.update(this.ctx.service.material.tableName, {
                 id: mid ? mid : this.ctx.material.id,
                 id: mid ? mid : this.ctx.material.id,
                 ex_tp,
                 ex_tp,
@@ -230,7 +230,7 @@ module.exports = app => {
          * @param mid
          * @param mid
          * @returns {Promise<number>}
          * @returns {Promise<number>}
          */
          */
-        async updateNewMaterial(transaction, mid, ctx, stage_id, ex_calc) {
+        async updateNewMaterial(transaction, mid, ctx, stage_id, ex_calc, decimal) {
             const stage_list = await ctx.service.stage.getStageMsgByStageId(stage_id);
             const stage_list = await ctx.service.stage.getStageMsgByStageId(stage_id);
             const calcBase = await ctx.service.stage.getMaterialCalcBase(stage_list, ctx.tender.info);
             const calcBase = await ctx.service.stage.getMaterialCalcBase(stage_list, ctx.tender.info);
             const old_ex_calc = ex_calc ? JSON.parse(ex_calc) : null;
             const old_ex_calc = ex_calc ? JSON.parse(ex_calc) : null;
@@ -241,7 +241,7 @@ module.exports = app => {
                 bq.value = calc.value;
                 bq.value = calc.value;
                 bq.select = oldcalc ? oldcalc.select : false;
                 bq.select = oldcalc ? oldcalc.select : false;
             }
             }
-            await this.calcMaterialExTp(transaction, new_ex_calc, mid);
+            await this.calcMaterialExTp(transaction, new_ex_calc, mid, decimal);
             return new_ex_calc;
             return new_ex_calc;
         }
         }
     }
     }