Browse Source

Merge branch 'budget' of http://192.168.1.41:3000/SmartCost/ConstructionCost into budget

zhangweicheng 4 years ago
parent
commit
394a600eff

+ 29 - 5
modules/pm/facade/pm_facade.js

@@ -109,6 +109,7 @@ const shareListModel = mongoose.model('share_list');
 const shareLibModel = mongoose.model('share_libs');
 let welcomeModel = mongoose.model("welcome_setting");
 let equipmentPurchaseModel = mongoose.model('equipment_purchase');
+const gaterFeeModel = mongoose.model('gather_calc_programs');
 
 
 let scMathUtil = require('../../../public/scMathUtil').getUtil();
@@ -705,6 +706,9 @@ async function copyProject(userID, compilationID,data,newProjectID = null, delay
 
     copyTasks.push(copyEquipment(newProjectID,originalID));
 
+    // 复制费用汇总
+    copyTasks.push(copyGatherFee(newProjectID, originalID));
+
     await Promise.all(copyTasks);
     // 最后再处理项目数据
     // 可能会有最后再在外层方法插入项目数据的需求,如拷贝例题,暂时先不在这里插入项目数据
@@ -833,6 +837,17 @@ async function copyEquipment(newProjectID,oldProjectID){//复制设备购置费
     return result;
 }
 
+// 复制费用汇总
+async function copyGatherFee(newProjectID, oldProjectID) {
+    let result = null;
+    const gatherItem = await gaterFeeModel.findOne({ projectID: oldProjectID }, '-_id').lean();
+    if (gatherItem) {
+        gatherItem.projectID = newProjectID;
+        result = await gaterFeeModel.create(gatherItem);
+    }
+    return result;
+}
+
 async  function commonCopy(newProjectID,oldID,newID,model) { //对于只需更新ID和projectID的文件的复制
     let result = null;
     let file = await model.findOne({"ID": oldID}, '-_id');
@@ -2542,6 +2557,7 @@ async function exportTenderData(data){
     result.bidList = await bidListModel.find({projectID:data.projectID}, '-_id').lean();
     result.contractorList = await contractorListModel.find({projectID:data.projectID}, '-_id').lean();
     result.equipments = await equipmentPurchaseModel.findOne({projectID:data.projectID},'-_id').lean();
+    result.gatherFees = await gaterFeeModel.findOne({projectID:data.projectID},'-_id').lean();
 
     return cipher.aesEncrypt(JSON.stringify(result));
 }
@@ -2786,9 +2802,9 @@ async function importProjects(data,req,updateData) {
             let [constructionProjectID,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap] = await handleMainProjectDatas(mainData,updateData,req.session.sessionUser.id);
             result.constructionProjectID = constructionProjectID;
             if(datas.length > 1 ){
-                let newProjectSettings=[],bills=[],rations=[],installationFees=[],projectGLJs=[],rationGLJs=[],rationCoes=[],quantityDetails=[],rationInstallations=[],rationTemplates=[],evaluateList=[],bidList=[],contractorList=[],newCalcProgramsFiles=[],newLabourCoes=[],newEquipments = [];
+                let newProjectSettings=[],bills=[],rations=[],installationFees=[],projectGLJs=[],rationGLJs=[],rationCoes=[],quantityDetails=[],rationInstallations=[],rationTemplates=[],evaluateList=[],bidList=[],contractorList=[],newCalcProgramsFiles=[],newLabourCoes=[],newEquipments = [],newGatherFees = [];
                 for(let i = 1;i<datas.length;i++){
-                  let [tnewProjectSetting,tbills,trations,tinstallationFees,tprojectGLJs,trationGLJs,trationCoes,tquantityDetails,trationInstallations,trationTemplates,tevaluateList,tbidList,tcontractorList,tnewCalcProgramsFile,tnewLabourCoe,tnewEquipments] = await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
+                  let [tnewProjectSetting,tbills,trations,tinstallationFees,tprojectGLJs,trationGLJs,trationCoes,tquantityDetails,trationInstallations,trationTemplates,tevaluateList,tbidList,tcontractorList,tnewCalcProgramsFile,tnewLabourCoe,tnewEquipments, tnewGatherFees] = await handleEachProject(datas[i],projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap)
                   if(tnewProjectSetting) newProjectSettings.push(tnewProjectSetting);
                   if(tbills.length > 0) bills = bills.concat(tbills);
                   if(trations.length > 0) rations = rations.concat(trations);
@@ -2804,7 +2820,8 @@ async function importProjects(data,req,updateData) {
                   if(tcontractorList.length > 0)  contractorList = contractorList.concat(tcontractorList);
                   if(tnewCalcProgramsFile) newCalcProgramsFiles.push(tnewCalcProgramsFile);
                   if(tnewLabourCoe) newLabourCoes.push(tnewLabourCoe); 
-                  if(tnewEquipments) newEquipments.push(tnewEquipments); 
+                  if(tnewEquipments) newEquipments.push(tnewEquipments);
+                  if(tnewGatherFees) newGatherFees.push(tnewGatherFees);
                 }
 
                 if(newProjectSettings.length > 0) await insertMany(newProjectSettings,projectSettingModel)
@@ -2823,6 +2840,7 @@ async function importProjects(data,req,updateData) {
                 if(newCalcProgramsFiles.length > 0) await insertMany(newCalcProgramsFiles,calcProgramsModel);
                 if(newLabourCoes.length > 0) await insertMany(newLabourCoes,labourCoesModel); 
                 if(newEquipments.length > 0) await insertMany(newEquipments,equipmentPurchaseModel); 
+                if(newGatherFees.length > 0) await insertMany(newGatherFees,gaterFeeModel); 
 
             }
 
@@ -2836,7 +2854,7 @@ async function importProjects(data,req,updateData) {
 
 async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgramFileIDMap){
     let bills = [],rations = [],projectGLJs = [],installationFees=[],rationGLJs=[],rationCoes=[],quantityDetails=[],rationInstallations=[],rationTemplates=[],evaluateList=[],bidList=[],contractorList=[];
-    let newProjectSetting =null,newCalcProgramsFile = null,newLabourCoe = null,newEquipments = null;
+    let newProjectSetting =null,newCalcProgramsFile = null,newLabourCoe = null,newEquipments = null, newGatherFees = null;
     let billsIDMap = {},projectGLJIDMap={},rationIDMap = {};
     let newProjectID = projectIDMap[data.projectID];
     //生成安装增加费设置
@@ -2924,9 +2942,15 @@ async function handleEachProject(data,projectIDMap,labourCoeFileIDMap,calcProgra
         delete newEquipments._id; 
     }
 
+    if (data.gatherFees) {
+        data.gatherFees.projectID = newProjectID;
+        newGatherFees = data.gatherFees;
+        delete newGatherFees._id;
+    }
+
 
 
-    return [newProjectSetting,bills,rations,installationFees,projectGLJs,rationGLJs,rationCoes,quantityDetails,rationInstallations,rationTemplates,evaluateList,bidList,contractorList,newCalcProgramsFile,newLabourCoe,newEquipments]
+    return [newProjectSetting,bills,rations,installationFees,projectGLJs,rationGLJs,rationCoes,quantityDetails,rationInstallations,rationTemplates,evaluateList,bidList,contractorList,newCalcProgramsFile,newLabourCoe,newEquipments,newGatherFees]
 
 }
 function setMaterialList(datas,newProjectID,projectGLJIDMap){

+ 10 - 7
modules/reports/controllers/rpt_controller.js

@@ -212,12 +212,14 @@ async function getAllPagesCommon(construct_id, user_id, prj_id, prj_ids, rpt_id,
             let promiseArr = [null, null, null];
             if (summaryRst.length > 0) {
                 if (summaryRst.indexOf(`Budget`) >= 0 || summaryRst.indexOf(`BudgetDetail`) >= 0) {
-                    if (flag.budgetSumType && flag.budgetSumType === 'budget_single') {
-                        //单项工程
-                        promiseArr[0] = bill_facade.getSinglesBudgetSummary(construct_id); //与其他汇总类的请求互斥,不能同时出现!
-                    } else {
-                        promiseArr[0] = bill_facade.getBudgetSummary(construct_id); //与其他汇总类的请求互斥,不能同时出现!
-                    }
+                    promiseArr[0] = bill_facade.getBudgetSummary(construct_id); //与其他汇总类的请求互斥,不能同时出现!
+                    // if (flag.budgetSumType && flag.budgetSumType === 'budget_construct') {
+                    //     //建设项目level
+                    //     promiseArr[0] = bill_facade.getBudgetSummary(construct_id); //与其他汇总类的请求互斥,不能同时出现!
+                    // } else {
+                    //     //单项工程level
+                    //     promiseArr[0] = bill_facade.getSinglesBudgetSummary(construct_id); //与其他汇总类的请求互斥,不能同时出现!
+                    // }
                 }
                 if (summaryRst.indexOf(`Construct`) >= 0 || summaryRst.indexOf(`ConstructDetail`) >= 0) {
                     promiseArr[0] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.project);
@@ -402,10 +404,11 @@ async function getAllPagesCommon(construct_id, user_id, prj_id, prj_ids, rpt_id,
                                     rawDataObj.BudgetCalcTypeDetail = [];
                                     for (let doc of rst) {
                                         for (let calc of doc.calcPrograms) {
-                                            rawDataObj.BudgetCalcType.push({projectID: doc.projectID, name: calc.name, totalFee: calc.totalFee});
+                                            rawDataObj.BudgetCalcType.push({projectID: doc.projectID, bID: (doc.projectID + '_' + calc.ID), name: calc.name, totalFee: calc.totalFee});
                                             if (calc.calcItems && calc.calcItems.length > 0) {
                                                 for (let cdtlItem of calc.calcItems) {
                                                     cdtlItem.projectID = doc.projectID; //额外加的所属projectID
+                                                    cdtlItem.bID = (doc.projectID + '_' + calc.ID); //额外加的所属父节点ID,projectID + calc本身ID
                                                     rawDataObj.BudgetCalcTypeDetail.push(cdtlItem);
                                                 }
                                                 // rawDataObj.BudgetCalcTypeDetail.push(calc.calcItems);

+ 3 - 4
web/building_saas/main/js/models/calc_program.js

@@ -2889,9 +2889,8 @@ class CalcProgram {
             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);
+            calcItem.unitFee = (eval(calcItem.compiledExpr) * feeRate * 0.01).toDecimal(decimalObj.ration.unitPrice);
+            calcItem.totalFee = (calcItem.unitFee * 1).toDecimal(decimalObj.ration.totalPrice);
 
             if (calcItem.fieldName =='common') {
                 template.totalFee = calcItem.totalFee;
@@ -2920,7 +2919,7 @@ class CalcProgram {
             rst.calcPrograms.push(obj.template);
             temp = temp + obj.value;
         }
-        rst.totalFee = temp.toDecimal(decimalObj.bills.totalPrice);
+        rst.totalFee = temp.toDecimal(decimalObj.ration.totalPrice);
         let oldValue = projectObj.project.mainTree.items[0].data.totalFee;
         if (oldValue != rst.totalFee){
           projectObj.project.mainTree.items[0].data.totalFee = rst.totalFee;