Przeglądaj źródła

Merge branch 'master' of http://192.168.1.12:3000/SmartCost/ConstructionCost

TonyKang 7 lat temu
rodzic
commit
12ac1fb70b
1 zmienionych plików z 34 dodań i 17 usunięć
  1. 34 17
      web/building_saas/main/js/models/calc_program.js

+ 34 - 17
web/building_saas/main/js/models/calc_program.js

@@ -272,23 +272,26 @@ let executeObj = {
 
             // 机上人工费:多一层
             if (isSubset(base.gljTypes, [gljType.MACHINE_LABOUR])) {
-                for (let glj of me.treeNode.data.gljList) {
-                    if (glj.type == gljType.GENERAL_MACHINE) {
-                        // 获取机械组成物
-                        let mds = projectObj.project.composition.getCompositionByCode(glj.code);
-                        if (!mds) mds = [];
-                        for (let md of mds){
-                            if (base.gljTypes.indexOf(md.glj_type) >= 0) {
-                                price = md["base_price"];
-                                if (!price) price = 0;
-                                mdSum = mdSum + (md["consumption"] * price).toDecimal(me.digit);
-                                mdSum = (mdSum).toDecimal(me.digitDefault);
-                            }
-                        };
-                        tmpSum = tmpSum + (glj["quantity"] * mdSum).toDecimal(me.digitDefault);
-                        tmpSum = (tmpSum).toDecimal(me.digitDefault);
-                    }
-                };
+                if (!me.treeNode.data.gljList) tmpSum = 0
+                else{
+                    for (let glj of me.treeNode.data.gljList) {
+                        if (glj.type == gljType.GENERAL_MACHINE) {
+                            // 获取机械组成物
+                            let mds = projectObj.project.composition.getCompositionByCode(glj.code);
+                            if (!mds) mds = [];
+                            for (let md of mds){
+                                if (base.gljTypes.indexOf(md.glj_type) >= 0) {
+                                    price = md["base_price"];
+                                    if (!price) price = 0;
+                                    mdSum = mdSum + (md["consumption"] * price).toDecimal(me.digit);
+                                    mdSum = (mdSum).toDecimal(me.digitDefault);
+                                }
+                            };
+                            tmpSum = tmpSum + (glj["quantity"] * mdSum).toDecimal(me.digitDefault);
+                            tmpSum = (tmpSum).toDecimal(me.digitDefault);
+                        }
+                    };
+                }
             }else{
                 if (!me.treeNode.data.gljList) tmpSum = 0
                 else{
@@ -657,6 +660,7 @@ class CalcProgram {
             treeNode.calcType = treeNodeCalcType.ctRationCalcProgram
         else if (isLeafBill) {
             if (treeNode.children && treeNode.children.length > 0){
+                me.calcLeafBillChildren(treeNode);
                 if (treeNode.children[0].sourceType == me.project.Ration.getSourceType()){
                     if (isBillPriceCalc)                   // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算
                         treeNode.calcType = treeNodeCalcType.ctBillCalcProgram;
@@ -759,4 +763,17 @@ class CalcProgram {
         calcNodes(me.project.mainTree.roots);
         me.saveNodes(needSaveNodes);
     };
+
+    // 重新计算叶子清单下的所有子结点:如定额、工料机定额等(calculate算法基于定额、工料机定额的计算结果是正确的,实际上有时它们的计算结果并不是最新的)
+    calcLeafBillChildren(treeNode){
+        let me = this;
+        if (treeNode.children && treeNode.children.length > 0) {
+            let needSaveNodes = [];
+            for (let child of treeNode.children){
+                me.calculate(child, false);
+                if (child.changed) needSaveNodes.push(child);
+            };
+            me.saveNodes(needSaveNodes);
+        };
+    };
 }