zhangweicheng 5 年之前
父節點
當前提交
05d8d9a2d6

+ 65 - 11
modules/main/facade/project_facade.js

@@ -32,6 +32,7 @@ const gljUtil = require('../../../public/gljUtil');
 let stdColSettingModel = mongoose.model('std_main_col_lib');
 let decimal_facade = require('../../main/facade/decimal_facade');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
+const calcUtil = require('../../../public/calculate_util')
 import fixedFlag from  '../../common/const/bills_fixed';
 import GLJListModel from "../../glj/models/glj_list_model";
 const projectDao = require('../../pm/models/project_model').project;
@@ -287,13 +288,14 @@ async function getDefaultColSetting(libID){
     return await stdColSettingModel.findOne({ID: libID, deleted: false}, '-_id main_tree_col');
 }
 
-async function getBudgetSummayDatas(projectIDs){
+async function getBudgetSummayDatas(projectIDs,overWriteUrl){
     try {
         let projects = [];
         let names = [];
         let prjTypeNames = [];
         let compilationScopes = [];
         let decimal = null;
+        let isProgressiveType = false;
         for(let ID of projectIDs){
             projects.push(await getBillsByProjectID(ID)) ;
         }
@@ -309,9 +311,11 @@ async function getBudgetSummayDatas(projectIDs){
             names.push(projects[i].name);
             prjTypeNames.push(projects[i].prjTypeName);
             compilationScopes.push(projects[i].compilationScope);
-            decimal = await mergeProject(mp.roots,projects[i].roots)
+            decimal = await mergeProject(mp.roots,projects[i].roots);
+            if(projects[i].progressiveType == 0)  isProgressiveType = true;
         }
-        let SummaryAuditDetail = getReportData(names,mp.roots,prjTypeNames,compilationScopes,decimal);
+
+        let SummaryAuditDetail = getReportData(names,mp.roots,prjTypeNames,compilationScopes,decimal,isProgressiveType,mp.progressiveInterval,overWriteUrl);
         let parentProject = await projectsModel.findOne({ID:mp.ParentID});
         let result = {
             prj: {},
@@ -330,9 +334,23 @@ async function getBudgetSummayDatas(projectIDs){
 }
 
 
-function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
+function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal,isProgressiveType,progressiveInterval,overWriteUrl) {
     let datas = [],totalItem = null;
+    let overWrite = null;
+    if(overWriteUrl && overWriteUrl!=""){
+      overWrite = require("../../.."+compilation.overWriteUrl);
+    }
     setChildrenDatas(items,datas);
+    let totalExp = totalItem.calcBase;
+    if(isProgressiveType&&progressiveInterval){
+      for(let t of datas){
+        totalExp.replace(t.ID,t.billsTtlPrice+"");
+      }
+      totalExp.replace(/@/g,"");
+      let nTotal = eval(totalExp);
+      totalItem.billsTtlPrice = scMathUtil.roundForObj(nTotal,decimal.bills.totalPrice);
+    }
+
     for(let d of datas){
         if(d.billsTtlPrice&&totalItem.billsTtlPrice){
             d['各项费用比例'] = scMathUtil.roundForObj(d.billsTtlPrice/totalItem.billsTtlPrice * 100,2)
@@ -340,19 +358,31 @@ function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
         d['prjNames'] = nameList;
         d['prjTypeNames'] = prjTypeNames;
         d['编制范围明细'] = compilationScopes;
+        
     }
+   
+
     return datas;
 
 
-    function setChildrenDatas(children,arr,level = 0) {
+    function setChildrenDatas(children,arr,level = 0,rootFlag) {
+        let temTotalPrice = 0;
         for(let c of children){
-            arr.push(getBillDatas(c,level));
-            setChildrenDatas(c.children,arr,level+1);
+            if(level == 0) rootFlag = c.flag;//取最顶层节点的固定清单类别
+            let sumChildren = setChildrenDatas(c.children,arr,level+1,rootFlag);
+            let tbill = getBillDatas(c,level,rootFlag);
+            if(isProgressiveType && progressiveInterval && rootFlag == fixedFlag.MAINTENANCE_EXPENSES){//如果要累进的,父节点要重新汇总
+              if(level>0) temTotalPrice = scMathUtil.roundForObj(tbill.billsTtlPrice + temTotalPrice,decimal.bills.totalPrice); 
+              if(c.children.length > 0) tbill.billsTtlPrice = sumChildren;
+            }
+            arr.push(tbill);
         }
+        return temTotalPrice
     }
 
-    function getBillDatas(bills,level) {
+    function getBillDatas(bills,level,rootFlag) {
         let tem = {
+            ID:bills.ID,
             billsName:bills.name,
             billsCode:bills.code,
             billsUnit:bills.unit,
@@ -367,10 +397,12 @@ function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
         };
         let total = 0;
         let rationTotal =0;
+        let baseTotal = 0;
         for(let n of nameList){
             let  p = 0;//金额
             let up =0;//单价
             let ra = 0;//定额建安费
+            let bt = 0; //累计相关
             if(bills.unitPrices[n]) up = scMathUtil.roundForObj(bills.unitPrices[n],decimal.bills.unitPrice);
             tem.billsUnitPrices.push(up);
             if(bills.prices[n]){
@@ -390,8 +422,22 @@ function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
                 tem.billsAmounts.push(0);
                 tem['技术经济指标'].push(scMathUtil.roundForObj(p,2));
             }
+            if(rootFlag == fixedFlag.MAINTENANCE_EXPENSES){//如果是第三部分下的子清单,才要计算累计的相关信息
+              if(bills.baseProgressiveFees[n]){
+                bt =  scMathUtil.roundForObj(bills.baseProgressiveFees[n],decimal.bills.totalPrice);
+                baseTotal = scMathUtil.roundForObj(bt+baseTotal,decimal.process);
+              }
+            }
+        }
+        if(progressiveInterval && isProgressiveType&&calcUtil.isProgressive(bills.calcBase,overWrite?overWrite.progression:undefined) && rootFlag == fixedFlag.MAINTENANCE_EXPENSES){
+          let calcTotal = calcUtil.getProgressiveFee(baseTotal,bills.calcBase,progressiveInterval,decimal.bills.totalPrice,overWrite?overWrite.deficiency:undefined);
+          tem.billsTtlPrice = calcTotal;
+          let rate =  scMathUtil.roundForObj(calcTotal * 100/baseTotal,decimal.feeRate);
+          tem.billsMemos = "费率:"+rate+"%"; 
+          //“费率:n%”,n为汇总后重算的金额/汇总后的基数
+        }else{
+          tem.billsTtlPrice = scMathUtil.roundForObj(total,decimal.bills.totalPrice);
         }
-        tem.billsTtlPrice = scMathUtil.roundForObj(total,decimal.bills.totalPrice);
         tem.rationTotal =  scMathUtil.roundForObj(rationTotal,decimal.bills.totalPrice);//定额总建安费
         tem['技术经济综合指标'] = (tem.billsTtlAmt && parseFloat(tem.billsTtlAmt) !== 0)?scMathUtil.roundForObj(tem.billsTtlPrice/tem.billsTtlAmt,2):scMathUtil.roundForObj(tem.billsTtlPrice,2);
         if(bills.flag == fixedFlag.TOTAL_COST) totalItem = tem;
@@ -427,6 +473,7 @@ async function mergeItem(a,b,decimal,project) {
         a.rationCommons[name] = b.rationCommons[name];
         a.quantityMap[name] = b.quantityMap[name];
         a.unitPrices[name]=b.unitPrices[name];
+        a.baseProgressiveFees[name] = b.baseProgressiveFees[name];
     }
     for(let name in a.quantityMap){
         a.quantityMap[name] = a.quantityMap[name]?scMathUtil.roundForObj(a.quantityMap[name],bqDecimal):0;
@@ -513,6 +560,8 @@ async function getBillsByProjectID(projectID){
     let auditor='';//审核人
     let compilationScope='';//编制范围
     let engineering='';//养护类别
+    let progressiveType = 0;//累进计算类型
+    let progressiveInterval = null;
     if(project.property&&project.property.projectFeature){
         for(let f of project.property.projectFeature){
             if(f.key == 'author') author = f.value;
@@ -520,6 +569,8 @@ async function getBillsByProjectID(projectID){
             if(f.key =='compilationScope') compilationScope = f.value;
             if(f.key == 'engineering') engineering = f.value;
         }
+        if(project.property.progressiveType) progressiveType = project.property.progressiveType;
+        progressiveInterval = project.property.progressiveInterval;
     }
    for(let b of  bills){
        let commonFee =_.find(b._doc.fees,{"fieldName":"common"});
@@ -527,13 +578,16 @@ async function getBillsByProjectID(projectID){
        let quantityMap={};
        let unitPrices ={};
        let rationCommons={};
+       let baseProgressiveFees ={};
        let rationFee = _.find(b._doc.fees,{"fieldName":"rationCommon"});
        if(commonFee&&commonFee.totalFee) prices[projectName] =  commonFee.totalFee;
        if(commonFee&&commonFee.unitFee) unitPrices[projectName] = commonFee.unitFee;
        if(rationFee&&rationFee.totalFee) rationCommons[projectName] = rationFee.totalFee;
+       baseProgressiveFees = baseProgressiveFees[projectName] = b.baseProgressiveFee;
+
        quantityMap[projectName] = b.quantity;
        let flagIndex = _.find(b._doc.flags,{'fieldName':'fixed'});
-       let doc = {ID:b.ID,name:b.name,code:b.code,unit:b.unit,projectID:b.projectID, ParentID:b.ParentID,NextSiblingID:b.NextSiblingID,unitPrices:unitPrices,quantity:b.quantity,prices:prices,rationCommons:rationCommons,quantityMap:quantityMap,flag:flagIndex?flagIndex.flag:-99,remark:b.remark};//选取有用字段
+       let doc = {ID:b.ID,name:b.name,code:b.code,unit:b.unit,projectID:b.projectID, ParentID:b.ParentID,NextSiblingID:b.NextSiblingID,unitPrices:unitPrices,quantity:b.quantity,prices:prices,rationCommons:rationCommons,quantityMap:quantityMap,flag:flagIndex?flagIndex.flag:-99,remark:b.remark,calcBase:b.calcBase,baseProgressiveFees:baseProgressiveFees};//选取有用字段
        if(b.ParentID == -1) roots.push(doc);
        parentMap[b.ParentID]?parentMap[b.ParentID].push(doc):parentMap[b.ParentID]=[doc];
    }//设置子节点
@@ -541,7 +595,7 @@ async function getBillsByProjectID(projectID){
         setChildren(r,parentMap,1);
    }
     roots = sortChildren(roots);
-    return {name:projectName,roots:roots,author:author,auditor:auditor,compilationScope:compilationScope,ParentID:project.ParentID,prjTypeName:engineering}
+    return {name:projectName,roots:roots,author:author,auditor:auditor,compilationScope:compilationScope,ParentID:project.ParentID,prjTypeName:engineering,progressiveType:progressiveType,progressiveInterval:progressiveInterval}
 }
 
 function setChildren(bill,parentMap,level) {

+ 5 - 0
web/building_saas/main/html/main.html

@@ -952,6 +952,11 @@
                                                     自动根据定额单位转换定额工程量
                                                 </label>
                                             </div>
+                                            <h5 class="mt-3">累进计算费用</h5>
+                                            <div class="">
+                                              <input type="radio" class="form-radio" name="progressiveType" id="progressive_unite" value=0>统一累进办法&nbsp;&nbsp;
+                                              <input type="radio" class="form-radio" name="progressiveType" id="progressive_sum" value=1>各汇总工程相加&nbsp;&nbsp;
+                                            </div>
                                         </fieldset>
                                             <label style="margin-top: 320px">*将影响所有建设项目</label>
                                     </div>

+ 11 - 1
web/building_saas/main/js/views/project_view.js

@@ -2309,13 +2309,16 @@ $('#poj-set').on('show.bs.modal', function () {
 
         let zg = projectObj.project.property.zanguCalcMode !== undefined &&
                  projectObj.project.property.zanguCalcMode !== null ? projectObj.project.property.zanguCalcMode : zanguCalcType.common;
+        let progressiveType = projectObj.project.property.progressiveType?projectObj.project.property.progressiveType:0;   
         setCalcFlag($('#rationContent'), leafBillGetFeeType.rationContent, ft);
         setCalcFlag($('#rationPriceConverse'), leafBillGetFeeType.rationPriceConverse, ft);
         setCalcFlag($('#rationPrice'), leafBillGetFeeType.rationPrice, ft);
         setCalcFlag($('#billsPrice'), leafBillGetFeeType.billsPrice, ft);
         setCalcFlag($('#zangu_common'), zanguCalcType.common, zg);
         setCalcFlag($('#zangu_gatherMaterial'), zanguCalcType.gatherMaterial, zg);
-
+        setCalcFlag($('#progressive_unite'), 0, progressiveType);
+        setCalcFlag($('#progressive_sum'), 1, progressiveType);
+        
         let showAdjustPrice = projectObj.project.projSetting.glj_col?projectObj.project.projSetting.glj_col.showAdjustPrice:false;
         showAdjustPrice === true ? $("#tab_poj-settings-6").show():$("#tab_poj-settings-6").hide();
         projDisplayView.init();
@@ -2473,6 +2476,13 @@ $('#property_ok').click(function () {
         project.property.zanguCalcMode = zg;
         reCalcRations = true;
     };
+
+    let progressiveType = parseInt($("input[name='progressiveType']:checked").val())
+    if (progressiveType !== project.property.progressiveType) {
+      properties['property.progressiveType'] = progressiveType;
+      project.property.progressiveType = progressiveType;
+  };
+
     //价差预备费,预算项目才有
     if (project.property.valuationType === 'bill') {
         let costGrowthRateV = $('#costGrowthRate').val(),