|
@@ -23,6 +23,8 @@ const { getSortedTreeData, getEngineeringFeeType } = require('../../../public/co
|
|
|
const { billType, constructionFeeNodeID, constructionEquipmentFeeNodeID, BudgetArea, fixedFlag } = require('../../../public/common_constants');
|
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
const uuidV1 = require('uuid/v1');
|
|
|
+const equipmentFacade = require('../../equipment_purchase/facade/equipment_purchase_facade');
|
|
|
+const gatherModel = mongoose.model('gather_calc_programs');
|
|
|
|
|
|
const GLJController = require("../../glj/controllers/glj_controller");
|
|
|
|
|
@@ -129,17 +131,28 @@ module.exports={
|
|
|
await bill_Model.bulkWrite(bulks);
|
|
|
}
|
|
|
},
|
|
|
- // 获取单位工程ID 工程费用 映射表
|
|
|
+ // 获取单位工程ID 工程费用(费用汇总里的totalFee) 映射表
|
|
|
getUnitsBudgetMap: async function (unitIDs) {
|
|
|
const rst = {};
|
|
|
- unitIDs.forEach(unitID => {
|
|
|
+ /* unitIDs.forEach(unitID => {
|
|
|
rst[unitID] = 1000000;
|
|
|
+ }); */
|
|
|
+ const gatherData = await gatherModel.find({ projectID: { $in: unitIDs } }, '-_id projectID totalFee').lean();
|
|
|
+ const gatherMap = {};
|
|
|
+ gatherData.forEach(item => gatherMap[item.projectID] = item.totalFee || 0);
|
|
|
+ unitIDs.forEach(unitID => {
|
|
|
+ rst[unitID] = gatherMap[unitID] || 0;
|
|
|
});
|
|
|
return rst;
|
|
|
},
|
|
|
// 获取设备购置费
|
|
|
- getEquipmentFee: async function (unitIDs) {
|
|
|
- return 5000.15;
|
|
|
+ getUnitsEquipmentMap: async function (unitIDs) {
|
|
|
+ /* const rst = {};
|
|
|
+ unitIDs.forEach(unitID => {
|
|
|
+ rst[unitID] = 5000;
|
|
|
+ });
|
|
|
+ return rst; */
|
|
|
+ return await equipmentFacade.getEquipmentTotalCost(unitIDs);
|
|
|
},
|
|
|
// 获取概算汇总初始化数据
|
|
|
initialBudgetSummary: async function (constructionID) {
|
|
@@ -164,6 +177,12 @@ module.exports={
|
|
|
// 汇算工程费用
|
|
|
await this.summarizeData(constructionFeeBills);
|
|
|
const rst = [...constructionFeeBills, ...sortedOtherFeeBills];
|
|
|
+ const totalItem = rst.find(item => item.flags && item.flags[0] && item.flags[0].flag === fixedFlag.CONSTRUCTION_BUDGET);
|
|
|
+ let totalFee = 0;
|
|
|
+ if (totalItem) {
|
|
|
+ const totalFeeItem = totalItem.fees && totalItem.fees.find(f => f.fieldName === 'common');
|
|
|
+ totalFee = totalFeeItem ? +totalFeeItem.totalFee : 0;
|
|
|
+ }
|
|
|
// 方便报表取数据,规范数据
|
|
|
rst.forEach(item => {
|
|
|
item.code = item.code || '';
|
|
@@ -180,7 +199,9 @@ module.exports={
|
|
|
item.equipmentFee = equipmentFeeItem ? equipmentFeeItem.totalFee : 0;
|
|
|
item.otherFee = otherFeeItem ? otherFeeItem.totalFee : 0;
|
|
|
item.totalFee = totalFeeItem ? totalFeeItem.totalFee : 0;
|
|
|
- item.rate = '0';
|
|
|
+ // 计算占总投资比例
|
|
|
+ const rate = totalFee ? scMathUtil.roundForObj(item.totalFee / totalFee, 4) : 0;
|
|
|
+ item.rate = rate * 100; // 转换为百分比
|
|
|
});
|
|
|
return rst;
|
|
|
},
|
|
@@ -205,7 +226,7 @@ module.exports={
|
|
|
let curSingleNo = 0;
|
|
|
let curSingleID;
|
|
|
let curUnitNo = 0;
|
|
|
- let latestSingleNode;
|
|
|
+ // let latestSingleNode;
|
|
|
items.forEach((item, index) => {
|
|
|
item.area = BudgetArea.CONSTRUCTION_FEE;
|
|
|
item.ID = IDMap[item.ID];
|
|
@@ -221,7 +242,7 @@ module.exports={
|
|
|
} else {
|
|
|
item.type = billType.BILL;
|
|
|
if (item.ParentID === curConstructionID) {
|
|
|
- latestSingleNode = item;
|
|
|
+ // latestSingleNode = item;
|
|
|
curSingleNo += 1;
|
|
|
curUnitNo = 0;
|
|
|
curSingleID = item.ID;
|
|
@@ -232,7 +253,7 @@ module.exports={
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- const constructionFeeNode = items[0];
|
|
|
+ /* const constructionFeeNode = items[0];
|
|
|
// 设备及工器具购置费
|
|
|
const constructionEquipmentNode = {
|
|
|
type: billType.BILL,
|
|
@@ -245,7 +266,7 @@ module.exports={
|
|
|
name: '设备及工器具购置费',
|
|
|
};
|
|
|
latestSingleNode.NextSiblingID = constructionEquipmentNode.ID;
|
|
|
- items.push(constructionEquipmentNode);
|
|
|
+ items.push(constructionEquipmentNode); */
|
|
|
return items;
|
|
|
},
|
|
|
// 汇算数据
|
|
@@ -264,18 +285,23 @@ module.exports={
|
|
|
// 获取第一个单位工程的小数位数(清单合价)
|
|
|
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;
|
|
|
- // 获取单位工程 工程费用映射表
|
|
|
+ // 获取单位工程 -工程费用映射表
|
|
|
const unitBudgetMap = await this.getUnitsBudgetMap(unitProjectIDs);
|
|
|
+ // 获取单位工程 - 设备购置费映射表
|
|
|
+ const unitEquipmentMap = await this.getUnitsEquipmentMap(unitProjectIDs);
|
|
|
// 汇算
|
|
|
- const constructionFeeObj = { total: 0, building: 0, installation: 0 };
|
|
|
+ const constructionFeeObj = { total: 0, building: 0, installation: 0, equipment: 0 };
|
|
|
for (const single of singles) {
|
|
|
- const singleFeeObj = { total: 0, building: 0, installation: 0 };
|
|
|
+ const singleFeeObj = { total: 0, building: 0, installation: 0, equipment: 0 };
|
|
|
const refUnits = units.filter(unit => unit.ParentID === single.ID);
|
|
|
for (const unit of refUnits) {
|
|
|
- const unitFee = unitBudgetMap[unit.orgProjectID];
|
|
|
+ const unitFee = unitBudgetMap[unit.orgProjectID]; // 费用汇总算出来的值
|
|
|
+ const unitEquipmentFee = unitEquipmentMap[unit.orgProjectID]; // 设备购置窗口的值
|
|
|
+ const unitTotalFee = scMathUtil.roundForObj(unitFee + unitEquipmentFee, decimal); // 费用汇总算出来的值 + 设备购置值
|
|
|
// 汇算到单项工程
|
|
|
- singleFeeObj.total = scMathUtil.roundForObj(singleFeeObj.total + unitFee, processDecimal);
|
|
|
- const unitFeeObj = { total: unitFee || 0, building: 0, installation: 0 };
|
|
|
+ singleFeeObj.total = scMathUtil.roundForObj(singleFeeObj.total + unitTotalFee, processDecimal);
|
|
|
+ singleFeeObj.equipment = scMathUtil.roundForObj(singleFeeObj.equipment + unitEquipmentFee, processDecimal);
|
|
|
+ const unitFeeObj = { total: unitTotalFee || 0, building: 0, installation: 0, equipment: unitEquipmentFee || 0 };
|
|
|
// 建筑工程费、安装工程费
|
|
|
const feeType = getEngineeringFeeType(unit.property && unit.property.engineeringName || '');
|
|
|
if (feeType) {
|
|
@@ -289,22 +315,24 @@ module.exports={
|
|
|
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);
|
|
|
- // 获取设备购置费
|
|
|
- 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 equipmentFeeObj = { fieldName: 'equipment', totalFee: equipmentFee };
|
|
|
if (equipmentItem) {
|
|
|
equipmentItem.fees = [equipmentFeeObj];
|
|
|
}
|
|
|
- construction.fees.push(equipmentFeeObj);
|
|
|
+ construction.fees.push(equipmentFeeObj); */
|
|
|
|
|
|
function feeObj2Fees(feeObj) {
|
|
|
return [
|
|
|
{ fieldName: 'common', totalFee: scMathUtil.roundForObj(feeObj.total, decimal) },
|
|
|
{ fieldName: 'building', totalFee: scMathUtil.roundForObj(feeObj.building, decimal) },
|
|
|
{ fieldName: 'installation', totalFee: scMathUtil.roundForObj(feeObj.installation, decimal) },
|
|
|
+ { fieldName: 'equipment', totalFee: scMathUtil.roundForObj(feeObj.equipment, decimal) },
|
|
|
];
|
|
|
}
|
|
|
},
|