Browse Source

feat: 概算、估算经济指标算法调整

vian 4 years ago
parent
commit
555f97f858

+ 29 - 9
modules/main/facade/bill_facade.js

@@ -277,10 +277,11 @@ module.exports={
             item.equipmentFee = equipmentFeeItem ? equipmentFeeItem.totalFee : 0;
             item.otherFee = otherFeeItem ? otherFeeItem.totalFee : 0;
             item.totalFee = totalFeeItem ? totalFeeItem.totalFee : 0;
-            item.estimateFee = estimateFeeItem ? estimateFeeItem.totalFee : 0;
+            item.estimateTotalFee = estimateFeeItem ? estimateFeeItem.totalFee : 0;
+            item.estimateUnitFee = estimateFeeItem ? estimateFeeItem.unitFee : 0;
             item.unitFee = totalFeeItem ? totalFeeItem.unitFee : 0;
-            item.diffFee = item.estimateFee - item.totalFee;  // 增减金额 估算合价-概算合价
-            item.diffRate = item.estimateFee ? scMathUtil.roundForObj((item.diffFee / item.estimateFee) * 100, 4) : 0; // 增减金额/估算合价*100
+            item.diffFee = item.estimateTotalFee - item.totalFee;  // 增减金额 估算合价-概算合价
+            item.diffRate = item.estimateTotalFee ? scMathUtil.roundForObj((item.diffFee / item.estimateTotalFee) * 100, 4) : 0; // 增减金额/估算合价*100
             // 计算占总投资比例
             item.rate = totalFee ?  scMathUtil.roundForObj((item.totalFee / totalFee) * 100, 4) : 0;
         });
@@ -288,7 +289,7 @@ module.exports={
     },
     // 获取工程费用数据,作为概算汇总数据的拼接树数据
     getConstructionFeeData: async function (constructionID, nextID) {
-        const projects = await pmFacade.getPosterityProjects([constructionID], true, { _id: 0, ID: 1, ParentID: 1, NextSiblingID: 1, name: 1, projType: 1, chapterCode: 1, sectionCode: 1, quantity: 1, unit: 1, fees: 1, 'property.engineeringName': 1});
+        const projects = await pmFacade.getPosterityProjects([constructionID], true, { _id: 0, ID: 1, ParentID: 1, NextSiblingID: 1, name: 1, projType: 1, chapterCode: 1, sectionCode: 1, quantity: 1, unit: 1, fees: 1, 'property.engineeringName': 1, 'property.basicInformation': 1 });
         const construction = projects.find(p => p.ID === constructionID);
         const items = getSortedTreeData(construction.ParentID, projects);
         // 转换为uuid
@@ -363,6 +364,21 @@ module.exports={
             return;
         }
         const unitProjectIDs = units.map(unit => unit.orgProjectID);
+        // 工程总量
+        let projectQuantity = 0;
+        // 估算总量
+        let estimateQuantity = 0;
+        for (const item of construction.property.basicInformation) {
+            if (item.key === 'basicInfo' && item.items && item.items.length) {
+                for (const sub of item.items) {
+                    if (sub.key === 'projectQuantity') {
+                        projectQuantity = +sub.value || 0;
+                    } else if (sub.key === 'estimateQuantity') {
+                        estimateQuantity = +sub.value || 0;          
+                    }
+                }
+            }
+        }
         // 获取第一个单位工程的小数位数(清单合价)
         const theUnit = await projectModel.findOne({ ID: unitProjectIDs[0] }, { _id: 0, 'property.decimal': 1 }).lean();
         const decimal = theUnit && theUnit.property && theUnit.property.decimal && theUnit.property.decimal.bills && theUnit.property.decimal.bills.totalPrice || 2;
@@ -389,16 +405,16 @@ module.exports={
                     unitFeeObj[feeType] = unitFee;
                     singleFeeObj[feeType] = scMathUtil.roundForObj(singleFeeObj[feeType] + unitFee, processDecimal);
                 }
-                unit.fees = feeObj2Fees(unitFeeObj, unit.fees, unit.quantity);
+                unit.fees = feeObj2Fees(unitFeeObj, unit.fees, projectQuantity, estimateQuantity);
             }
-            single.fees = feeObj2Fees(singleFeeObj, single.fees, single.quantity);
+            single.fees = feeObj2Fees(singleFeeObj, single.fees, projectQuantity, estimateQuantity);
             // 汇算到建设项目
             constructionFeeObj.total = scMathUtil.roundForObj(constructionFeeObj.total + singleFeeObj.total, processDecimal);
             constructionFeeObj.building = scMathUtil.roundForObj(constructionFeeObj.building + singleFeeObj.building, processDecimal);
             constructionFeeObj.installation = scMathUtil.roundForObj(constructionFeeObj.installation + singleFeeObj.installation, processDecimal);
             constructionFeeObj.equipment = scMathUtil.roundForObj(constructionFeeObj.equipment + singleFeeObj.equipment, processDecimal);
         }
-        construction.fees = feeObj2Fees(constructionFeeObj, construction.fees, construction.quantity);
+        construction.fees = feeObj2Fees(constructionFeeObj, construction.fees, projectQuantity, estimateQuantity);
         // 更新fees字段
         const bulks = [];
         items.forEach(item => {
@@ -423,7 +439,7 @@ module.exports={
         }
         construction.fees.push(equipmentFeeObj); */
 
-        function feeObj2Fees(feeObj, orgFees, quantity) {
+        function feeObj2Fees(feeObj, orgFees, quantity, estQuantity) {
             const totalFee = scMathUtil.roundForObj(feeObj.total, decimal)
             let unitFee = 0;
             if (+quantity && totalFee) {
@@ -431,12 +447,16 @@ module.exports={
             }
             const estimateItem = orgFees && orgFees.find(item => item.fieldName === 'estimation') || null;
             const estimateFee = estimateItem ? estimateItem.totalFee : 0;
+            let estimateUnitFee = 0;
+            if (+estQuantity && estimateFee) {     
+                estimateUnitFee = scMathUtil.roundForObj(estimateFee / (+estQuantity), 2);
+            }
             return [
                 { fieldName: 'common', totalFee: scMathUtil.roundForObj(feeObj.total, decimal), unitFee },
                 { fieldName: 'building', totalFee: scMathUtil.roundForObj(feeObj.building, decimal) },
                 { fieldName: 'installation', totalFee: scMathUtil.roundForObj(feeObj.installation, decimal) },
                 { fieldName: 'equipment', totalFee: scMathUtil.roundForObj(feeObj.equipment, decimal) },
-                { fieldName: 'estimation', totalFee: estimateFee },
+                { fieldName: 'estimation', totalFee: estimateFee, unitFee: estimateUnitFee },
             ];
         }
     },

+ 1 - 1
web/building_saas/budget-summary/js/budgetSummarySheet.js

@@ -305,7 +305,7 @@ const budgetSummaryObj = (() => {
           const estimationItem = data.fees && data.fees.find(item => item.fieldName === 'estimation');
           const estimationFee = estimationItem ? estimationItem.totalFee : 0;
           if (orgEstimationFee !== estimationFee) {
-            if (!estimationItem) {
+            if (!estimationItem && data.fees) {
               data.fees.push({ fieldName: 'estimation', totalFee: orgEstimationFee });
             }
           }