浏览代码

汇总方案2

chenshilong 4 年之前
父节点
当前提交
7f6156743d

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

@@ -10,6 +10,8 @@
 
 <body>
     <div class="toolsbar px-1" style="height:30px;width:100%;line-height:30px;font-size:15px;" id="lblGatherFee">费用汇总</div>
+    <!--<button type="button" class="btn btn-outline-primary btn-sm" id="btnGatherFee">费用汇总</button>-->
+
     <div class="container-fluid">
         <div class="row">
             <div class="col-lg-2 p-0">

+ 136 - 56
web/building_saas/main/js/models/calc_program.js

@@ -141,7 +141,9 @@ let calcTools = {
         };
     },
     getGLJListByProgramID: function (programID) {
-        return null;
+        let rations = calcTools.getRationsByProgramID(programID);
+        let gljList = projectObj.project.ration_glj.getGljArrByRations(rations);
+        return gljList;
     },
     getLeafBills: function (treeNode){
         let leafBills = [];
@@ -846,30 +848,30 @@ let calcTools = {
         };
         return coe;
     },
-    tenderCoe_GLJQty: function (treeNode, glj){
+    tenderCoe_GLJQty: function (rationData, glj){
         let coe = 1;
-        if (!treeNode.data.quantityCoe) return coe;
+        if (!rationData.quantityCoe) return coe;
         if (!calcTools.isTenderProjectGLJ(glj)) return coe;
 
         if (gljType.LABOUR == glj.type){
-            if (treeNode.data.quantityCoe.labour)
-                coe = treeNode.data.quantityCoe.labour;
+            if (rationData.quantityCoe.labour)
+                coe = rationData.quantityCoe.labour;
         }
         else if (baseMaterialTypes.indexOf(glj.type)){
-            if (treeNode.data.quantityCoe.material)
-                coe = treeNode.data.quantityCoe.material;
+            if (rationData.quantityCoe.material)
+                coe = rationData.quantityCoe.material;
         }
         else if (baseMachineTypes.indexOf(glj.type)){
-            if (treeNode.data.quantityCoe.machine)
-                coe = treeNode.data.quantityCoe.machine;
+            if (rationData.quantityCoe.machine)
+                coe = rationData.quantityCoe.machine;
         }
         else if (gljType.MAIN_MATERIAL == glj.type){
-            if (treeNode.data.quantityCoe.main)
-                coe = treeNode.data.quantityCoe.main;
+            if (rationData.quantityCoe.main)
+                coe = rationData.quantityCoe.main;
         }
         else if (gljType.EQUIPMENT == glj.type){
-            if (treeNode.data.quantityCoe.equipment)
-                coe = treeNode.data.quantityCoe.equipment;
+            if (rationData.quantityCoe.equipment)
+                coe = rationData.quantityCoe.equipment;
         };
 
         if (coe == '0') coe = 1;   // 这里加个保护
@@ -1093,6 +1095,14 @@ let calcTools = {
               arr.push(tpl);
         };
         return arr;
+    },
+    getRationsByProgramID: function(programID){
+      let rations = [];
+      for (const r of projectObj.project.Ration.datas) {
+        if (r.programID == programID)
+            rations.push(r);
+      };
+      return rations;
     }
 };
 
