Browse Source

计算四舍五入,浮点数存储换成String。
叶子清单挂定额、项目属性取费方式为清单单价时,清单取自己的计算程序ID读定额的计算程序计算。

Chenshilong 7 years ago
parent
commit
7f51dd20c5

+ 1 - 1
modules/main/models/calc_program_model.js

@@ -14,7 +14,7 @@ let calcItemSchema = new Schema({
     compiledExpr: String,
     statement: String,
     feeRateID: Number,
-    feeRate: Number,
+    feeRate: String,
     labourCoeID: Number
 },{versionKey:false, _id: false});
 

+ 1 - 1
modules/main/models/labour_coe_model.js

@@ -8,7 +8,7 @@ let coeSchema = new Schema({
     ID: Number,
     ParentID: Number,
     name: String,
-    coe: Number,
+    coe: String,
     _id: false
 },{versionKey:false});
 

+ 9 - 5
public/calc_util.js

@@ -5,9 +5,11 @@
  */
 
 // 需求说小数位数固定为2位,这里预留缓冲接口,防止以后需求变卦。
-const Digit_Calc_Program = -2;      // 这里指定计算程序用到的小数位数。
-function round(num) {
-    return scMathUtil.roundTo(num, Digit_Calc_Program);
+const Digit_Calc_Program = -2;              // 需求指定计算程序用到的小数位数。
+const Digit_Calc_Program_Default = -6;      // 需求末指定时默认用到的小数位数。
+function round(value, useDef = false) {
+    let digit = useDef ? Digit_Calc_Program_Default : Digit_Calc_Program;
+    return scMathUtil.roundTo(value, digit);
 };
 
 let executeObj = {
@@ -51,9 +53,11 @@ let executeObj = {
                                    price = md["base_price"];
                                    if (!price) price = 0;
                                    mdSum = mdSum +  round(md["consumption"] * price);
+                                   mdSum = round(mdSum, true);
                                }
                            };
-                           tmpSum = tmpSum + glj["quantity"] * mdSum;     // 这里不能四舍五入
+                           tmpSum = tmpSum + round(glj["quantity"] * mdSum, true);
+                           tmpSum = round(tmpSum, true);
                        }
                 };
             }else{
@@ -70,7 +74,7 @@ let executeObj = {
                             price = mprice - aprice;
                         };
                         if (!price) price = 0;
-                        tmpSum = tmpSum + glj["quantity"] * price;
+                        tmpSum = round(tmpSum + round(glj["quantity"] * price, true), true);
                     };
                 };
             };

+ 6 - 2
web/building_saas/main/js/calc/bills_calc.js

@@ -263,12 +263,13 @@ class BillsCalcHelper {
     };
     calcRationLeaf (node, fields, isIncre) {
         nodeCalcObj.node = node;
-        nodeCalcObj.digit = this.project.Decimal.unitFee;
+        nodeCalcObj.digit = this.project.Decimal.common.unitFee;
         calcFees.checkFields(node.data, fields);
         let nodeCalc = nodeCalcObj, virData= null, decimal = this.project.Decimal;
 
         // 清单单价:套用定额计算程序
-        if (this.project.calcFlag === billsPrice) {
+        // if (this.project.calcFlag === billsPrice) {
+        if (this.project.projSetting.billsCalcMode === billsPrice) {
             rationCalcObj.calcGljs = this.getBillsGLjs(node);
             console.log(rationCalcObj.calcGljs);
             rationCalcObj.calcFields = rationCalcFields;
@@ -352,6 +353,7 @@ class BillsCalcHelper {
         if (parent && parent.sourceType === this.project.Bills.getSourceType()) {
             calcFees.checkFields(parent.data, [field]);
             parent.data.feesIndex[field.type].totalFee = (parent.data.feesIndex[field.type].totalFee + Incre).toDecimal(this.project.Decimal.common.totalFee);
+            parent.data.feesIndex[field.type].unitFee = 0;   // AAAAA 临时补上,使存储 unitFee.toFixed(2) 时不出错
             this.updateParent(parent.parent, field, Incre);
         }
     };
@@ -359,9 +361,11 @@ class BillsCalcHelper {
         if (isIncre) {
             let incre = value - node.data.feesIndex[field.type].totalFee;
             node.data.feesIndex[field.type].totalFee = value;
+            node.data.feesIndex[field.type].unitFee = 0; // AAAAA 临时补上,使存储 unitFee.toFixed(2) 时不出错
             this.updateParent(node.parent, field, incre);
         } else {
             node.data.feesIndex[field.type].totalFee = value;
+            node.data.feesIndex[field.type].unitFee = 0; // AAAAA 临时补上,使存储 unitFee.toFixed(2) 时不出错
         }
     };
     converseCalc (node) {

+ 8 - 1
web/building_saas/main/js/models/calc_program.js

@@ -50,7 +50,14 @@ class CalcProgram {
     };
 
     calculate(treeNode){
-        treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID);
+        if (treeNode.sourceType === this.project.Ration.getSourceType()) {
+            treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID);
+        }
+        else if (treeNode.sourceType === this.project.Bills.getSourceType()) {
+             let rations = this.project.Ration.getBillsSortRation(treeNode.source.getID());
+            treeNode.data.gljList = this.project.ration_glj.getGatherGljArrByRations(rations);
+        };
+
         this.calc.calculate(treeNode);
         projectObj.mainController.refreshTreeNode([treeNode]);
     }

+ 8 - 2
web/building_saas/main/js/views/calc_program_view.js

@@ -228,7 +228,13 @@ let calcProgramObj = {
     showData: function (treeNode) {
         var me = this;
         me.treeNode = treeNode;
-        if (treeNode.sourceType === projectObj.project.Ration.getSourceType()) {
+
+        let isRation = treeNode.sourceType === projectObj.project.Ration.getSourceType();
+        let isBill = treeNode.sourceType === projectObj.project.Bills.getSourceType();
+        let isLeafBill = isBill && treeNode.source.children && treeNode.source.children.length === 0;
+        let isBillPriceCalc = projectObj.project.projSetting.billsCalcMode === billsPrice;
+
+        if (isRation || (isLeafBill && isBillPriceCalc)) {
             projectObj.project.calcProgram.calculate(treeNode);
             if (treeNode.parent) {
                 projectObj.converseCalculateBills(treeNode.parent);
@@ -237,7 +243,7 @@ let calcProgramObj = {
             sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);
             sheetCommonObj.showData(me.sheet, me.setting, me.datas);
         }
-        else if (treeNode.sourceType === projectObj.project.Bills.getSourceType()) {
+        else if (isBill) {
             SheetDataHelper.loadSheetHeader(calcProgramSetting, me.sheet);
             SheetDataHelper.loadSheetData(calcProgramSetting, me.sheet, baseCalcField);
         }