Selaa lähdekoodia

定额基数结构调整。

chenshilong 7 vuotta sitten
vanhempi
commit
993e713baa

+ 2 - 2
config/gulpConfig.js

@@ -83,8 +83,8 @@ module.exports = {
         'public/web/id_tree.js',
         'web/building_saas/main/js/models/cache_tree.js',
         'web/building_saas/main/js/calc/calc_fees.js',
-        'web/building_saas/main/js/calc/ration_calc.js',
-        'web/building_saas/main/js/calc/bills_calc.js',
+        // 'web/building_saas/main/js/calc/ration_calc.js',
+        // 'web/building_saas/main/js/calc/bills_calc.js',
         // 'public/calc_util.js',
         'public/web/tree_sheet/tree_sheet_controller.js',
         'public/web/tree_sheet/tree_sheet_helper.js',

+ 8 - 0
public/web/common_util.js

@@ -27,3 +27,11 @@ function mergeArr(arr1, arr2){
         };
     }
 };
+
+// 判断 sub 是否是 arr 的子数组。
+function isSubArr(sub, arr){
+    for(var i = 0, len = sub.length; i < len; i++){
+        if(arr.indexOf(sub[i]) == -1) return false;
+    }
+    return true;
+};

+ 2 - 2
web/building_saas/main/html/main.html

@@ -867,8 +867,8 @@
         <script type="text/javascript" src="/public/web/id_tree.js"></script>
         <script type="text/javascript" src="/web/building_saas/main/js/models/cache_tree.js"></script>
         <script type="text/javascript" src="/web/building_saas/main/js/calc/calc_fees.js"></script>
-        <script type="text/javascript" src="/web/building_saas/main/js/calc/ration_calc.js"></script>
-        <script type="text/javascript" src="/web/building_saas/main/js/calc/bills_calc.js"></script>
+        <!--<script type="text/javascript" src="/web/building_saas/main/js/calc/ration_calc.js"></script>-->
+        <!--<script type="text/javascript" src="/web/building_saas/main/js/calc/bills_calc.js"></script>-->
         <!--<script type="text/javascript" src="/public/calc_util.js"></script>-->
         <!-- Controller -->
         <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_controller.js"></script>

+ 12 - 12
web/building_saas/main/js/calc/bills_calc.js

@@ -5,14 +5,14 @@
 // const rationContent = 0, rationPrice = 1, rationPriceConverse = 2, billsPrice = 3;
 
 // sumTotalFeeFlag: sum(child.totalFee), totalFeeFlag: bills.quantity × bills.unitFee
-const sumTotalFeeFlag = 0, totalFeeFlag = 1;
+// const sumTotalFeeFlag = 0, totalFeeFlag = 1;
 // rationContentUnitFeeFlag: sum(child.unitFee * child.quantity / bills.quantity)
 // averageQtyUnitFeeFlag: sum(child.totalFee/bills.quantity)
 // billsPriceUnitFeeFlag: 根据定额计算程序
 // converseUnitFeeFalg: bills.totalFee / bills.quantity
-const rationContentUnitFeeFlag = 0, averageQtyUnitFeeFlag = 1, billsPriceUnitFeeFlag = 2, converseUnitFeeFlag = 3;
+// const rationContentUnitFeeFlag = 0, averageQtyUnitFeeFlag = 1, billsPriceUnitFeeFlag = 2, converseUnitFeeFlag = 3;
 