@@ -1808,7 +1818,7 @@ class CalcProgram {
             me.innerCalcBillCustom(treeNode)
         // 定额:计算程序
         else
-            me.innerCalcRation(treeNode, tenderType);
+            me.innerCalcRation2(treeNode, tenderType);
 
         if (!calcTools.isTotalCostBill(treeNode))  // 已在上面的分支中计算过
             calcTools.estimateFee(treeNode);
@@ -1982,6 +1992,51 @@ class CalcProgram {
         treeNode.data.calcTemplate = {"calcItems": []};
     };
 
+    innerCalcRation2(treeNode){
+      let me = this;
+      calcTools.getGLJList(treeNode, true);
+
+      let nQ = calcTools.uiNodeQty(treeNode);
+
+      if (treeNode.calcType == treeNodeCalcType.ctRationCalcProgram) {
+        // 量价、工料机类型的定额要求"市场合价"
+        if (calcTools.isVP_or_GLJR(treeNode)){
+          let u = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
+          let t = (u * nQ).toDecimal(decimalObj.ration.totalPrice);
+          if (treeNode.data.marketTotalFee != t){
+            treeNode.data.marketTotalFee = t;
+            treeNode.changed = true;
+          } ;
+        };
+      };
+
+      calcTools.initFees(treeNode);
+      // 只有人、材、机、主、设。
+      let fieldNames = ['labour', 'material', 'machine', 'mainMaterial', 'equipment', 'common'];
+      let funcNames = ['定额人工费','定额材料费','定额施工机具使用费','市场价主材费','市场价设备费'];
+      debugger;
+      for (let i = 0; i < 6; i++) {
+        let obj = {};
+        obj.fieldName = fieldNames[i];
+        if (obj.fieldName != 'common'){
+          obj.unitFee = (rationCalcBases[funcNames[i]](treeNode)).toDecimal(decimalObj.decimal('unitPrice', treeNode));
+        }
+        else{
+            let sum = 0;
+            for (let i = 0; i < fieldNames.length - 1; i++) {
+                let u = treeNode.data.feesIndex[fieldNames[i]]? treeNode.data.feesIndex[fieldNames[i]].unitFee : 0;
+                sum = sum + u;
+            }
+          obj.unitFee = sum.toDecimal(decimalObj.decimal('unitPrice', treeNode))
+        }
+        obj.totalFee = (obj.unitFee * nQ).toDecimal(decimalObj.decimal('totalPrice', treeNode));
+        obj.tenderUnitFee = obj.unitFee;
+        obj.tenderTotalFee = obj.totalFee;
+        calcTools.checkFeeField(treeNode, obj);
+      };
+
+    };
+
     // 定额部分抽取出来,供分摊定额公用。
     innerCalcRation(treeNode, tenderType = tenderTypes.ttCalc){
         let me = this;
@@ -2759,66 +2814,91 @@ class CalcProgram {
 
     };
 
+    // 算法1:直接累计同取费多定额的各个费
     gatherFee(template){
-        // $.bootstrapLoading.start();
-        // setTimeout(()=>{
-            // 先把符合的定额筛选出来,以提高速度。
-            let rations = [];
-            let rst = 0;
-            for (const r of projectObj.project.Ration.datas) {
-                if (r.programID == template.ID) rations.push(r);
-            };
-
-            for (let ft of cpFeeTypes) {
-                let sum_uf = 0, sum_tuf = 0, sum_tf = 0, sum_ttf = 0;
-                for (const r of rations) {
-                    let uf = 0, tuf = 0, tf = 0, ttf = 0;
-                    if (r.feesIndex && r.feesIndex[ft.type]) {
-                        uf = parseFloatPlus(r.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
-                        tuf = parseFloatPlus(r.feesIndex[ft.type].tenderUnitFee).toDecimal(decimalObj.bills.unitPrice);
-                        tf = parseFloatPlus(r.feesIndex[ft.type].totalFee).toDecimal(decimalObj.bills.totalPrice);
-                        ttf = parseFloatPlus(r.feesIndex[ft.type].tenderTotalFee).toDecimal(decimalObj.bills.totalPrice);
-                    };
-                    sum_uf = (sum_uf + uf).toDecimal(decimalObj.process);
-                    sum_tuf = (sum_tuf + tuf).toDecimal(decimalObj.process);
-                    sum_tf = (sum_tf + tf).toDecimal(decimalObj.process);
-                    sum_ttf = (sum_ttf + ttf).toDecimal(decimalObj.process);
-                };
-                for (let i = 0; i < template.calcItems.length; i++) {
-                    let ci = template.calcItems[i];
-                    if (ci.fieldName == ft.type){
-                      ci.totalFee = sum_tf.toDecimal(decimalObj.bills.totalPrice);
-                      ci.tenderTotalFee = sum_ttf.toDecimal(decimalObj.bills.totalPrice);
-                      ci.unitFee = sum_uf.toDecimal(decimalObj.bills.unitPrice);
-                      ci.tenderUnitFee = sum_tuf.toDecimal(decimalObj.bills.unitPrice);
-                      if (ft.type =='common') {
-                        template.totalFee = ci.totalFee;
-                        rst = ci.totalFee;
-                      }
-                      break;
-                    }
+        let rations = calcTools.getRationsByProgramID(template.ID);
+        let rst = 0;
+        for (let ft of cpFeeTypes) {
+            let sum_uf = 0, sum_tuf = 0, sum_tf = 0, sum_ttf = 0;
+            for (const r of rations) {
+                let uf = 0, tuf = 0, tf = 0, ttf = 0;
+                if (r.feesIndex && r.feesIndex[ft.type]) {
+                    uf = parseFloatPlus(r.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
+                    tuf = parseFloatPlus(r.feesIndex[ft.type].tenderUnitFee).toDecimal(decimalObj.bills.unitPrice);
+                    tf = parseFloatPlus(r.feesIndex[ft.type].totalFee).toDecimal(decimalObj.bills.totalPrice);
+                    ttf = parseFloatPlus(r.feesIndex[ft.type].tenderTotalFee).toDecimal(decimalObj.bills.totalPrice);
                 };
+                sum_uf = (sum_uf + uf).toDecimal(decimalObj.process);
+                sum_tuf = (sum_tuf + tuf).toDecimal(decimalObj.process);
+                sum_tf = (sum_tf + tf).toDecimal(decimalObj.process);
+                sum_ttf = (sum_ttf + ttf).toDecimal(decimalObj.process);
             };
-            return rst;
-        // });
-        // $.bootstrapLoading.end();
+            for (let i = 0; i < template.calcItems.length; i++) {
+                let ci = template.calcItems[i];
+                if (ci.fieldName == ft.type){
+                  ci.totalFee = sum_tf.toDecimal(decimalObj.bills.totalPrice);
+                  ci.tenderTotalFee = sum_ttf.toDecimal(decimalObj.bills.totalPrice);
+                  ci.unitFee = sum_uf.toDecimal(decimalObj.bills.unitPrice);
+                  ci.tenderUnitFee = sum_tuf.toDecimal(decimalObj.bills.unitPrice);
+                  if (ft.type =='common') {
+                    template.totalFee = ci.totalFee;
+                    rst = ci.totalFee;
+                  }
+                  break;
+                }
+            };
+        };
+        return rst;
+    };
+
+    // 算法2:先汇总同取费多定额下的工料机,虚拟成一个大定额对象,走计算程序。
+    gatherFee2(template){
+        let data = {gljList: null};
+        let obj = {data: data};
+        obj.data.gljList = calcTools.getGLJListByProgramID(template.ID);
+
+        let $CE = executeObj;
+        $CE.treeNode = obj;
+        $CE.template = template;
+
+        let rst = 0;
+        for (let idx of template.compiledSeq) {
+            let calcItem = template.calcItems[idx];
+            $CE.tempCalcItem = calcItem;
+            let feeRate = 100;  // 100%
+            if (calcItem.feeRate != undefined)
+              feeRate = parseFloat(calcItem.feeRate).toDecimal(decimalObj.feeRate);
+
+            calcItem.unitFee = (eval(calcItem.compiledExpr) * feeRate * 0.01).toDecimal(2);
+            // calcItem.totalFee = (calcItem.unitFee * nQ).toDecimal(2);
+            calcItem.totalFee = (calcItem.unitFee * 1).toDecimal(2);
+
+            if (calcItem.fieldName =='common') {
+                template.totalFee = calcItem.totalFee;
+                rst = calcItem.totalFee;
+            }
+        };
+        return rst;
     };
 
     //报表用取费类别汇总。调用:let obj = projectObj.project.calcProgram.getGatherFeeData();
     getGatherFeeData(){
+      // $.bootstrapLoading.start();
+      // setTimeout(()=>{
         let rst = {};
         let tpls = calcTools.getUsedTemplates();
 
         let temp = 0;
         for (const t of tpls) {
-            temp = temp + this.gatherFee(t);
+            temp = temp + this.gatherFee2(t);
         }
         rst.calcPrograms = tpls;
         rst.totalFee = temp.toDecimal(decimalObj.bills.totalPrice);
         projectObj.project.mainTree.items[0].data.totalFee = rst.totalFee;
         console.log(rst);
         return rst;
+      // });
+      // $.bootstrapLoading.end();
     };
 };
 
-// export default analyzer;

+ 53 - 49
web/building_saas/main/js/models/ration_glj.js

@@ -44,65 +44,69 @@ let ration_glj = {
            return  _.filter(this.datas, {'rationID': rationID})
         };
 
+        ration_glj.prototype.getGljArrByRations = function (rations){
+          let clone = function (obj) {
+            if (obj === null) return null;
+            let o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
+            for (let i in obj) {
+              o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
+            }
+            return o;
+          }
 
-        ration_glj.prototype.getGljArrByBill = function (treeNode, needOneBill) {
-            let result = [];
-            let clone = function (obj) {
-                if (obj === null) return null;
-                let o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
-                for (let i in obj) {
-                    o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
-                }
-                return o;
+          let findGlj = function (sourceGlj, gljArr) {
+            for (let glj of gljArr) {
+              if (glj.projectGLJID === sourceGlj.projectGLJID) {
+                return glj;
+              }
             }
-            let findGlj = function (sourceGlj, gljArr) {
-                for (let glj of gljArr) {
-                    if (glj.projectGLJID === sourceGlj.projectGLJID) {
-                        return glj;
-                    }
+            return null;
+          }
+
+          let result = [];
+          for (let ration of rations) {
+            if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
+              let glj = JSON.parse(JSON.stringify(ration));
+              glj.type = glj.subType;
+              glj.totalQuantity = parseFloatPlus(ration.quantity);
+              glj.markertPrice = glj.marketUnitFee;
+              glj.basePrice = glj.marketUnitFee;
+              glj.adjustPrice = glj.marketUnitFee;
+              result.push(glj);
+            }
+            else{
+              let rationGljs = this.getGLJListByRationID(ration.ID);
+              for (let glj of rationGljs) {
+                let sameGlj = findGlj(glj, result);
+                let coe = calcTools.tenderCoe_GLJQty(ration, glj);
+                if (!sameGlj) {
+                  sameGlj = clone(glj);
+                  sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
+                  // glj的 tenderQuantity = glj的quantity * 定额的quantity * glj的消耗量调整系数coe。
+                  // 与定额的tenderQuantity无关,与定额的子目工程量调整系数coe无关。下面这里直接取数量即可,因为它在上一句已经乘过定额数量了。
+                  sameGlj.tenderQuantity = (sameGlj.quantity * coe).toDecimal(4);
+                  result.push(sameGlj);
+                } else {
+                  sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
+                  sameGlj.tenderQuantity = sameGlj.tenderQuantity + (glj.quantity * coe).toDecimal(4);
+
+                  sameGlj.totalQuantity = (parseFloat(sameGlj.totalQuantity) + parseFloat(glj.totalQuantity)).toDecimal(4);
                 }
-                return null;
+              }
             }
+          }
+          result = gljOprObj.combineWithProjectGlj(result, false);
+          return result;
+        };
 
+        ration_glj.prototype.getGljArrByBill = function (treeNode, needOneBill) {
             let nodeQ = calcTools.uiNodeQty(treeNode);
             let q = nodeQ ? nodeQ : 1;
             let allNodes = projectObj.project.Ration.getRationNodes(treeNode);
             let rNodes = allNodes.filter(function (node) {return calcTools.isRationItem(node)});
             let rations = rNodes.map(function (node) {return node.data});
 
-            for (let ration of rations) {
-                if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
-                    let glj = JSON.parse(JSON.stringify(ration));
-                    glj.type = glj.subType;
-                    glj.totalQuantity = parseFloatPlus(ration.quantity);
-                    glj.markertPrice = glj.marketUnitFee;
-                    glj.basePrice = glj.marketUnitFee;
-                    glj.adjustPrice = glj.marketUnitFee;
-                    result.push(glj);
-                }
-                else{
-                    let rationGljs = projectObj.project.calcProgram.getGljArrByRation(ration);
-                    for (let glj of rationGljs) {
-                        let sameGlj = findGlj(glj, result);
-                        let coe = calcTools.tenderCoe_GLJQty(treeNode, glj);
-                        if (!sameGlj) {
-                            sameGlj = clone(glj);
-                            sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
-                            // glj的 tenderQuantity = glj的quantity * 定额的quantity * glj的消耗量调整系数coe。
-                            // 与定额的tenderQuantity无关,与定额的子目工程量调整系数coe无关。下面这里直接取数量即可,因为它在上一句已经乘过定额数量了。
-                            sameGlj.tenderQuantity = (sameGlj.quantity * coe).toDecimal(4);
-                            result.push(sameGlj);
-                        } else {
-                            sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
-                            sameGlj.tenderQuantity = sameGlj.tenderQuantity + (glj.quantity * coe).toDecimal(4);
-
-                            sameGlj.totalQuantity = (parseFloat(sameGlj.totalQuantity) + parseFloat(glj.totalQuantity)).toDecimal(4);
-                        }
-                    }
-                }
-            }
-
-            result = gljOprObj.combineWithProjectGlj(result,false);
+            let result = this.getGljArrByRations(rations);
 
             if (!needOneBill) return result;
 
@@ -1053,4 +1057,4 @@ let ration_glj = {
         };
         return new ration_glj(project);
     }
-};
+};

+ 10 - 0
web/building_saas/main/js/views/gather_fees_view.js

@@ -580,6 +580,16 @@ $(document).ready(function(){
             $.bootstrapLoading.end();
         });
     });
+
+    // $("#btnGatherFee").bind('click',function () {
+    //   gatherFeesView.buildSheet();
+    //   gatherFeesView.refreshDetailSheet();
+    // });
+
+    $("#lblGatherFee").bind('click',function () {
+        gatherFeesView.buildSheet();
+        gatherFeesView.refreshDetailSheet();
+    });
 });