|
@@ -198,33 +198,36 @@ module.exports={
|
|
|
const budgetTotalFeeItem = budgetTotalItem.fees && budgetTotalItem.fees.find(f => f.fieldName === 'common');
|
|
|
const budgetTotalFee = budgetTotalFeeItem ? +budgetTotalFeeItem.totalFee : 0;
|
|
|
const rst = [];
|
|
|
- for (const project of items) {
|
|
|
- rst.push(project);
|
|
|
+ let seq = 1;
|
|
|
+ let unitIDs = [];
|
|
|
+ for (let i = 0; i < items.length; i++) {
|
|
|
+ const project = items[i];
|
|
|
// 方便报表取值处理
|
|
|
if (project.projType === 'Engineering') {
|
|
|
project.engineeringName = project.name || '';
|
|
|
+ rst.push(project);
|
|
|
+ unitIDs = [];
|
|
|
+ seq = 1;
|
|
|
} else if (project.projType === 'Tender') {
|
|
|
+ project.code = seq++;
|
|
|
project.tenderName = project.name || '';
|
|
|
+ rst.push(project);
|
|
|
+ unitIDs.push(project.orgProjectID);
|
|
|
// 追加分部和设备购置数据
|
|
|
const feeType = getEngineeringFeeType(project.property && project.property.engineeringName || '');
|
|
|
const fbs = await this.getFBData(project.orgProjectID);
|
|
|
- const equipments = await equipmentFacade.getSortedEquipmentData(project.orgProjectID);
|
|
|
- const detailData = [...fbs, ...equipments].map(item => {
|
|
|
+ const detailData = fbs.map(item => {
|
|
|
let totalFee = 0;
|
|
|
- if (item.feeType === 'equipment') {
|
|
|
- totalFee = item.totalPrice || 0;
|
|
|
- } else {
|
|
|
- const totalFeeItem = item.fees && item.fees.find(f => f.fieldName === 'common');
|
|
|
- totalFee = totalFeeItem ? +totalFeeItem.totalFee : 0;
|
|
|
- }
|
|
|
+ const totalFeeItem = item.fees && item.fees.find(f => f.fieldName === 'common');
|
|
|
+ totalFee = totalFeeItem ? +totalFeeItem.totalFee : 0;
|
|
|
// 计算占总投资比例
|
|
|
- const rate = (budgetTotalFee ? scMathUtil.roundForObj(totalFee / budgetTotalFee, 4) : 0) * 100;
|
|
|
+ const rate = (budgetTotalFee ? scMathUtil.roundForObj(totalFee / budgetTotalFee, 2) : 0) * 100;
|
|
|
return {
|
|
|
code: item.code || '',
|
|
|
name: item.name || '',
|
|
|
- buildingFee: item.feeType !== 'equipment' && feeType === 'building' ? totalFee : 0,
|
|
|
- installationFee: item.feeType !== 'equipment' && feeType === 'installation' ? totalFee : 0,
|
|
|
- equipmentFee: item.feeType === 'equipment' ? totalFee : 0,
|
|
|
+ buildingFee: feeType === 'building' ? totalFee : 0,
|
|
|
+ installationFee: feeType === 'installation' ? totalFee : 0,
|
|
|
+ equipmentFee: 0,
|
|
|
otherFee: 0,
|
|
|
totalFee,
|
|
|
rate,
|
|
@@ -233,7 +236,16 @@ module.exports={
|
|
|
rst.push(...detailData);
|
|
|
|
|
|
}
|
|
|
+ const nextProject = items[i + 1];
|
|
|
+ // 插入单项工程的设备购置汇总
|
|
|
+ if ((i === items.length - 1 || (nextProject && nextProject.projType === 'Engineering')) && unitIDs.length) {
|
|
|
+ const unitEquipmentMap = await this.getUnitsEquipmentMap(unitIDs);
|
|
|
+ const equipmentFee = scMathUtil.roundForObj(Object.values(unitEquipmentMap).reduce((total, cur) => total + cur, 0), 0);
|
|
|
+ equipmentRate = (budgetTotalFee ? scMathUtil.roundForObj(equipmentFee / budgetTotalFee, 2) : 0) * 100;
|
|
|
+ rst.push({ code: '', name: '设备购置费', buildingFee: 0, installationFee: 0, equipmentFee, otherFee: 0, totalFee: equipmentFee, rate: equipmentRate });
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
return rst;
|
|
|
},
|
|
|
|
|
@@ -260,6 +272,21 @@ module.exports={
|
|
|
const totalFeeItem = totalItem.fees && totalItem.fees.find(f => f.fieldName === 'common');
|
|
|
totalFee = totalFeeItem ? +totalFeeItem.totalFee : 0;
|
|
|
}
|
|
|
+ // 工程总量
|
|
|
+ let projectQuantity = 0;
|
|
|
+ // 估算总量
|
|
|
+ let estimateQuantity = 0;
|
|
|
+ for (const item of constructionFeeBills[0].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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
// 方便报表取数据,规范数据
|
|
|
rst.forEach(item => {
|
|
|
item.code = item.code || '';
|
|
@@ -278,12 +305,14 @@ module.exports={
|
|
|
item.otherFee = otherFeeItem ? otherFeeItem.totalFee : 0;
|
|
|
item.totalFee = totalFeeItem ? totalFeeItem.totalFee : 0;
|
|
|
item.estimateTotalFee = estimateFeeItem ? estimateFeeItem.totalFee : 0;
|
|
|
- item.estimateUnitFee = estimateFeeItem ? estimateFeeItem.unitFee : 0;
|
|
|
- item.unitFee = totalFeeItem ? totalFeeItem.unitFee : 0;
|
|
|
- item.diffFee = item.totalFee - item.estimateTotalFee; // 增减金额 概算合价 - 估算合价
|
|
|
- item.diffRate = item.estimateTotalFee ? scMathUtil.roundForObj((item.diffFee / item.estimateTotalFee) * 100, 4) : 0; // 增减金额/估算合价*100
|
|
|
+ // item.estimateUnitFee = estimateFeeItem ? estimateFeeItem.unitFee : 0;
|
|
|
+ item.estimateUnitFee = estimateQuantity ? scMathUtil.roundForObj(item.estimateTotalFee / estimateQuantity, 2) : 0;
|
|
|
+ // item.unitFee = totalFeeItem ? totalFeeItem.unitFee : 0;
|
|
|
+ item.unitFee = projectQuantity ? scMathUtil.roundForObj(item.totalFee / projectQuantity, 2) : 0;
|
|
|
+ item.diffFee = scMathUtil.roundForObj(item.totalFee - item.estimateTotalFee, 0); // 增减金额 概算合价 - 估算合价
|
|
|
+ item.diffRate = item.estimateTotalFee ? scMathUtil.roundForObj((item.diffFee / item.estimateTotalFee) * 100, 2) : 0; // 增减金额/估算合价*100
|
|
|
// 计算占总投资比例
|
|
|
- item.rate = totalFee ? scMathUtil.roundForObj((item.totalFee / totalFee) * 100, 4) : 0;
|
|
|
+ item.rate = totalFee ? scMathUtil.roundForObj((item.totalFee / totalFee) * 100, 2) : 0;
|
|
|
});
|
|
|
return rst;
|
|
|
},
|
|
@@ -335,20 +364,6 @@ module.exports={
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- /* const constructionFeeNode = items[0];
|
|
|
- // 设备及工器具购置费
|
|
|
- const constructionEquipmentNode = {
|
|
|
- type: billType.BILL,
|
|
|
- area: BudgetArea.CONSTRUCTION_FEE,
|
|
|
- flags: [{ fieldName: 'fixed', flag: fixedFlag.CONSTRUCTION_EQUIPMENT_FEE }],
|
|
|
- ID: constructionEquipmentFeeNodeID,
|
|
|
- ParentID: constructionFeeNode.ID,
|
|
|
- NextSiblingID: '-1',
|
|
|
- code: `1.${curSingleNo + 1}`,
|
|
|
- name: '设备及工器具购置费',
|
|
|
- };
|
|
|
- latestSingleNode.NextSiblingID = constructionEquipmentNode.ID;
|
|
|
- items.push(constructionEquipmentNode); */
|
|
|
return items;
|
|
|
},
|
|
|
// 汇算数据
|
|
@@ -364,21 +379,6 @@ 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;
|
|
@@ -405,16 +405,16 @@ module.exports={
|
|
|
unitFeeObj[feeType] = unitFee;
|
|
|
singleFeeObj[feeType] = scMathUtil.roundForObj(singleFeeObj[feeType] + unitFee, processDecimal);
|
|
|
}
|
|
|
- unit.fees = feeObj2Fees(unitFeeObj, unit.fees, projectQuantity, estimateQuantity);
|
|
|
+ unit.fees = feeObj2Fees(unitFeeObj, unit.fees);
|
|
|
}
|
|
|
- single.fees = feeObj2Fees(singleFeeObj, single.fees, projectQuantity, estimateQuantity);
|
|
|
+ single.fees = feeObj2Fees(singleFeeObj, single.fees);
|
|
|
// 汇算到建设项目
|
|
|
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, projectQuantity, estimateQuantity);
|
|
|
+ construction.fees = feeObj2Fees(constructionFeeObj, construction.fees);
|
|
|
// 更新fees字段
|
|
|
const bulks = [];
|
|
|
items.forEach(item => {
|
|
@@ -430,33 +430,16 @@ module.exports={
|
|
|
if (bulks.length) {
|
|
|
await projectModel.bulkWrite(bulks);
|
|
|
}
|
|
|
- // 获取设备购置费(旧)
|
|
|
- /* 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); */
|
|
|
|
|
|
- function feeObj2Fees(feeObj, orgFees, quantity, estQuantity) {
|
|
|
- const totalFee = scMathUtil.roundForObj(feeObj.total, decimal)
|
|
|
- let unitFee = 0;
|
|
|
- if (+quantity && totalFee) {
|
|
|
- unitFee = scMathUtil.roundForObj(totalFee / (+quantity), 2);
|
|
|
- }
|
|
|
+ function feeObj2Fees(feeObj, orgFees) {
|
|
|
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: '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) },
|
|
|
- { fieldName: 'estimation', totalFee: estimateFee, unitFee: estimateUnitFee },
|
|
|
+ { fieldName: 'estimation', totalFee: estimateFee },
|
|
|
];
|
|
|
}
|
|
|
},
|