-let rationContentCalcFields = [
+/*let rationContentCalcFields = [
     {'type': 'common', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': totalFeeFlag},
     {'type': 'labour', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
     {'type': 'material', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
@@ -35,9 +35,9 @@ let billsPriceCalcFields = [
     {'type': 'labour', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
     {'type': 'material', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
     {'type': 'machine', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag}
-];
+];*/
 
-let nodeCalcObj = {
+/*let nodeCalcObj = {
     node: null,
     digit: 2,
     field: null,
@@ -98,9 +98,9 @@ let nodeCalcObj = {
             return 0;
         }
     }
-};
+};*/
 
-let baseCalcField = [
+/*let baseCalcField = [
     {
         ID: 1,
         // 序号
@@ -246,9 +246,9 @@ let baseCalcField = [
         // 备注
         memo: ''
     }
-];
+];*/
 
-class BillsCalcHelper {
+/*class BillsCalcHelper {
     constructor (project, calcFlag) {
         this.project = project;
         this.InitFields(project.calcFields);
@@ -269,12 +269,12 @@ class BillsCalcHelper {
 
         // 清单单价:套用定额计算程序
         // if (this.project.projSetting.billsCalcMode === billsPrice) {
-        if (this.project.property.billsCalcMode === leafBillGetFeeType.billsPrice) {
+/!*        if (this.project.property.billsCalcMode === leafBillGetFeeType.billsPrice) {
             rationCalcObj.calcGljs = this.getBillsGLjs(node);
             console.log(rationCalcObj.calcGljs);
             rationCalcObj.calcFields = rationCalcFields;
             virData = rationCalcObj.calculate();
-        }
+        }*!/
 
         for (let field of fields) {
             nodeCalcObj.field = field;
@@ -396,4 +396,4 @@ class BillsCalcHelper {
             field.tenderTotalFeeSplit = field.tenderTotalFee.split('.');
         }
     };
-}
+}*/

+ 9 - 11
web/building_saas/main/js/calc/ration_calc.js

@@ -96,15 +96,13 @@ let rationCalcFields = [
     }
 ];
 */
-"use strict";
+// let calcEvaluate = function (expr) {
+//     let exp = new Expression('');
+//     exp.Expression(expr);
+//     return exp.Evaluate();
+// }
 
-let calcEvaluate = function (expr) {
-    let exp = new Expression('');
-    exp.Expression(expr);
-    return exp.Evaluate();
-}
-
-let rationCalcFields = [
+/*let rationCalcFields = [
     {
         type: 'rationBaseLabour', code: "1.1.1", name: "定额基价人工费",
         dispExpr: "定额基价人工费", expression: "定额基价人工费", compiledExpr: "",
@@ -301,9 +299,9 @@ let rationCalcObj = {
         }
         return result;
     }
-};
+};*/
 
-class RationCalcHelper {
+/*class RationCalcHelper {
     constructor (project) {
         this.project = project;
     }
@@ -327,4 +325,4 @@ class RationCalcHelper {
             this.calculate(rationData);
         }
     };
-}
+}*/

+ 109 - 155
web/building_saas/main/js/models/calc_program.js

@@ -98,57 +98,8 @@ let defaultBillTemplate = {
     ]
 };*/
 
-const baseCalcType = {baseCalc: 0, adjustCalc: 1, budgetCalc: 2, diffCalc: 3,  offerCalc: 4};
-
-let rationCalcBase = [
-    {
-        'dispName': '定额基价人工费',
-        'calcType': baseCalcType.baseCalc,
-        'gljTypes': [gljType.LABOUR]
-    },
-    {
-        'dispName': '定额基价材料费',
-        'calcType': baseCalcType.baseCalc,
-        'gljTypes': [gljType.GENERAL_MATERIAL, gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]
-    },
-    {
-        'dispName': '定额基价机械费',
-        'calcType': baseCalcType.baseCalc,
-        'gljTypes': [gljType.GENERAL_MACHINE]
-    },
-    {
-        'dispName': '定额基价机上人工费',
-        'calcType': baseCalcType.baseCalc,
-        'gljTypes': [gljType.MACHINE_LABOUR]
-    },
-    {
-        'dispName': '人工费价差',
-        'calcType': baseCalcType.diffCalc,
-        'gljTypes': [gljType.LABOUR]
-    },
-    {
-        'dispName': '材料费价差',
-        'calcType': baseCalcType.diffCalc,
-        'gljTypes': [gljType.GENERAL_MATERIAL, gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]
-    },
-    {
-        'dispName': '机械费价差',
-        'calcType': baseCalcType.diffCalc,
-        'gljTypes': [gljType.GENERAL_MACHINE]
-    },
-    {
-        'dispName': '主材费',
-        'calcType': baseCalcType.budgetCalc,
-        'gljTypes': [gljType.MAIN_MATERIAL]
-    },
-    {
-        'dispName': '设备费',
-        'calcType': baseCalcType.budgetCalc,
-        'gljTypes': [gljType.EQUIPMENT]
-    }
-];
-
-let cpFeeTypes = [
+const priceTypes = {ptBasePrice: 1, ptAdjustPrice: 2, ptMarketPrice: 3, ptDiffPrice: 4};
+const cpFeeTypes = [
     {type: 'direct', name: '直接费'},
     {type: 'labour', name: '人工费'},
     {type: 'material', name: '材料费'},
@@ -165,10 +116,93 @@ let cpFeeTypes = [
     {type: 'adjustMachineLabour', name: '调整机上人工费'},
     {type: 'estimate', name: '暂估费'},
     {type: 'fee1', name: '甲供材料费'},
-    // 模拟用户新增
     {type: 'common', name: '工程造价'}
 ];
 
+function getRationBaseFee(treeNode, gljTypes, priceType){
+    if (!treeNode.data.gljList) 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);
+                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);
+            };
+
+            result = (result + temp).toDecimal(decimalObj.ration.unitPrice);
+        };
+    };
+    return result;
+};
+
+// 定额计算基数。CSL, 2018-01-23
+const rationCalcBaser = {
+    '定额基价人工费':
+        function (node) {
+            return getRationBaseFee(node, [gljType.LABOUR], priceTypes.ptBasePrice);
+        },
+    '定额基价材料费':
+        function (node) {
+            return getRationBaseFee(node, baseMaterialTypes, priceTypes.ptBasePrice);
+        },
+    '定额基价机械费':
+        function (node) {
+            return getRationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptBasePrice);
+        },
+    '定额基价机上人工费':
+        function machineLabourFee(node) {
+            if (!node.data.gljList) return 0;
+            let result = 0, mdSum = 0;
+            for (let glj of node.data.gljList) {
+                if (glj.type == gljType.GENERAL_MACHINE) {
+                    // 获取机械组成物
+                    let mds = projectObj.project.composition.getCompositionByGLJ(glj);
+                    if (!mds) mds = [];
+                    for (let md of mds) {
+                        if (md.type == gljType.MACHINE_LABOUR) {
+                            let q = md["consumption"] ? md["consumption"] : 0;
+                            let p = md["basePrice"] ? md["basePrice"] : 0;
+                            mdSum = mdSum + (q * p).toDecimal(decimalObj.process);
+                            mdSum = (mdSum).toDecimal(decimalObj.process);
+                        }
+                    };
+                    result = result + (glj["quantity"] * mdSum).toDecimal(decimalObj.process);
+                    result = (result).toDecimal(decimalObj.process);
+                };
+            };
+            return result;
+        },
+    '人工费价差':
+        function (node) {
+            return getRationBaseFee(node, [gljType.LABOUR], priceTypes.ptDiffPrice);
+        },
+    '材料费价差':
+        function (node) {
+            return getRationBaseFee(node, baseMaterialTypes, priceTypes.ptDiffPrice);
+        },
+    '机械费价差':
+        function (node) {
+            return getRationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptDiffPrice);
+        },
+    '主材费':
+        function (node) {
+            return getRationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptMarketPrice);
+        },
+    '设备费':
+        function (node) {
+            return getRationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptMarketPrice);
+        }
+};
+
 let analyzer = {
     calcTemplate: null,
     success: true,
@@ -313,101 +347,32 @@ let analyzer = {
 let executeObj = {
     treeNode: null,
     template: null,
-    calcBase: null,
 
     at: function(ID) {
-        let me = executeObj,
-            rst = 0;
-        rst = me.template.compiledCalcItems[ID].unitFee;
+        let me = executeObj;
+        let rst = me.template.compiledCalcItems[ID].unitFee;
         rst = parseFloat(rst);
         return rst;
     },
-    base: function(calcBaseName) {
-        let me = executeObj, rst = 0,
-            base = me.calcBase[calcBaseName];
-
-        if (base != null) {
-            function isSubset(sub, arr){
-                for(var i = 0, len = sub.length; i < len; i++){
-                    if(arr.indexOf(sub[i]) == -1) return false;
-                }
-                return true;
-            };
-            // 机上人工费:多一层
-            function machineLabourFee() {
-                if (!me.treeNode.data.gljList) return 0;
-                let result = 0, mdSum = 0;
-                for (let glj of me.treeNode.data.gljList) {
-                    if (glj.type == gljType.GENERAL_MACHINE) {
-                        // 获取机械组成物
-                        let mds = projectObj.project.composition.getCompositionByGLJ(glj);
-                        if (!mds) mds = [];
-                        for (let md of mds){
-                            if (base.gljTypes.indexOf(md.type) >= 0) {
-                                let q = md["consumption"] ? md["consumption"] : 0;
-                                let p = md["basePrice"] ? md["basePrice"] : 0;
-                                mdSum = mdSum + (q * p).toDecimal(decimalObj.process);
-                                mdSum = (mdSum).toDecimal(decimalObj.process);
-                            }
-                        };
-                        result = result + (glj["quantity"] * mdSum).toDecimal(decimalObj.process);
-                        result = (result).toDecimal(decimalObj.process);
-                    };
-                };
-                return result;
-            };
-            function commonGLJFee(){
-                if (!me.treeNode.data.gljList) return 0;
-                let result = 0;
-                for (let glj of me.treeNode.data.gljList) {
-                    let price = 0, temp = 0;
-                    if (base.gljTypes.indexOf(glj.type) >= 0) {
-                        if (base.calcType == baseCalcType.diffCalc){
-                            let aprice = glj["adjustPrice"] ? glj["adjustPrice"] : 0;
-                            aprice = parseFloat(aprice);
-                            let mprice = glj["marketPrice"] ? glj["marketPrice"] : 0;
-                            mprice = parseFloat(mprice);
-                            temp = (glj["quantity"] * mprice).toDecimal(decimalObj.ration.unitPrice) - (glj["quantity"] * aprice).toDecimal(decimalObj.ration.unitPrice);
-                            temp = temp.toDecimal(decimalObj.ration.unitPrice);
-                        }
-                        else {
-                            if (base.calcType == baseCalcType.baseCalc){ price = parseFloat(glj["basePrice"]);}
-                            else if (base.calcType == baseCalcType.adjustCalc){price = parseFloat(glj["adjustPrice"]);}
-                            else if (base.calcType == baseCalcType.budgetCalc){price = parseFloat(glj["marketPrice"]);}
-                            temp = (glj["quantity"] * price).toDecimal(decimalObj.ration.unitPrice);
-                        };
-
-                        result = (result + temp).toDecimal(decimalObj.ration.unitPrice);
-                    };
-                };
-                return result;
-            };
-            // 量价、工料机形式的定额, 要把自己的市场单价用于计算程序中的基数。
-            function marketPriceToBase() {
-                let result = 0;
-                if (
-                    ( me.treeNode.data.subType === gljType.LABOUR && base.dispName === '定额基价人工费') ||
-                    ( baseMaterialTypes.includes(me.treeNode.data.subType) && base.dispName === '定额基价材料费') ||
-                    ( me.treeNode.data.subType === gljType.GENERAL_MACHINE && base.dispName === '定额基价机械费') ||
-                    ( me.treeNode.data.subType === gljType.MAIN_MATERIAL && base.dispName === '主材费') ||
-                    ( me.treeNode.data.subType === gljType.EQUIPMENT && base.dispName === '设备费')
-                ) result = me.treeNode.data.marketUnitFee ? me.treeNode.data.marketUnitFee : 0;
-
-                return result;
-            };
-
-            if (me.treeNode.data.type == rationType.volumePrice || me.treeNode.data.type == rationType.gljRation){
-                rst = marketPriceToBase();
-            }
-            else{
-                if (isSubset(base.gljTypes, [gljType.MACHINE_LABOUR]))
-                    rst = machineLabourFee()
-                else
-                    rst = commonGLJFee();
-            }
+    base: function(baseName) {
+        let me = executeObj;
+        function marketPriceToBase(baseName) {
+            let result = 0;
+            if (
+                ( me.treeNode.data.subType === gljType.LABOUR && baseName === '定额基价人工费') ||
+                ( baseMaterialTypes.includes(me.treeNode.data.subType) && baseName === '定额基价材料费') ||
+                ( 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;
+            return result;
         };
 
-        return rst;
+        // 量价、工料机形式的定额, 要把自己的市场单价用于计算程序中的基数。
+        if (me.treeNode.data.type == rationType.volumePrice || me.treeNode.data.type == rationType.gljRation)
+            return marketPriceToBase(baseName)
+        else
+            return rationCalcBaser[baseName](me.treeNode);
     },
     HJ: function () {
         let me = this;
@@ -593,7 +558,7 @@ class CalcProgram {
         me.feeRates = this.project.FeeRate.datas.rates;
         me.labourCoes = this.project.labourCoe.datas.coes;
         me.feeTypes = cpFeeTypes;
-        me.calcBases = rationCalcBase;
+        // me.calcBases = rationCalcBase;
         me.templates = this.project.calcProgram.datas.templates;
 
         // me.templates.push(defaultBillTemplate);
@@ -630,9 +595,9 @@ class CalcProgram {
             me.compiledFeeTypeNames.push(ft.name);
         }
 
-        for (let cb of me.calcBases) {
+/*        for (let cb of me.calcBases) {
             me.compiledCalcBases[cb.dispName] = cb;         // 中文预编译,可靠性有待验证
-        }
+        }*/
     };
 
     compileTemplate(template){
@@ -1091,7 +1056,6 @@ class CalcProgram {
                 let $CE = executeObj;
                 $CE.treeNode = treeNode;
                 $CE.template = template;
-                $CE.calcBase = me.compiledCalcBases;
 
                 nodeTools.initFees(treeNode);
 
@@ -1243,6 +1207,7 @@ class CalcProgram {
         let changedNodes = this.calculate(treeNode);
         this.saveNodes(changedNodes);
     };
+
     calcAllNodesAndSave(calcType = calcAllType.catAll){
         let changedNodes = this.calcAllNodes(calcType);
         this.saveNodes(changedNodes);
@@ -1255,17 +1220,6 @@ class CalcProgram {
         let rst = 0;
 
         function calcNodes(nodes) {
-            /*for (let node of nodes) {
-                if (node.children.length > 0) {
-                    calcNodes(node.children);
-                }
-                else{
-                    if (!excludeNodes.includes(node) && node.sourceType != ModuleNames.ration_glj) {
-                        rst = (rst + nodeTools.getFee(node, 'common.totalFee')).toDecimal(decimalObj.bills.totalPrice);
-                    };
-                }
-            }*/
-
             for (let node of nodes) {
                 if (!excludeNodes.includes(node)){
                     if (node.children.length > 0) {