chenshilong 7 years ago
parent
commit
6fc866a0ba

+ 152 - 144
web/building_saas/main/js/models/calc_program.js

@@ -118,24 +118,33 @@ const cpFeeTypes = [
     {type: 'fee1', name: '甲供材料费'},
     {type: 'common', name: '工程造价'}
 ];
-
 function getRationBaseFee(treeNode, gljTypes, priceType){
     if (!treeNode.data.gljList) return 0;
+    function uiGLJPrice(price){
+        if (price)
+            return parseFloat(price).toDecimal(decimalObj.glj.unitPrice)
+        else return 0;
+    };
+    function uiGLJQuantity(quantity){
+        if (quantity)
+            return parseFloat(quantity).toDecimal(decimalObj.glj.quantity)
+        else return 0;
+    };
     let result = 0;
     for (let glj of treeNode.data.gljList) {
         let price = 0, temp = 0;
         if (gljTypes.indexOf(glj.type) >= 0) {
             if (priceType == priceTypes.ptDiffPrice){
-                let aprice = glj["adjustPrice"] ? parseFloat(glj["adjustPrice"]) : 0;
-                let mprice = glj["marketPrice"] ? parseFloat(glj["marketPrice"]) : 0;
-                temp = (glj["quantity"] * mprice).toDecimal(decimalObj.ration.unitPrice) - (glj["quantity"] * aprice).toDecimal(decimalObj.ration.unitPrice);
+                let aprice = uiGLJPrice(glj["adjustPrice"]);
+                let mprice = uiGLJPrice(glj["marketPrice"]);
+                temp = (uiGLJQuantity(glj["quantity"]) * mprice).toDecimal(decimalObj.ration.unitPrice) - (uiGLJQuantity(glj["quantity"]) * aprice).toDecimal(decimalObj.ration.unitPrice);
                 temp = temp.toDecimal(decimalObj.ration.unitPrice);
             }
             else {
-                if (priceType == priceTypes.ptBasePrice){ price = parseFloat(glj["basePrice"]);}
-                else if (priceType == priceTypes.ptAdjustPrice){price = parseFloat(glj["adjustPrice"]);}
-                else if (priceType == priceTypes.ptMarketPrice){price = parseFloat(glj["marketPrice"]);}
-                temp = (glj["quantity"] * price).toDecimal(decimalObj.ration.unitPrice);
+                if (priceType == priceTypes.ptBasePrice){ price = uiGLJPrice(glj["basePrice"]);}
+                else if (priceType == priceTypes.ptAdjustPrice){price = uiGLJPrice(glj["adjustPrice"]);}
+                else if (priceType == priceTypes.ptMarketPrice){price = uiGLJPrice(glj["marketPrice"]);}
+                temp = (uiGLJQuantity(glj["quantity"]) * price).toDecimal(decimalObj.ration.unitPrice);
             };
 
             result = (result + temp).toDecimal(decimalObj.ration.unitPrice);
@@ -144,7 +153,6 @@ function getRationBaseFee(treeNode, gljTypes, priceType){
     return result;
 };
 
-// 定额计算基数。CSL, 2018-01-23
 const rationCalcBaser = {
     '定额基价人工费':
         function (node) {
@@ -203,6 +211,139 @@ const rationCalcBaser = {
         }
 };
 
+let nodeTools = {
+    isBill: function(treeNode){
+        return treeNode.sourceType === ModuleNames.bills;
+    },
+    isLeafBill: function(treeNode){
+        return treeNode.sourceType === ModuleNames.bills &&
+            treeNode.source.children &&
+            treeNode.source.children.length === 0;
+    },
+    isNullBill: function (treeNode) {
+        return this.isLeafBill(treeNode) && (treeNode.children.length === 0) && (!treeNode.data.calcBase);
+    },
+    isTotalCostBill: function (treeNode) {
+        return treeNode.data.flagsIndex && treeNode.data.flagsIndex.fixed && treeNode.data.flagsIndex.fixed.flag &&
+            treeNode.data.flagsIndex.fixed.flag == fixedFlag.ENGINEERINGCOST;
+    },
+
+    isRationCategory: function(treeNode){
+        return treeNode.sourceType === ModuleNames.ration;
+    },
+    isRation: function(treeNode){
+        return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.ration;
+    },
+    isVolumePrice: function (treeNode) {
+        return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.volumePrice;
+    },
+    isGljRation: function (treeNode) {
+        return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.gljRation;
+    },
+
+    initFees(treeNode){
+        if (!treeNode.data.fees) {
+            treeNode.data.fees = [];
+            treeNode.data.feesIndex = {};
+            treeNode.changed = true;
+        };
+    },
+    initFeeField(treeNode, fieldName){
+        this.initFees(treeNode);
+        if (!treeNode.data.feesIndex[fieldName]) {
+            let fee = {
+                'fieldName': fieldName,
+                'unitFee': 0,
+                'totalFee': 0,
+                'tenderUnitFee': 0,
+                'tenderTotalFee': 0
+            };
+            treeNode.data.fees.push(fee);
+            treeNode.data.feesIndex[fieldName] = fee;
+            treeNode.changed = true;
+        };
+    },
+    checkFeeField(treeNode, feeObj){
+        if (!feeObj) return;
+        if (feeObj.fieldName == '') return;
+
+        // 初始化前先拦截末定义的情况
+        if (!treeNode.data.feesIndex || !treeNode.data.feesIndex[feeObj.fieldName]){
+            if (feeObj.unitFee == 0 && feeObj.totalFee == 0) return;
+        }
+
+        this.initFeeField(treeNode, feeObj.fieldName);
+
+        if (treeNode.data.feesIndex[feeObj.fieldName].unitFee != feeObj.unitFee){
+            treeNode.data.feesIndex[feeObj.fieldName].unitFee = feeObj.unitFee;
+            treeNode.changed = true;
+        };
+
+        if (treeNode.data.feesIndex[feeObj.fieldName].totalFee != feeObj.totalFee){
+            treeNode.data.feesIndex[feeObj.fieldName].totalFee = feeObj.totalFee;
+            treeNode.changed = true;
+        };
+    },
+    initSummaryFee(treeNode){
+        if (!treeNode.data.summaryFees){
+            treeNode.data.summaryFees = {
+                totalFee: 0,
+                estimateFee: 0,
+                safetyFee: 0,
+                chargeFee: 0
+            };
+            treeNode.changed = true;
+        };
+    },
+    getCalcType(treeNode) {
+        if (this.isRationCategory(treeNode)){
+            return treeNodeCalcType.ctRationCalcProgram;
+        }
+        else if (this.isNullBill(treeNode)){
+            return treeNodeCalcType.ctNull;
+        }
+        else if (this.isLeafBill(treeNode)) {
+            if (treeNode.children && treeNode.children.length > 0){
+                // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
+                if (projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
+                    return treeNodeCalcType.ctBillCalcProgram;
+                else                                        // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
+                    return treeNodeCalcType.ctGatherRationsFees;
+            }
+            else{                                          // 公式计算
+                return treeNodeCalcType.ctCalcBaseValue;
+            };
+        }
+        else if (this.isBill(treeNode)) {                              // 父清单:汇总子清单的费用类别
+            return treeNodeCalcType.ctGatherBillsFees;
+        }
+        else {
+            return treeNodeCalcType.ctRationCalcProgram;
+        };
+    },
+    uiQuantity(treeNode){
+        return parseFloatPlus(treeNode.data.quantity).toDecimal(decimalObj.decimal("quantity", treeNode));
+    },
+
+    getFee(treeNode, fieldName) {    // fieldName: 'common.totalFee'、'equipment.unitFee'
+        let ns = fieldName.split(".");
+        if (ns.length != 2)
+            return 0
+        else if (treeNode.data.feesIndex[ns[0]] && treeNode.data.feesIndex[ns[0]][ns[1]])
+            return parseFloat(treeNode.data.feesIndex[ns[0]][ns[1]])
+        else
+            return 0;
+    },
+    getNodeByFlag(flag) {
+        let bill = cbTools.findBill(flag);
+        if (bill) return this.getNodeByID(bill.ID)
+        else return null;
+    },
+    getNodeByID(ID){
+        return cbTools.getNodeByID(ID);
+    }
+};
+
 let analyzer = {
     calcTemplate: null,
     success: true,
@@ -364,7 +505,7 @@ let executeObj = {
                 ( me.treeNode.data.subType === gljType.GENERAL_MACHINE && baseName === '定额基价机械费') ||
                 ( me.treeNode.data.subType === gljType.MAIN_MATERIAL && baseName === '主材费') ||
                 ( me.treeNode.data.subType === gljType.EQUIPMENT && baseName === '设备费')
-            ) result = me.treeNode.data.marketUnitFee ? me.treeNode.data.marketUnitFee : 0;
+            ) result = me.treeNode.data.marketUnitFee ? parseFloat(me.treeNode.data.marketUnitFee).toDecimal(decimalObj.ration.unitPrice) : 0;
             return result;
         };
 
@@ -383,139 +524,6 @@ let executeObj = {
     }
 };
 
-let nodeTools = {
-    isBill: function(treeNode){
-        return treeNode.sourceType === ModuleNames.bills;
-    },
-    isLeafBill: function(treeNode){
-        return treeNode.sourceType === ModuleNames.bills &&
-            treeNode.source.children &&
-            treeNode.source.children.length === 0;
-    },
-    isNullBill: function (treeNode) {
-        return this.isLeafBill(treeNode) && (treeNode.children.length === 0) && (!treeNode.data.calcBase);
-    },
-    isTotalCostBill: function (treeNode) {
-        return treeNode.data.flagsIndex && treeNode.data.flagsIndex.fixed && treeNode.data.flagsIndex.fixed.flag &&
-            treeNode.data.flagsIndex.fixed.flag == fixedFlag.ENGINEERINGCOST;
-    },
-
-    isRationCategory: function(treeNode){
-        return treeNode.sourceType === ModuleNames.ration;
-    },
-    isRation: function(treeNode){
-        return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.ration;
-    },
-    isVolumePrice: function (treeNode) {
-        return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.volumePrice;
-    },
-    isGljRation: function (treeNode) {
-        return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.gljRation;
-    },
-
-    initFees(treeNode){
-        if (!treeNode.data.fees) {
-            treeNode.data.fees = [];
-            treeNode.data.feesIndex = {};
-            treeNode.changed = true;
-        };
-    },
-    initFeeField(treeNode, fieldName){
-        this.initFees(treeNode);
-        if (!treeNode.data.feesIndex[fieldName]) {
-            let fee = {
-                'fieldName': fieldName,
-                'unitFee': 0,
-                'totalFee': 0,
-                'tenderUnitFee': 0,
-                'tenderTotalFee': 0
-            };
-            treeNode.data.fees.push(fee);
-            treeNode.data.feesIndex[fieldName] = fee;
-            treeNode.changed = true;
-        };
-    },
-    checkFeeField(treeNode, feeObj){
-        if (!feeObj) return;
-        if (feeObj.fieldName == '') return;
-
-        // 初始化前先拦截末定义的情况
-        if (!treeNode.data.feesIndex || !treeNode.data.feesIndex[feeObj.fieldName]){
-            if (feeObj.unitFee == 0 && feeObj.totalFee == 0) return;
-        }
-
-        this.initFeeField(treeNode, feeObj.fieldName);
-
-        if (treeNode.data.feesIndex[feeObj.fieldName].unitFee != feeObj.unitFee){
-            treeNode.data.feesIndex[feeObj.fieldName].unitFee = feeObj.unitFee;
-            treeNode.changed = true;
-        };
-
-        if (treeNode.data.feesIndex[feeObj.fieldName].totalFee != feeObj.totalFee){
-            treeNode.data.feesIndex[feeObj.fieldName].totalFee = feeObj.totalFee;
-            treeNode.changed = true;
-        };
-    },
-    initSummaryFee(treeNode){
-        if (!treeNode.data.summaryFees){
-            treeNode.data.summaryFees = {
-                totalFee: 0,
-                estimateFee: 0,
-                safetyFee: 0,
-                chargeFee: 0
-            };
-            treeNode.changed = true;
-        };
-    },
-    getCalcType(treeNode) {
-        if (this.isRationCategory(treeNode)){
-            return treeNodeCalcType.ctRationCalcProgram;
-        }
-        else if (this.isNullBill(treeNode)){
-            return treeNodeCalcType.ctNull;
-        }
-        else if (this.isLeafBill(treeNode)) {
-            if (treeNode.children && treeNode.children.length > 0){
-                // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
-                if (projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
-                    return treeNodeCalcType.ctBillCalcProgram;
-                else                                        // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
-                    return treeNodeCalcType.ctGatherRationsFees;
-            }
-            else{                                          // 公式计算
-                return treeNodeCalcType.ctCalcBaseValue;
-            };
-        }
-        else if (this.isBill(treeNode)) {                              // 父清单:汇总子清单的费用类别
-            return treeNodeCalcType.ctGatherBillsFees;
-        }
-        else {
-            return treeNodeCalcType.ctRationCalcProgram;
-        };
-    },
-    uiQuantity(treeNode){
-        return parseFloatPlus(treeNode.data.quantity).toDecimal(decimalObj.decimal("quantity", treeNode));
-    },
-
-    getFee(treeNode, fieldName) {    // fieldName: 'common.totalFee'、'equipment.unitFee'
-        let ns = fieldName.split(".");
-        if (ns.length != 2)
-            return 0
-        else if (treeNode.data.feesIndex[ns[0]] && treeNode.data.feesIndex[ns[0]][ns[1]])
-            return parseFloat(treeNode.data.feesIndex[ns[0]][ns[1]])
-        else
-            return 0;
-    },
-    getNodeByFlag(flag) {
-         let bill = cbTools.findBill(flag);
-         if (bill) return this.getNodeByID(bill.ID)
-         else return null;
-    },
-    getNodeByID(ID){
-        return cbTools.getNodeByID(ID);
-    }
-};
-
 class CalcProgram {
     constructor(project){
         let me = this;
@@ -1237,4 +1245,4 @@ class CalcProgram {
         calcNodes(me.project.mainTree.roots);
         return rst;
     };
-}
+};

+ 3 - 47
web/building_saas/main/js/views/project_view.js

@@ -180,50 +180,6 @@ var projectObj = {
             return this.checkCommonField(editingText, colSetting);
         }
     },
-    /*updateAndReCalculate: function (node, fieldName, value) {
-        let project = projectObj.project, calc = new BillsCalcHelper(project), nodes = [];
-        let getNodes = function (node) {
-            let cur = node, nodes = [];
-            while (cur) {
-                nodes.push(cur);
-                cur = cur.parent;
-            }
-            return nodes;
-        }
-        if (value) {
-            value = value.toDecimal(projectObj.project.Decimal.common.quantity);
-        }
-        if (node.sourceType === projectObj.project.Bills.getSourceType()) {
-            calcFees.setFee(node.data, fieldName, value);
-            calc.calcNode(node, true);
-            nodes = getNodes(node);
-            project.Bills.updateNodes(nodes, true);
-        }
-        else if (node.sourceType === projectObj.project.VolumePrice.getSourceType()) {
-            project.beginUpdate('VolumePrice_QuantityChange');
-            project.VolumePrice.updateField(node.source, fieldName, value, false);
-            calc.calcNode(node.parent, true);
-            nodes = getNodes(node.parent);
-            project.Bills.updateNodes(nodes, false);
-            project.endUpdate();
-            nodes.push(node);
-        }
-        else if (node.sourceType === projectObj.project.Ration.getSourceType()) {
-            project.beginUpdate('Ration_QuantityChange');
-            calcFees.setFee(node.data, fieldName, value);
-            node.data.gljList = project.ration_glj.getGljArrByRation(node.data.ID);
-            // calcProgram.calculate的传参必须是cacheNode类型,故无法将计算放在Ration模块中。
-            project.calcProgram.calculate(node);
-            project.Ration.updateRation(node.source, false);    // 加入待存储队列
-            calc.calcNode(node.parent, true);       //
-            nodes = getNodes(node.parent);
-            project.Bills.updateNodes(nodes, false);
-            project.endUpdate();
-            nodes.push(node);
-        }
-        this.mainController.refreshTreeNode(nodes, false);
-        calc = null;
-    },*/
     updateBillsCode: function (node, value) {
         let project = projectObj.project;
         let stdMatchCode, formatCode, matchs;
@@ -1112,8 +1068,8 @@ $('#property_ok').click(function () {
             bills: bills
         },
 
-        reCalcBills= false,
-        reCalcRations= false;
+        reCalcBills = false,
+        reCalcRations = false;
 
     let b = parseInt($("input[name='calcFlag']:checked").val());
     if (b !== project.property.billsCalcMode) {
@@ -1126,7 +1082,7 @@ $('#property_ok').click(function () {
     if (zg !== project.property.zanguCalcMode) {
         properties['property.zanguCalcMode'] = zg;
         project.property.zanguCalcMode = zg;
-        reCalcBills = true;
+        reCalcRations = true;
     };
 
     //基本信息