Browse Source

修复设置小数位费用工料数量bug

laiguoran 2 years ago
parent
commit
e2f4a93f0c
1 changed files with 32 additions and 13 deletions
  1. 32 13
      app/service/material_bills.js

+ 32 - 13
app/service/material_bills.js

@@ -648,13 +648,24 @@ module.exports = app => {
                         };
                         if (newDecimalQty !== this.ctx.material.decimal.qty) {
                             // 通过管理重新算出quantity并保留小数位
-                            const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `ms_id`=? AND `is_join`=1';
-                            const sqlParam = [this.ctx.material.id, mb.id, ms.id];
-                            const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                            const newQuantity = this.ctx.helper.round(mb_quantity.quantity, newDecimalQty);
-                            if (newQuantity !== msb.quantity) {
-                                updateStageBillData.quantity = newQuantity;
-                                msb.quantity = newQuantity;
+                            if (mb.t_type === materialConst.t_type[0].value) {
+                                // 通过管理重新算出quantity并保留小数位
+                                const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `ms_id`=? AND `is_join`=1';
+                                const sqlParam = [this.ctx.material.id, mb.id, ms.id];
+                                const mb_quantity = await transaction.queryOne(sql, sqlParam);
+                                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, newDecimalQty);
+                                if (newQuantity !== msb.quantity) {
+                                    updateStageBillData.quantity = newQuantity;
+                                    msb.quantity = newQuantity;
+                                }
+                            } else if (mb.t_type === materialConst.t_type[1].value) {
+                                const materialCalculator = new MaterialCalculator(this.ctx, ms.sid, this.ctx.tender.info);
+                                const quantity = await materialCalculator.calculateExpr(msb.expr);
+                                const newQuantity = this.ctx.helper.round(quantity, newDecimalQty);
+                                if (newQuantity !== msb.quantity) {
+                                    updateStageBillData.quantity = newQuantity;
+                                    msb.quantity = newQuantity;
+                                }
                             }
                         }
                         if (newDecimalUp !== this.ctx.material.decimal.up) {
@@ -716,12 +727,20 @@ module.exports = app => {
                     }
                     if (newDecimalQty !== this.ctx.material.decimal.qty) {
                         // 通过管理重新算出quantity并保留小数位
-                        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 = [this.ctx.material.id, mb.id];
-                        const mb_quantity = await transaction.queryOne(sql, sqlParam);
-                        const newQuantity = this.ctx.helper.round(mb_quantity.quantity, newDecimalQty);
-                        mb.quantity = newQuantity;
-                        updateData.quantity = newQuantity;
+                        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 sqlParam = [this.ctx.material.id, mb.id];
+                            const mb_quantity = await transaction.queryOne(sql, sqlParam);
+                            const newQuantity = this.ctx.helper.round(mb_quantity.quantity, newDecimalQty);
+                            mb.quantity = newQuantity;
+                            updateData.quantity = newQuantity;
+                        } else if (mb.t_type === materialConst.t_type[1].value) {
+                            const materialCalculator = new MaterialCalculator(this.ctx, this.ctx.material.stage_id, this.ctx.tender.info);
+                            const quantity = await materialCalculator.calculateExpr(mb.expr);
+                            const newQuantity = this.ctx.helper.round(quantity, newDecimalQty);
+                            mb.quantity = newQuantity;
+                            updateData.quantity = newQuantity;
+                        }
                     }
                     const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, mb.m_spread), newDecimalTp);
                     updateData.m_tp = newTp;