Browse Source

项目属性清单计算的前三种取费方式下3种不同的算法。

Chenshilong 7 years atrás
parent
commit
15cac257ba

+ 1 - 0
web/building_saas/main/js/calc/calc_fees.js

@@ -18,6 +18,7 @@ let feeType = [
     {type: 'material', name: '材料费'},
     {type: 'machine', name: '机械费'},
     {type: 'mainMaterial', name: '主材费'},
+    {type: 'equipment', name: '设备费'},
     {type: 'manage', name: '企业管理费'},
     {type: 'profit', name: '利润'},
     {type: 'risk', name: '风险费'},

+ 69 - 23
web/building_saas/main/js/models/calc_program.js

@@ -343,10 +343,10 @@ let executeObj = {
                 for (let glj of me.treeNode.data.gljList) {
                     let price = 0;
                     if (base.gljTypes.indexOf(glj.type) >= 0) {
-                        if (base.calcType == baseCalc){ price = parseFloat(glj["basePrice"]);}
-                        else if (base.calcType == adjustCalc){price = parseFloat(glj["adjustPrice"]);}
-                        else if (base.calcType == budgetCalc){price = parseFloat(glj["marketPrice"]);}
-                        else if (base.calcType == diffCalc){
+                        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"]);}
+                        else if (base.calcType == baseCalcType.diffCalc){
                             let aprice = glj["adjustPrice"] ? glj["adjustPrice"] : 0;
                             let mprice = glj["marketPrice"] ? glj["marketPrice"] : 0;
                             price = (parseFloat(mprice) - parseFloat(aprice)).toDecimal(me.digitDefault);
@@ -639,32 +639,76 @@ class CalcProgram {
             };
         };
 
+        function isBaseFeeType(type){
+            return ['labour', 'material', 'machine', 'mainMaterial', 'equipment'].indexOf(type) > -1;
+        };
+
         // 汇总定额或子清单的费用类别
-        if (treeNode.calcType == treeNodeCalcType.ctGatherRations || treeNode.calcType == treeNodeCalcType.ctGatherBills){
+        if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees || treeNode.calcType == treeNodeCalcType.ctGatherBillsFees){
             treeNode.data.programID = null;
             initFees(treeNode);
 
-            let objsArr = (treeNode.calcType == treeNodeCalcType.ctGatherRations) ? project.Ration.getRationsByNode(treeNode) : treeNode.children;
+            let objsArr = (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees) ? project.Ration.getRationsByNode(treeNode) : treeNode.children;
             let rst = [];
             for (let ft of feeType) {
                 let ftObj = {};
                 ftObj.fieldName = ft.type;
                 ftObj.name = ft.name;
-                let uf = 0, tf = 0, tuf = 0, ttf = 0;
-                for (let item of objsArr) {
-                    let data = (treeNode.calcType == treeNodeCalcType.ctGatherRations) ? item : item.data;
-                    if (data.feesIndex && data.feesIndex[ft.type]) {
-                        uf = (uf + parseFloat(data.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault);
-                        tf = (tf + parseFloat(data.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault);
-                        tuf = (tuf + parseFloat(data.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault);
-                        ttf = (ttf + parseFloat(data.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault);
+                let buf = 0, btf = 0, btuf = 0, bttf = 0;
+
+                if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees){
+                    for (let item of objsArr) {
+                        let data = item.data;
+                        if (data.feesIndex && data.feesIndex[ft.type]) {
+                            buf = (buf + parseFloat(data.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault);
+                            btf = (btf + parseFloat(data.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault);
+                            btuf = (btuf + parseFloat(data.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault);
+                            bttf = (bttf + parseFloat(data.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault);
+                        };
+                    };
+                }
+                else if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){     // 这里的算法要配合冷姐姐的神图才能看懂^_^
+                    let sum_rtf = 0, sum_rttf = 0;
+                    let bq = parseFloat(treeNode.data.quantity ? treeNode.data.quantity : 1);
+
+                    for (let data of objsArr) {
+                        let rq = parseFloat(data.quantity ? data.quantity : 0);
+
+                        let ruf = 0, rtuf = 0, rtf = 0, rttf = 0;
+                        if (data.feesIndex && data.feesIndex[ft.type]) {
+                            ruf = parseFloat(data.feesIndex[ft.type].unitFee);
+                            rtuf = parseFloat(data.feesIndex[ft.type].tenderUnitFee);
+                            rtf = parseFloat(data.feesIndex[ft.type].totalFee);
+                            rttf = parseFloat(data.feesIndex[ft.type].tenderTotalFee);
+                        };
+
+                        if (me.project.projSetting.billsCalcMode === leafBillGetFeeType.rationContent) {
+                            buf = (buf + (ruf * rq / bq).toDecimal(2)).toDecimal(2);
+                            btuf = (btuf + (rtuf * rq / bq).toDecimal(2)).toDecimal(2);
+                        };
+
+                        sum_rtf = (sum_rtf + rtf).toDecimal(2);
+                        sum_rttf = (sum_rttf + rttf).toDecimal(2);
+                    };
+
+                    if (me.project.projSetting.billsCalcMode === leafBillGetFeeType.rationPrice || me.project.projSetting.billsCalcMode === leafBillGetFeeType.rationPriceConverse) {
+                        buf = (sum_rtf / bq).toDecimal(2);
+                        btuf = (sum_rttf / bq).toDecimal(2);
+                    };
+                    if (isBaseFeeType(ft.type) || (me.project.projSetting.billsCalcMode === leafBillGetFeeType.rationPriceConverse && ft.type == "common")){
+                        btf = sum_rtf;
+                        bttf = sum_rttf;
+                    }
+                    else{
+                        btf = (buf * bq).toDecimal(2);
+                        bttf = (btuf * bq).toDecimal(2);
                     };
                 };
-                ftObj.unitFee = uf.toDecimal(me.digit);
-                ftObj.totalFee = tf.toDecimal(me.digit);
-                ftObj.tenderUnitFee = tuf.toDecimal(me.digit);
-                ftObj.tenderTotalFee = ttf.toDecimal(me.digit);
 
+                ftObj.unitFee = buf;
+                ftObj.totalFee = btf;
+                ftObj.tenderUnitFee = btuf;
+                ftObj.tenderTotalFee = bttf;
                 checkFee(treeNode, ftObj);
 
                 rst.push(ftObj);
@@ -742,25 +786,26 @@ class CalcProgram {
         let isRation = treeNode.sourceType === me.project.Ration.getSourceType();
         let isBill = treeNode.sourceType === me.project.Bills.getSourceType();
         let isBillPriceCalc = me.project.projSetting.billsCalcMode === leafBillGetFeeType.billsPrice;
+        let isLeafBill = me.isLeafBill(treeNode);
 
         if (isRation){
             treeNode.calcType = treeNodeCalcType.ctRationCalcProgram;
         }
-        else if (me.isLeafBill(treeNode)) {
+        else if (isLeafBill) {
             if (treeNode.children && treeNode.children.length > 0){
-                me.calcLeafBillChildren(treeNode);
+                // me.calcLeafBillChildren(treeNode);
 
-                if (isBillPriceCalc)                        // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算
+                if (isBillPriceCalc)                        // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
                     treeNode.calcType = treeNodeCalcType.ctBillCalcProgram;
                 else                                        // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
-                    treeNode.calcType = treeNodeCalcType.ctGatherRations;
+                    treeNode.calcType = treeNodeCalcType.ctGatherRationsFees;
             }
             else{                                          // 公式计算
                 treeNode.calcType = treeNodeCalcType.ctCalcBaseValue;
             };
         }
         else if (isBill)                                 // 父清单:汇总子清单的费用类别
-            treeNode.calcType = treeNodeCalcType.ctGatherBills;
+            treeNode.calcType = treeNodeCalcType.ctGatherBillsFees;
 
         me.InnerCalc(treeNode);
 
@@ -848,6 +893,7 @@ class CalcProgram {
     // 重新计算叶子清单下的所有子结点:如定额、工料机定额等(calculate算法基于定额、工料机定额的计算结果是正确的,实际上有时它们的计算结果并不是最新的)
     calcLeafBillChildren(treeNode){
         let me = this;
+        if(!me.isLeafBill(treeNode)) return;
         if (treeNode.children && treeNode.children.length > 0) {
             let needSaveNodes = [];
             for (let child of treeNode.children){

+ 3 - 3
web/building_saas/main/js/models/main_consts.js

@@ -69,9 +69,9 @@ const CP_Col_Width = {          // 多处计算程序界面的列宽统一设置
 
 const treeNodeCalcType = {
     ctRationCalcProgram: 1,
-    ctBillCalcProgram: 2,
-    ctGatherRations: 3,
-    ctGatherBills: 4,
+    ctBillCalcProgram: 2,       // 汇总清单下所有定额的工料机
+    ctGatherRationsFees: 3,     // 汇总定额的各个费
+    ctGatherBillsFees: 4,       // 汇总清单的各个费
     ctCalcBaseValue: 5
 };