Browse Source

暂估费结构大调整。

chenshilong 7 years ago
parent
commit
8010038b4b

+ 86 - 84
web/building_saas/main/js/models/calc_program.js

@@ -102,8 +102,13 @@ let calcTools = {
     isBill: function(treeNode){
         return treeNode.sourceType === ModuleNames.bills;
     },
+    isParentBill: function (treeNode) {
+        return this.isBill(treeNode) &&
+            treeNode.source.children &&
+            treeNode.source.children.length > 0;
+    },
     isLeafBill: function(treeNode){
-        return treeNode.sourceType === ModuleNames.bills &&
+        return this.isBill(treeNode) &&
             treeNode.source.children &&
             treeNode.source.children.length === 0;
     },
@@ -126,6 +131,21 @@ let calcTools = {
     isGljRation: function (treeNode) {
         return this.isRationCategory(treeNode) && treeNode.data.type === rationType.gljRation;
     },
+    getGLJList: function (treeNode) {
+        delete treeNode.data.gljList;
+        if (this.isRationCategory(treeNode)) {
+            if (treeNode.data.type != rationType.volumePrice) {
+                treeNode.data.gljList = projectObj.project.ration_glj.getGljArrByRation(treeNode.data);
+            };
+        }
+        else if (this.isBill(treeNode)){
+            let nodeQ = this.uiNodeQty(treeNode);
+            let q = nodeQ ? nodeQ : 1;
+            let rNodes = projectObj.project.Ration.getRationNodes(treeNode);
+            let rations = rNodes.map(function (node) {return node.data});
+            treeNode.data.gljList = projectObj.project.ration_glj.getGatherGljArrByRations(rations, q);
+        };
+    },
 
     initFees: function (treeNode){
         if (!treeNode.data.fees) {
@@ -261,12 +281,15 @@ let calcTools = {
         }
         return result;
     },
-    // 父清单暂估费是汇总子清单的暂估费,走计算程序逻辑,不在这里。
+    // 总造价清单、叶子清单、定额的暂估费。父清单是汇总子清单的暂估费,走计算程序逻辑,不在这里。
     estimateFee: function (treeNode, isBase = false){
         let me = this, sumU = 0, sumT = 0;
         let nodeQ = me.uiNodeQty(treeNode);
+        let isGather = (projectObj.project.property.zanguCalcMode == zanguCalcType.gatherMaterial);
+
         // 先汇总数量,再乘市场价
-        function estimateTotalFee(){
+        function eTFee(){
+            if (!treeNode.data.gljList) return 0;
             let GLJObjs = [];
             for (let glj of treeNode.data.gljList) {
                 if (!allMaterialTypes.includes(glj.type)) continue;
@@ -307,8 +330,20 @@ let calcTools = {
             };
             return rst;
         };
+        // 汇总子结点的暂估合价
+        function eTFeeByChildren(){
+            let rst = 0;
+            for (let node of treeNode.children){
+                if (node.data.feesIndex && node.data.feesIndex['estimate']) {
+                    rst = (rst + parseFloatPlus(node.data.feesIndex['estimate'].totalFee)).toDecimal(decimalObj.process);
+                };
+            };
+            rst = (rst).toDecimal(decimalObj.bills.totalPrice);
+            return rst;
+        };
         // 先数量乘市场价,再汇总
-        function estimateUnitFee(){
+        function eUFee(){
+            if (!treeNode.data.gljList) return 0;
             let rst = 0;
             for (let glj of treeNode.data.gljList) {
                 if (!allMaterialTypes.includes(glj.type)) continue;
@@ -351,29 +386,27 @@ let calcTools = {
             sumU = (sumU).toDecimal(decimalObj.bills.unitPrice);
             sumT = (sumT).toDecimal(decimalObj.bills.totalPrice);
         }
-        // 叶子清单、定额的暂估费
-        else{
-            if (!treeNode.data.gljList) return;
-            let isGather = (projectObj.project.property.zanguCalcMode == zanguCalcType.gatherMaterial);
-
-            if (calcTools.isRationCategory(treeNode)){
-                sumU = estimateUnitFee();
-                if (isBase) return sumU;
+        else if (me.isParentBill(treeNode)){  // 父清单不要汇总单价。
+            sumT = eTFeeByChildren();
+            sumU = undefined;
+        }
+        else if (me.isLeafBill(treeNode)){
+            if (isGather)
+                sumT = eTFee()
+            else
+                sumT = eTFeeByChildren();
 
-                if (isGather)
-                    sumT = estimateTotalFee()
-                else
-                    sumT = (nodeQ * sumU).toDecimal(decimalObj.ration.totalPrice);
-            }
-            else if (calcTools.isBill(treeNode)){
-                if (isGather)
-                    sumT = estimateTotalFee()
-                else
-                    sumT = 0;
+            let q = nodeQ ? nodeQ : 1;
+            sumU = (sumT / q).toDecimal(decimalObj.bills.totalPrice);
+        }
+        else if (me.isRationCategory(treeNode)){
+            sumU = eUFee();
+            if (isBase) return sumU;
 
-                let q = nodeQ ? nodeQ : 1;
-                sumU = (sumT / q).toDecimal(decimalObj.bills.totalPrice);
-            };
+            if (isGather)
+                sumT = eTFee()
+            else
+                sumT = (nodeQ * sumU).toDecimal(decimalObj.ration.totalPrice);
         };
 
         me.checkFeeField(treeNode, {'fieldName': 'estimate', 'unitFee': sumU, 'totalFee': sumT});
@@ -1367,10 +1400,16 @@ class CalcProgram {
         if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees || treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){
             treeNode.data.programID = null;
             calcTools.initFees(treeNode);
-            let nodes = (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees) ? treeNode.children : me.project.Ration.getRationNodes(treeNode);
+
+            let nodes = [];
+            if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){
+                calcTools.getGLJList(treeNode);
+                nodes = me.project.Ration.getRationNodes(treeNode);
+            }
+            else nodes = treeNode.children;
+
             let rst = [];
             for (let ft of cpFeeTypes) {
-                let isEstimate = ft.type == 'estimate';
                 let ftObj = {};
                 ftObj.fieldName = ft.type;
                 ftObj.name = ft.name;
@@ -1379,11 +1418,8 @@ class CalcProgram {
 
                 if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees){
                     for (let node of nodes) {
-                        if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
-                            // 父清单不要汇总综合单价。
-                            // buf = (buf + parseFloatPlus(node.data.feesIndex[ft.type].unitFee)).toDecimal(decimalObj.process);
+                        if (node.data.feesIndex && node.data.feesIndex[ft.type]) { // 父清单不要汇总综合单价。
                             btf = (btf + parseFloatPlus(node.data.feesIndex[ft.type].totalFee)).toDecimal(decimalObj.process);
-                            // btuf = (btuf + parseFloatPlus(node.data.feesIndex[ft.type].tenderUnitFee)).toDecimal(decimalObj.process);
                             bttf = (bttf + parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee)).toDecimal(decimalObj.process);
                         };
                     };
@@ -1391,7 +1427,6 @@ class CalcProgram {
                 else if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){     // 这里的算法要配合冷姐姐的神图才能看懂^_^
                     let sum_rtf = 0, sum_rttf = 0;
                     for (let node of nodes) {
-                        let rq = calcTools.uiNodeQty(node) ? calcTools.uiNodeQty(node) : 0;
                         let ruf = 0, rtuf = 0, rtf = 0, rttf = 0;
                         if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
                             ruf = parseFloatPlus(node.data.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
@@ -1406,39 +1441,27 @@ class CalcProgram {
                         sum_rtf = (sum_rtf + rtf).toDecimal(decimalObj.process);
                         sum_rttf = (sum_rttf + rttf).toDecimal(decimalObj.process);
                     };
-                    if (isEstimate){
+
+                    if (me.project.property.billsCalcMode == leafBillGetFeeType.rationPriceConverse ||
+                        me.project.property.billsCalcMode == leafBillGetFeeType.rationPrice) {
+                        buf = (sum_rtf / bq).toDecimal(decimalObj.process);
+                        btuf = (sum_rttf / bq).toDecimal(decimalObj.process);
+                    };
+                    if (isBaseFeeType(ft.type) ||
+                        (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice && ft.type == "common")){
                         btf = sum_rtf;
                         bttf = sum_rttf;
-                    }else{
-                        if (me.project.property.billsCalcMode == leafBillGetFeeType.rationPriceConverse ||
-                            me.project.property.billsCalcMode == leafBillGetFeeType.rationPrice) {
-                            buf = (sum_rtf / bq).toDecimal(decimalObj.process);
-                            btuf = (sum_rttf / bq).toDecimal(decimalObj.process);
-                        };
-                        if (isBaseFeeType(ft.type) ||
-                            (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice && ft.type == "common")){
-                            btf = sum_rtf;
-                            bttf = sum_rttf;
-                        }
-                        else{
-                            btf = (buf.toDecimal(decimalObj.bills.unitPrice) * bq).toDecimal(decimalObj.process);
-                            bttf = (btuf.toDecimal(decimalObj.bills.unitPrice) * bq).toDecimal(decimalObj.process);
-                        };
+                    }
+                    else{
+                        btf = (buf.toDecimal(decimalObj.bills.unitPrice) * bq).toDecimal(decimalObj.process);
+                        bttf = (btuf.toDecimal(decimalObj.bills.unitPrice) * bq).toDecimal(decimalObj.process);
                     };
                 };
 
                 ftObj.totalFee = btf.toDecimal(decimalObj.bills.totalPrice);
                 ftObj.tenderTotalFee = bttf.toDecimal(decimalObj.bills.totalPrice);
-                if (isEstimate){
-                    if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){
-                        ftObj.unitFee = (ftObj.totalFee / bq).toDecimal(decimalObj.bills.unitPrice);
-                        ftObj.tenderUnitFee = (ftObj.tenderTotalFee / bq).toDecimal(decimalObj.bills.unitPrice);
-                    }
-                }
-                else{
-                    ftObj.unitFee = buf.toDecimal(decimalObj.bills.unitPrice);
-                    ftObj.tenderUnitFee = btuf.toDecimal(decimalObj.bills.unitPrice);
-                }
+                ftObj.unitFee = buf.toDecimal(decimalObj.bills.unitPrice);
+                ftObj.tenderUnitFee = btuf.toDecimal(decimalObj.bills.unitPrice);
 
                 calcTools.checkFeeField(treeNode, ftObj);
 
@@ -1509,10 +1532,11 @@ class CalcProgram {
         // 定额或叶子清单自己的计算程序计算
         else{
             let fnArr = [];
+            calcTools.getGLJList(treeNode);
+
             if (treeNode.calcType == treeNodeCalcType.ctRationCalcProgram) {
                 // 量价、工料机类型的定额要求市场合价
                 if (treeNode.data.type == rationType.volumePrice || treeNode.data.type == rationType.gljRation){
-                    delete treeNode.data.gljList;
                     let muf = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
                     let q = calcTools.uiNodeQty(treeNode) ? calcTools.uiNodeQty(treeNode) : 0;
                     let mtf = (muf * q).toDecimal(decimalObj.ration.totalPrice);
@@ -1521,33 +1545,9 @@ class CalcProgram {
                         treeNode.changed = true;
                     } ;
                 };
-
-                // 工料机类型的定额、定额要算暂估费
-                if (treeNode.data.type != rationType.volumePrice){
-                     treeNode.data.gljList = me.project.ration_glj.getGljArrByRation(treeNode.data);
-                    // 计算程序里没有暂估费的计算规则,会漏掉,所以这里要专门算。
-                    calcTools.estimateFee(treeNode);
-                    fnArr.push('estimate');
-                };
-
-                if (treeNode.data.programID == undefined){
-                    treeNode.data.programID = projectInfoObj.projectInfo.property.engineering;
-                };
-            }
-            else if (treeNode.calcType == treeNodeCalcType.ctBillCalcProgram) {
-                let rations = me.project.Ration.getBillsSortRation(treeNode.source.getID());
-                let q = calcTools.uiNodeQty(treeNode) ? calcTools.uiNodeQty(treeNode) : 1;
-                treeNode.data.gljList = me.project.ration_glj.getGatherGljArrByRations(rations, q);
-
-                if (treeNode.data.programID == undefined){
-                    treeNode.data.programID = projectInfoObj.projectInfo.property.engineering;
-                }
-
-                // 叶子清单自己的计算程序计算,其暂估费也要汇总算。
-                calcTools.estimateFee(treeNode);
-                fnArr.push('estimate');
             };
 
+            if (treeNode.data.programID == undefined) treeNode.data.programID = projectInfoObj.projectInfo.property.engineering;
             let template = me.compiledTemplates[treeNode.data.programID];
             treeNode.data.calcTemplate = template;
 
@@ -1579,6 +1579,8 @@ class CalcProgram {
             };
         };
 
+        if (!calcTools.isTotalCostBill(treeNode))  // 已在上面的分支中计算过
+            calcTools.estimateFee(treeNode);
         if (treeNode.changed && !changedArr.includes(treeNode)) changedArr.push(treeNode);
     };
 

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

@@ -299,7 +299,7 @@ const cpFeeTypes = [
     {type: 'machineDiff', name: '机械价差'},
     {type: 'adjustLabour', name: '调整人工费'},
     {type: 'adjustMachineLabour', name: '调整机上人工费'},
-    {type: 'estimate', name: '暂估费'},
+    // {type: 'estimate', name: '暂估费'},
     {type: 'common', name: '工程造价'},
     {type: 'fee1', name: '费用1'}//,
     // {type: 'fee2', name: '费用2'},

+ 1 - 1
web/building_saas/main/js/views/calc_program_manage.js

@@ -51,7 +51,7 @@ let calcProgramManage = {
         me.mainSpread = sheetCommonObj.buildSheet($('#mainSpread')[0], me.mainSetting, me.datas.length);
         me.detailSpread = sheetCommonObj.buildSheet($('#detailSpread')[0], me.detailSetting, me.datas[0].calcItems.length);
         let arr = projectObj.project.calcProgram.compiledFeeTypeNames.slice();
-        arr.splice(arr.findIndex(function (e){return e == '暂估费'}), 1);
+        // arr.splice(arr.findIndex(function (e){return e == '暂估费'}), 1);
         let fieldName = new GC.Spread.Sheets.CellTypes.ComboBox();
         fieldName.items(arr);
         me.detailSpread.getSheet(0).getRange(-1, 4, -1, 1).cellType(fieldName);