Browse Source

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

vian 4 years ago
parent
commit
97539c1b8a

+ 19 - 3
modules/equipment_purchase/facade/equipment_purchase_facade.js

@@ -59,15 +59,31 @@ function sortEquipments(equipments) {
 
 async function getEquipmentSummary(projectIDs) {
      let data = [];
-     if(projectIDs.length > 0){
+     if (projectIDs.length > 0) {
          let map = {};
         let equipments = await equipmentPurchaseModel.find({projectID:{$in: projectIDs}}).lean();
-        for(let e of equipments){
+        for (let e of equipments) {
            e.equipments = sortEquipments(e.equipments);
            map[e.projectID] = e;
         }
-        for(let projectID of projectIDs ){
+        for (let projectID of projectIDs ) {
+            /*
             if(map[projectID]) data.push(map[projectID]);
+            /*/
+            // 以下是根据实际来调整
+            if(map[projectID]) {
+                for (let item of map[e.projectID].equipments) {
+                    let dtlData = {projectID: -1, total: 0, equipSummaryType: 'budget_equipment'};
+                    // 属性summaryType是作为一个判断依据给后来代码用
+                    dtlData.projectID = projectID;
+                    dtlData.total = item.total;
+                    for (let key in item) {
+                        dtlData[key] = item[key];
+                    }
+                    data.push(dtlData);
+                }
+            }
+            //*/
         }
     }
     return data;

+ 2 - 1
modules/main/facade/calc_program_facade.js

@@ -25,7 +25,8 @@ module.exports = {
     updateTemplateFile: updateTemplateFile,
     addTemplate: addTemplate,
     deleteTemplate: deleteTemplate,
-    saveGatherCalcPrograms: saveGatherCalcPrograms
+    saveGatherCalcPrograms: saveGatherCalcPrograms,
+    getGatherFees: getGatherFees
 };
 
 async function newProjectCalcProgramFile(data) {

+ 3 - 1
modules/main/models/project_consts.js

@@ -55,7 +55,9 @@ let summaryConstList = [
     `Segment`,
     `SegmentDetail`,
     'Budget',
-    'BudgetDetail'
+    'BudgetDetail',
+    'BudgetCalcType',
+    'BudgetCalcTypeDetail'
 ];
 
 let projectFieldConstList = [

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

@@ -12,6 +12,8 @@ let rptTplDataFacade = require("../facade/rpt_tpl_data_facade");
 let fsUtil = require("../../../public/fsUtil");
 let pm_facade = require('../../../modules/pm/facade/pm_facade');
 let bill_facade = require('../../../modules/main/facade/bill_facade');
+let equipment_facade = require('../../../modules/equipment_purchase/facade/equipment_purchase_facade');
+let calcProgramFacade = require('../../../modules/main/facade/calc_program_facade');
 
 const rptTplFacade = require("../facade/rpt_template_facade");
 const demoTemplateFacade = require("../facade/rpt_tpl_data_demo_facade");
@@ -215,6 +217,12 @@ async function getAllPagesCommon(construct_id, user_id, prj_id, prj_ids, rpt_id,
                 if (summaryRst.indexOf(`Construct`) >= 0 || summaryRst.indexOf(`ConstructDetail`) >= 0) {
                     promiseArr[0] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.project);
                 }
+                if (summaryRst.indexOf(`BudgetEquipmentDetail`) >= 0) {
+                    promiseArr[0] = equipment_facade.getEquipmentSummary(prj_ids);
+                }
+                if (summaryRst.indexOf(`BudgetCalcType`) >= 0 || summaryRst.indexOf(`BudgetCalcTypeDetail`) >= 0) {
+                    promiseArr[1] = calcProgramFacade.getGatherFees(prj_ids); //与其他汇总类的请求互斥,不能同时出现!
+                }
                 if (summaryRst.indexOf(`Segment`) >= 0 || summaryRst.indexOf(`SegmentDetail`) >= 0) {
                     promiseArr[1] = pm_facade.getSummaryInfoByTender(prj_id, pm_facade.projectType.engineering);
                 }
@@ -266,7 +274,7 @@ async function getAllPagesCommon(construct_id, user_id, prj_id, prj_ids, rpt_id,
                     cb('Exception occurs while on going...', null);
                 }
             };
-        if (flag !== undefined && flag !== null && (flag.constructSumType === 'constructSum' || flag.auditType === 'audit_compare')) {
+        if (flag !== undefined && flag !== null && (flag.constructSumType === 'constructSum' || flag.auditType === 'audit_compare' || flag.budgetSumType === 'budget_single')) {
                 //备注:原先这个功能是为了合并建设项目下所有的单位工程的数据,
                 //     现在发现就是通用型,审核对比也可以用这个逻辑把数据合并在一起再处理(审核对比的处理逻辑放在模板计算式里)
                 try {
@@ -333,13 +341,36 @@ async function getAllPagesCommon(construct_id, user_id, prj_id, prj_ids, rpt_id,
                                     rawDataObj.Construct = rst.parent;
                                     rawDataObj.ConstructDetail = rst.subList;
                                 } else {
-                                    rawDataObj.Budget = [];
-                                    rawDataObj.BudgetDetail = rst;
+                                    if (rst instanceof Array) {
+                                        if (rst.length > 0) {
+                                            if (rst[0].hasOwnProperty('equipSummaryType')) {
+                                                rawDataObj.BudgetEquipmentDetail = rst;
+                                            } else {
+                                                rawDataObj.Budget = [];
+                                                rawDataObj.BudgetDetail = rst;
+                                            }
+                                        } else {
+                                            rawDataObj.Budget = [];
+                                            rawDataObj.BudgetDetail = rst;
+                                            rawDataObj.BudgetEquipmentDetail = rst;
+                                        }
+                                    }
                                 }
                                 if (promiseArr[1] !== null) {
                                     promiseArr[1].then(function (rst2) {
-                                        rawDataObj.Segment = rst2.parent;
-                                        rawDataObj.SegmentDetail = rst2.subList;
+                                        if (rst2.hasOwnProperty('parent')) {
+                                            rawDataObj.Segment = rst2.parent;
+                                            rawDataObj.SegmentDetail = rst2.subList;
+                                        } else {
+                                            rawDataObj.BudgetCalcType = [];
+                                            rawDataObj.BudgetCalcTypeDetail = [];
+                                            for (let doc of rst2) {
+                                                for (let calc of doc.calcPrograms) {
+                                                    rawDataObj.BudgetCalcType.push({projectID: doc.projectID, name: calc.name, totalFee: calc.totalFee});
+                                                    rawDataObj.BudgetCalcTypeDetail.push(calc.calcItems);
+                                                }
+                                            }
+                                        }
                                         buildPageData(rawDataObj, rptDataUtil, rptTpl);
                                     });
                                 } else {
@@ -348,8 +379,19 @@ async function getAllPagesCommon(construct_id, user_id, prj_id, prj_ids, rpt_id,
                             });
                         } else  if (promiseArr[1] !== null) {
                             promiseArr[1].then(function (rst) {
-                                rawDataObj.Segment = rst.parent;
-                                rawDataObj.SegmentDetail = rst.subList;
+                                if (rst.hasOwnProperty('parent')) {
+                                    rawDataObj.Segment = rst.parent;
+                                    rawDataObj.SegmentDetail = rst.subList;
+                                } else {
+                                    rawDataObj.BudgetCalcType = [];
+                                    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.BudgetCalcTypeDetail.push(calc.calcItems);
+                                        }
+                                    }
+                                }
                                 buildPageData(rawDataObj, rptDataUtil, rptTpl);
                             });
                         } else {

+ 10 - 1
modules/reports/util/rpt_construct_data_util.js

@@ -373,7 +373,7 @@ class Rpt_Data_Extractor {
         }
         //还有汇总的...
         if (rawDataObj.hasOwnProperty(`Construct`) || rawDataObj.hasOwnProperty(`ConstructDetail`) || rawDataObj.hasOwnProperty(`Segment`) || rawDataObj.hasOwnProperty(`SegmentDetail`)
-        || rawDataObj.hasOwnProperty(`Budget`) || rawDataObj.hasOwnProperty(`BudgetDetail`)) {
+        || rawDataObj.hasOwnProperty(`Budget`) || rawDataObj.hasOwnProperty(`BudgetDetail`) || rawDataObj.hasOwnProperty(`BudgetCalcType`)) {
             $PROJECT.SUMMARY = {};
             if (rawDataObj.Construct) {
                 setupMainFunc($PROJECT.SUMMARY, `Construct`, rawDataObj.Construct);
@@ -393,6 +393,15 @@ class Rpt_Data_Extractor {
             if (rawDataObj.BudgetDetail) {
                 setupFunc($PROJECT.SUMMARY, `BudgetDetail`, {"data": rawDataObj.BudgetDetail});
             }
+            if (rawDataObj.BudgetCalcType) {
+                setupFunc($PROJECT.SUMMARY, `BudgetCalcType`, {"data": rawDataObj.BudgetCalcType});
+            }
+            if (rawDataObj.BudgetCalcTypeDetail) {
+                setupFunc($PROJECT.SUMMARY, `BudgetCalcTypeDetail`, {"data": rawDataObj.BudgetCalcTypeDetail});
+            }
+            if (rawDataObj.BudgetEquipmentDetail) {
+                setupFunc($PROJECT.SUMMARY, `BudgetEquipmentDetail`, {"data": rawDataObj.BudgetEquipmentDetail});
+            }
         }
 
         if (tpl[JV.NODE_MAP_DATA_HANDLE_INFO]) {