|
@@ -20,7 +20,7 @@ let bill_Model = require('../models/bills').model;
|
|
let billsLibDao = require("../../bills_lib/models/bills_lib_interfaces");
|
|
let billsLibDao = require("../../bills_lib/models/bills_lib_interfaces");
|
|
const pmFacade = require('../../pm/facade/pm_facade');
|
|
const pmFacade = require('../../pm/facade/pm_facade');
|
|
const { getSortedTreeData, getEngineeringFeeType } = require('../../../public/common_util');
|
|
const { getSortedTreeData, getEngineeringFeeType } = require('../../../public/common_util');
|
|
-const { billType, constructionFeeNodeID, constructionEquipmentFeeNodeID, BudgetArea, fixedFlag } = require('../../../public/common_constants');
|
|
|
|
|
|
+const { billType, constructionFeeNodeID, constructionEquipmentFeeNodeID, BudgetArea, fixedFlag, BudgetType } = require('../../../public/common_constants');
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
const uuidV1 = require('uuid/v1');
|
|
const uuidV1 = require('uuid/v1');
|
|
const equipmentFacade = require('../../equipment_purchase/facade/equipment_purchase_facade');
|
|
const equipmentFacade = require('../../equipment_purchase/facade/equipment_purchase_facade');
|
|
@@ -149,10 +149,12 @@ module.exports={
|
|
// 获取概算汇总初始化数据
|
|
// 获取概算汇总初始化数据
|
|
initialBudgetSummary: async function (constructionID) {
|
|
initialBudgetSummary: async function (constructionID) {
|
|
const treeData = await this.getBudgetSummary(constructionID);
|
|
const treeData = await this.getBudgetSummary(constructionID);
|
|
- const construction = await projectModel.findOne({ ID: constructionID }, { 'property.costGrowthRate': 1, 'property.growthPeriod': 1 }).lean();
|
|
|
|
|
|
+ const construction = await projectModel.findOne({ ID: constructionID }, { 'property.costGrowthRate': 1, 'property.growthPeriod': 1, 'property.budgetType': 1 }).lean();
|
|
const costGrowthRate = construction && construction.property && construction.property.costGrowthRate || 0;
|
|
const costGrowthRate = construction && construction.property && construction.property.costGrowthRate || 0;
|
|
const growthPeriod = construction && construction.property && construction.property.growthPeriod || 0;
|
|
const growthPeriod = construction && construction.property && construction.property.growthPeriod || 0;
|
|
|
|
+ const budgetType = construction && construction.property && construction.property.budgetType || BudgetType.BUILDING;
|
|
return {
|
|
return {
|
|
|
|
+ budgetType,
|
|
treeData,
|
|
treeData,
|
|
costGrowthRate,
|
|
costGrowthRate,
|
|
growthPeriod,
|
|
growthPeriod,
|
|
@@ -164,13 +166,18 @@ module.exports={
|
|
const task = [];
|
|
const task = [];
|
|
for (const constructionID of constructionIDs) {
|
|
for (const constructionID of constructionIDs) {
|
|
task.push(this.getBudgetSummary(constructionID, true));
|
|
task.push(this.getBudgetSummary(constructionID, true));
|
|
-
|
|
|
|
}
|
|
}
|
|
const summaryResult = await Promise.all(task);
|
|
const summaryResult = await Promise.all(task);
|
|
summaryResult.forEach(items => {
|
|
summaryResult.forEach(items => {
|
|
|
|
+ const constructionBudget = items.find(item => item.flags && item.flags[0] && item.flags[0].flag === fixedFlag.CONSTRUCTION_BUDGET);
|
|
items.forEach(item => {
|
|
items.forEach(item => {
|
|
if (item.orgProjectID) {
|
|
if (item.orgProjectID) {
|
|
map[item.orgProjectID] = item;
|
|
map[item.orgProjectID] = item;
|
|
|
|
+ if (item.projType === 'Project' && constructionBudget) {
|
|
|
|
+ // 建设项目的总价需要取建设项目总概算
|
|
|
|
+ map[item.orgProjectID].totalFee = constructionBudget.totalFee;
|
|
|
|
+ map[item.orgProjectID].fees = constructionBudget.fees;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -215,6 +222,7 @@ module.exports={
|
|
item.equipmentFee = equipmentFeeItem ? equipmentFeeItem.totalFee : 0;
|
|
item.equipmentFee = equipmentFeeItem ? equipmentFeeItem.totalFee : 0;
|
|
item.otherFee = otherFeeItem ? otherFeeItem.totalFee : 0;
|
|
item.otherFee = otherFeeItem ? otherFeeItem.totalFee : 0;
|
|
item.totalFee = totalFeeItem ? totalFeeItem.totalFee : 0;
|
|
item.totalFee = totalFeeItem ? totalFeeItem.totalFee : 0;
|
|
|
|
+ item.unitFee = totalFeeItem ? totalFeeItem.unitFee : 0;
|
|
// 计算占总投资比例
|
|
// 计算占总投资比例
|
|
const rate = totalFee ? scMathUtil.roundForObj(item.totalFee / totalFee, 4) : 0;
|
|
const rate = totalFee ? scMathUtil.roundForObj(item.totalFee / totalFee, 4) : 0;
|
|
item.rate = rate * 100; // 转换为百分比
|
|
item.rate = rate * 100; // 转换为百分比
|
|
@@ -223,7 +231,7 @@ module.exports={
|
|
},
|
|
},
|
|
// 获取工程费用数据,作为概算汇总数据的拼接树数据
|
|
// 获取工程费用数据,作为概算汇总数据的拼接树数据
|
|
getConstructionFeeData: async function (constructionID, nextID) {
|
|
getConstructionFeeData: async function (constructionID, nextID) {
|
|
- const projects = await pmFacade.getPosterityProjects([constructionID], true, { _id: 0, ID: 1, ParentID: 1, NextSiblingID: 1, name: 1, projType: 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, 'property.engineeringName': 1});
|
|
const construction = projects.find(p => p.ID === constructionID);
|
|
const construction = projects.find(p => p.ID === constructionID);
|
|
const items = getSortedTreeData(construction.ParentID, projects);
|
|
const items = getSortedTreeData(construction.ParentID, projects);
|
|
// 转换为uuid
|
|
// 转换为uuid
|
|
@@ -324,16 +332,31 @@ module.exports={
|
|
unitFeeObj[feeType] = unitFee;
|
|
unitFeeObj[feeType] = unitFee;
|
|
singleFeeObj[feeType] = scMathUtil.roundForObj(singleFeeObj[feeType] + unitFee, processDecimal);
|
|
singleFeeObj[feeType] = scMathUtil.roundForObj(singleFeeObj[feeType] + unitFee, processDecimal);
|
|
}
|
|
}
|
|
- unit.fees = feeObj2Fees(unitFeeObj);
|
|
|
|
|
|
+ unit.fees = feeObj2Fees(unitFeeObj, unit.quantity);
|
|
}
|
|
}
|
|
- single.fees = feeObj2Fees(singleFeeObj);
|
|
|
|
|
|
+ single.fees = feeObj2Fees(singleFeeObj, single.quantity);
|
|
// 汇算到建设项目
|
|
// 汇算到建设项目
|
|
constructionFeeObj.total = scMathUtil.roundForObj(constructionFeeObj.total + singleFeeObj.total, processDecimal);
|
|
constructionFeeObj.total = scMathUtil.roundForObj(constructionFeeObj.total + singleFeeObj.total, processDecimal);
|
|
constructionFeeObj.building = scMathUtil.roundForObj(constructionFeeObj.building + singleFeeObj.building, processDecimal);
|
|
constructionFeeObj.building = scMathUtil.roundForObj(constructionFeeObj.building + singleFeeObj.building, processDecimal);
|
|
constructionFeeObj.installation = scMathUtil.roundForObj(constructionFeeObj.installation + singleFeeObj.installation, processDecimal);
|
|
constructionFeeObj.installation = scMathUtil.roundForObj(constructionFeeObj.installation + singleFeeObj.installation, processDecimal);
|
|
constructionFeeObj.equipment = scMathUtil.roundForObj(constructionFeeObj.equipment + singleFeeObj.equipment, processDecimal);
|
|
constructionFeeObj.equipment = scMathUtil.roundForObj(constructionFeeObj.equipment + singleFeeObj.equipment, processDecimal);
|
|
}
|
|
}
|
|
- construction.fees = feeObj2Fees(constructionFeeObj);
|
|
|
|
|
|
+ construction.fees = feeObj2Fees(constructionFeeObj, construction.quantity);
|
|
|
|
+ // 更新fees字段
|
|
|
|
+ const bulks = [];
|
|
|
|
+ items.forEach(item => {
|
|
|
|
+ if (item.orgProjectID && item.fees) {
|
|
|
|
+ bulks.push({
|
|
|
|
+ updateOne: {
|
|
|
|
+ filter: { ID: item.orgProjectID },
|
|
|
|
+ update: { $set: { fees: item.fees } }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (bulks.length) {
|
|
|
|
+ await projectModel.bulkWrite(bulks);
|
|
|
|
+ }
|
|
// 获取设备购置费(旧)
|
|
// 获取设备购置费(旧)
|
|
/* const equipmentFee = await this.getEquipmentFee(unitProjectIDs);
|
|
/* const equipmentFee = await this.getEquipmentFee(unitProjectIDs);
|
|
const equipmentItem = items.find(item => item.flags && item.flags[0] && item.flags[0].flag === fixedFlag.CONSTRUCTION_EQUIPMENT_FEE);
|
|
const equipmentItem = items.find(item => item.flags && item.flags[0] && item.flags[0].flag === fixedFlag.CONSTRUCTION_EQUIPMENT_FEE);
|
|
@@ -343,9 +366,14 @@ module.exports={
|
|
}
|
|
}
|
|
construction.fees.push(equipmentFeeObj); */
|
|
construction.fees.push(equipmentFeeObj); */
|
|
|
|
|
|
- function feeObj2Fees(feeObj) {
|
|
|
|
|
|
+ function feeObj2Fees(feeObj, quantity) {
|
|
|
|
+ const totalFee = scMathUtil.roundForObj(feeObj.total, decimal)
|
|
|
|
+ let unitFee = 0;
|
|
|
|
+ if (+quantity && totalFee) {
|
|
|
|
+ unitFee = scMathUtil.roundForObj(totalFee / (+quantity), 2);
|
|
|
|
+ }
|
|
return [
|
|
return [
|
|
- { fieldName: 'common', totalFee: scMathUtil.roundForObj(feeObj.total, decimal) },
|
|
|
|
|
|
+ { fieldName: 'common', totalFee: scMathUtil.roundForObj(feeObj.total, decimal), unitFee },
|
|
{ fieldName: 'building', totalFee: scMathUtil.roundForObj(feeObj.building, decimal) },
|
|
{ fieldName: 'building', totalFee: scMathUtil.roundForObj(feeObj.building, decimal) },
|
|
{ fieldName: 'installation', totalFee: scMathUtil.roundForObj(feeObj.installation, decimal) },
|
|
{ fieldName: 'installation', totalFee: scMathUtil.roundForObj(feeObj.installation, decimal) },
|
|
{ fieldName: 'equipment', totalFee: scMathUtil.roundForObj(feeObj.equipment, decimal) },
|
|
{ fieldName: 'equipment', totalFee: scMathUtil.roundForObj(feeObj.equipment, decimal) },
|