瀏覽代碼

变更金额重算及bug

laiguoran 3 年之前
父節點
當前提交
d8abc4850b

+ 6 - 0
app/controller/change_controller.js

@@ -2999,6 +2999,9 @@ module.exports = app => {
                             throw '修改失败';
                         }
                         break;
+                    case 'update_tp':
+                        await ctx.service.changeApply.saveInfo(ctx.change.id, { name: 'total_price', val: data.updateData });
+                        break;
                     default: throw '参数有误';
                 }
 
@@ -3604,6 +3607,9 @@ module.exports = app => {
                         // 取所有工料表
                         responseData.data = changeList;
                         break;
+                    case 'update_tp':
+                        await ctx.service.changePlan.saveInfo(ctx.change.id, { name: 'total_price', val: data.updateData });
+                        break;
                     default: throw '参数有误';
                 }
 

+ 11 - 2
app/public/js/change_apply_information.js

@@ -227,10 +227,10 @@ $(document).ready(() => {
                 return ZhCalc.round(data.unit_price, unitPriceUnit);
             },
             oa_tp: function (data) {
-                return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
+                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), data.oamount), totalPriceUnit);
             },
             ca_tp: function (data) {
-                return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
+                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), data.camount), totalPriceUnit);
             },
             oamount: function (data) {
                 return ZhCalc.round(data.oamount, findDecimal(data.unit));
@@ -641,6 +641,15 @@ $(document).ready(() => {
         SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
         SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
         changeSpreadObj.makeSjsFooter();
+
+        // 计算最新的变更总额和change的total_price是否一致,不一致则更新
+        let new_tp = 0;
+        for (const c of changeList) {
+            new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(c.camount, ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
+        }
+        if (change.total_price && change.total_price !== new_tp) {
+            postData(preUrl + '/list/save', { type:'update_tp', updateData: new_tp }, function (result) {});
+        }
     });
 });
 

+ 14 - 5
app/public/js/change_plan_information.js

@@ -233,10 +233,10 @@ $(document).ready(() => {
                 return ZhCalc.round(data.unit_price, unitPriceUnit);
             },
             oa_tp: function (data) {
-                return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
+                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), data.oamount), totalPriceUnit);
             },
             ca_tp: function (data) {
-                return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
+                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), data.camount), totalPriceUnit);
             },
             oamount: function (data) {
                 return ZhCalc.round(data.oamount, findDecimal(data.unit));
@@ -248,7 +248,7 @@ $(document).ready(() => {
                 return ZhCalc.round(data.samount, findDecimal(data.unit));
             },
             sa_tp: function (data) {
-                return ZhCalc.round(ZhCalc.mul(data.unit_price, data.samount), totalPriceUnit);
+                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), data.samount), totalPriceUnit);
             },
         },
         readOnly: {
@@ -268,13 +268,13 @@ $(document).ready(() => {
         setAuditValue: function () {
             for (const c of changeList) {
                 for (const audit of change.listAudits) {
-                    c['sa_tp_' + audit.aid] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + audit.aid], c.unit_price), totalPriceUnit);
+                    c['sa_tp_' + audit.aid] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + audit.aid], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
                 }
             }
         },
         setRowValueAndSum: function (data, row, col) {
             for (const j in change.listAudits) {
-                const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
+                const sum = ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
                 changeSpreadSheet.setValue(row, 11 + j*2, sum !== 0 ? sum : null);
             }
             // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
@@ -838,6 +838,15 @@ $(document).ready(() => {
         } else {
             changeSpreadObj.showHideAudit(true);
         }
+
+        // 计算最新的变更总额和change的total_price是否一致,不一致则更新
+        let new_tp = 0;
+        for (const c of changeList) {
+            new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(c.spamount, ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
+        }
+        if (change.total_price && change.total_price !== new_tp) {
+            postData(preUrl + '/list/save', { type:'update_tp', updateData: new_tp }, function (result) {});
+        }
     });
 
     // 审批流程展示与隐藏