|
@@ -32,6 +32,7 @@ const gljUtil = require('../../../public/gljUtil');
|
|
|
let stdColSettingModel = mongoose.model('std_main_col_lib');
|
|
let stdColSettingModel = mongoose.model('std_main_col_lib');
|
|
|
let decimal_facade = require('../../main/facade/decimal_facade');
|
|
let decimal_facade = require('../../main/facade/decimal_facade');
|
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
|
|
+const calcUtil = require('../../../public/calculate_util')
|
|
|
import fixedFlag from '../../common/const/bills_fixed';
|
|
import fixedFlag from '../../common/const/bills_fixed';
|
|
|
import GLJListModel from "../../glj/models/glj_list_model";
|
|
import GLJListModel from "../../glj/models/glj_list_model";
|
|
|
const projectDao = require('../../pm/models/project_model').project;
|
|
const projectDao = require('../../pm/models/project_model').project;
|
|
@@ -287,13 +288,14 @@ async function getDefaultColSetting(libID){
|
|
|
return await stdColSettingModel.findOne({ID: libID, deleted: false}, '-_id main_tree_col');
|
|
return await stdColSettingModel.findOne({ID: libID, deleted: false}, '-_id main_tree_col');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async function getBudgetSummayDatas(projectIDs){
|
|
|
|
|
|
|
+async function getBudgetSummayDatas(projectIDs,overWriteUrl){
|
|
|
try {
|
|
try {
|
|
|
let projects = [];
|
|
let projects = [];
|
|
|
let names = [];
|
|
let names = [];
|
|
|
let prjTypeNames = [];
|
|
let prjTypeNames = [];
|
|
|
let compilationScopes = [];
|
|
let compilationScopes = [];
|
|
|
let decimal = null;
|
|
let decimal = null;
|
|
|
|
|
+ let isProgressiveType = false;
|
|
|
for(let ID of projectIDs){
|
|
for(let ID of projectIDs){
|
|
|
projects.push(await getBillsByProjectID(ID)) ;
|
|
projects.push(await getBillsByProjectID(ID)) ;
|
|
|
}
|
|
}
|
|
@@ -309,9 +311,11 @@ async function getBudgetSummayDatas(projectIDs){
|
|
|
names.push(projects[i].name);
|
|
names.push(projects[i].name);
|
|
|
prjTypeNames.push(projects[i].prjTypeName);
|
|
prjTypeNames.push(projects[i].prjTypeName);
|
|
|
compilationScopes.push(projects[i].compilationScope);
|
|
compilationScopes.push(projects[i].compilationScope);
|
|
|
- decimal = await mergeProject(mp.roots,projects[i].roots)
|
|
|
|
|
|
|
+ decimal = await mergeProject(mp.roots,projects[i].roots);
|
|
|
|
|
+ if(projects[i].progressiveType == 0) isProgressiveType = true;
|
|
|
}
|
|
}
|
|
|
- let SummaryAuditDetail = getReportData(names,mp.roots,prjTypeNames,compilationScopes,decimal);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ let SummaryAuditDetail = getReportData(names,mp.roots,prjTypeNames,compilationScopes,decimal,isProgressiveType,mp.progressiveInterval,overWriteUrl);
|
|
|
let parentProject = await projectsModel.findOne({ID:mp.ParentID});
|
|
let parentProject = await projectsModel.findOne({ID:mp.ParentID});
|
|
|
let result = {
|
|
let result = {
|
|
|
prj: {},
|
|
prj: {},
|
|
@@ -330,9 +334,23 @@ async function getBudgetSummayDatas(projectIDs){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
|
|
|
|
|
|
|
+function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal,isProgressiveType,progressiveInterval,overWriteUrl) {
|
|
|
let datas = [],totalItem = null;
|
|
let datas = [],totalItem = null;
|
|
|
|
|
+ let overWrite = null;
|
|
|
|
|
+ if(overWriteUrl && overWriteUrl!=""){
|
|
|
|
|
+ overWrite = require("../../.."+compilation.overWriteUrl);
|
|
|
|
|
+ }
|
|
|
setChildrenDatas(items,datas);
|
|
setChildrenDatas(items,datas);
|
|
|
|
|
+ let totalExp = totalItem.calcBase;
|
|
|
|
|
+ if(isProgressiveType&&progressiveInterval){
|
|
|
|
|
+ for(let t of datas){
|
|
|
|
|
+ totalExp.replace(t.ID,t.billsTtlPrice+"");
|
|
|
|
|
+ }
|
|
|
|
|
+ totalExp.replace(/@/g,"");
|
|
|
|
|
+ let nTotal = eval(totalExp);
|
|
|
|
|
+ totalItem.billsTtlPrice = scMathUtil.roundForObj(nTotal,decimal.bills.totalPrice);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for(let d of datas){
|
|
for(let d of datas){
|
|
|
if(d.billsTtlPrice&&totalItem.billsTtlPrice){
|
|
if(d.billsTtlPrice&&totalItem.billsTtlPrice){
|
|
|
d['各项费用比例'] = scMathUtil.roundForObj(d.billsTtlPrice/totalItem.billsTtlPrice * 100,2)
|
|
d['各项费用比例'] = scMathUtil.roundForObj(d.billsTtlPrice/totalItem.billsTtlPrice * 100,2)
|
|
@@ -340,19 +358,31 @@ function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
|
|
|
d['prjNames'] = nameList;
|
|
d['prjNames'] = nameList;
|
|
|
d['prjTypeNames'] = prjTypeNames;
|
|
d['prjTypeNames'] = prjTypeNames;
|
|
|
d['编制范围明细'] = compilationScopes;
|
|
d['编制范围明细'] = compilationScopes;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
return datas;
|
|
return datas;
|
|
|
|
|
|
|
|
|
|
|
|
|
- function setChildrenDatas(children,arr,level = 0) {
|
|
|
|
|
|
|
+ function setChildrenDatas(children,arr,level = 0,rootFlag) {
|
|
|
|
|
+ let temTotalPrice = 0;
|
|
|
for(let c of children){
|
|
for(let c of children){
|
|
|
- arr.push(getBillDatas(c,level));
|
|
|
|
|
- setChildrenDatas(c.children,arr,level+1);
|
|
|
|
|
|
|
+ if(level == 0) rootFlag = c.flag;//取最顶层节点的固定清单类别
|
|
|
|
|
+ let sumChildren = setChildrenDatas(c.children,arr,level+1,rootFlag);
|
|
|
|
|
+ let tbill = getBillDatas(c,level,rootFlag);
|
|
|
|
|
+ if(isProgressiveType && progressiveInterval && rootFlag == fixedFlag.MAINTENANCE_EXPENSES){//如果要累进的,父节点要重新汇总
|
|
|
|
|
+ if(level>0) temTotalPrice = scMathUtil.roundForObj(tbill.billsTtlPrice + temTotalPrice,decimal.bills.totalPrice);
|
|
|
|
|
+ if(c.children.length > 0) tbill.billsTtlPrice = sumChildren;
|
|
|
|
|
+ }
|
|
|
|
|
+ arr.push(tbill);
|
|
|
}
|
|
}
|
|
|
|
|
+ return temTotalPrice
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getBillDatas(bills,level) {
|
|
|
|
|
|
|
+ function getBillDatas(bills,level,rootFlag) {
|
|
|
let tem = {
|
|
let tem = {
|
|
|
|
|
+ ID:bills.ID,
|
|
|
billsName:bills.name,
|
|
billsName:bills.name,
|
|
|
billsCode:bills.code,
|
|
billsCode:bills.code,
|
|
|
billsUnit:bills.unit,
|
|
billsUnit:bills.unit,
|
|
@@ -367,10 +397,12 @@ function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
|
|
|
};
|
|
};
|
|
|
let total = 0;
|
|
let total = 0;
|
|
|
let rationTotal =0;
|
|
let rationTotal =0;
|
|
|
|
|
+ let baseTotal = 0;
|
|
|
for(let n of nameList){
|
|
for(let n of nameList){
|
|
|
let p = 0;//金额
|
|
let p = 0;//金额
|
|
|
let up =0;//单价
|
|
let up =0;//单价
|
|
|
let ra = 0;//定额建安费
|
|
let ra = 0;//定额建安费
|
|
|
|
|
+ let bt = 0; //累计相关
|
|
|
if(bills.unitPrices[n]) up = scMathUtil.roundForObj(bills.unitPrices[n],decimal.bills.unitPrice);
|
|
if(bills.unitPrices[n]) up = scMathUtil.roundForObj(bills.unitPrices[n],decimal.bills.unitPrice);
|
|
|
tem.billsUnitPrices.push(up);
|
|
tem.billsUnitPrices.push(up);
|
|
|
if(bills.prices[n]){
|
|
if(bills.prices[n]){
|
|
@@ -390,8 +422,22 @@ function getReportData(nameList,items,prjTypeNames,compilationScopes,decimal) {
|
|
|
tem.billsAmounts.push(0);
|
|
tem.billsAmounts.push(0);
|
|
|
tem['技术经济指标'].push(scMathUtil.roundForObj(p,2));
|
|
tem['技术经济指标'].push(scMathUtil.roundForObj(p,2));
|
|
|
}
|
|
}
|
|
|
|
|
+ if(rootFlag == fixedFlag.MAINTENANCE_EXPENSES){//如果是第三部分下的子清单,才要计算累计的相关信息
|
|
|
|
|
+ if(bills.baseProgressiveFees[n]){
|
|
|
|
|
+ bt = scMathUtil.roundForObj(bills.baseProgressiveFees[n],decimal.bills.totalPrice);
|
|
|
|
|
+ baseTotal = scMathUtil.roundForObj(bt+baseTotal,decimal.process);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(progressiveInterval && isProgressiveType&&calcUtil.isProgressive(bills.calcBase,overWrite?overWrite.progression:undefined) && rootFlag == fixedFlag.MAINTENANCE_EXPENSES){
|
|
|
|
|
+ let calcTotal = calcUtil.getProgressiveFee(baseTotal,bills.calcBase,progressiveInterval,decimal.bills.totalPrice,overWrite?overWrite.deficiency:undefined);
|
|
|
|
|
+ tem.billsTtlPrice = calcTotal;
|
|
|
|
|
+ let rate = scMathUtil.roundForObj(calcTotal * 100/baseTotal,decimal.feeRate);
|
|
|
|
|
+ tem.billsMemos = "费率:"+rate+"%";
|
|
|
|
|
+ //“费率:n%”,n为汇总后重算的金额/汇总后的基数
|
|
|
|
|
+ }else{
|
|
|
|
|
+ tem.billsTtlPrice = scMathUtil.roundForObj(total,decimal.bills.totalPrice);
|
|
|
}
|
|
}
|
|
|
- tem.billsTtlPrice = scMathUtil.roundForObj(total,decimal.bills.totalPrice);
|
|
|
|
|
tem.rationTotal = scMathUtil.roundForObj(rationTotal,decimal.bills.totalPrice);//定额总建安费
|
|
tem.rationTotal = scMathUtil.roundForObj(rationTotal,decimal.bills.totalPrice);//定额总建安费
|
|
|
tem['技术经济综合指标'] = (tem.billsTtlAmt && parseFloat(tem.billsTtlAmt) !== 0)?scMathUtil.roundForObj(tem.billsTtlPrice/tem.billsTtlAmt,2):scMathUtil.roundForObj(tem.billsTtlPrice,2);
|
|
tem['技术经济综合指标'] = (tem.billsTtlAmt && parseFloat(tem.billsTtlAmt) !== 0)?scMathUtil.roundForObj(tem.billsTtlPrice/tem.billsTtlAmt,2):scMathUtil.roundForObj(tem.billsTtlPrice,2);
|
|
|
if(bills.flag == fixedFlag.TOTAL_COST) totalItem = tem;
|
|
if(bills.flag == fixedFlag.TOTAL_COST) totalItem = tem;
|
|
@@ -427,6 +473,7 @@ async function mergeItem(a,b,decimal,project) {
|
|
|
a.rationCommons[name] = b.rationCommons[name];
|
|
a.rationCommons[name] = b.rationCommons[name];
|
|
|
a.quantityMap[name] = b.quantityMap[name];
|
|
a.quantityMap[name] = b.quantityMap[name];
|
|
|
a.unitPrices[name]=b.unitPrices[name];
|
|
a.unitPrices[name]=b.unitPrices[name];
|
|
|
|
|
+ a.baseProgressiveFees[name] = b.baseProgressiveFees[name];
|
|
|
}
|
|
}
|
|
|
for(let name in a.quantityMap){
|
|
for(let name in a.quantityMap){
|
|
|
a.quantityMap[name] = a.quantityMap[name]?scMathUtil.roundForObj(a.quantityMap[name],bqDecimal):0;
|
|
a.quantityMap[name] = a.quantityMap[name]?scMathUtil.roundForObj(a.quantityMap[name],bqDecimal):0;
|
|
@@ -513,6 +560,8 @@ async function getBillsByProjectID(projectID){
|
|
|
let auditor='';//审核人
|
|
let auditor='';//审核人
|
|
|
let compilationScope='';//编制范围
|
|
let compilationScope='';//编制范围
|
|
|
let engineering='';//养护类别
|
|
let engineering='';//养护类别
|
|
|
|
|
+ let progressiveType = 0;//累进计算类型
|
|
|
|
|
+ let progressiveInterval = null;
|
|
|
if(project.property&&project.property.projectFeature){
|
|
if(project.property&&project.property.projectFeature){
|
|
|
for(let f of project.property.projectFeature){
|
|
for(let f of project.property.projectFeature){
|
|
|
if(f.key == 'author') author = f.value;
|
|
if(f.key == 'author') author = f.value;
|
|
@@ -520,6 +569,8 @@ async function getBillsByProjectID(projectID){
|
|
|
if(f.key =='compilationScope') compilationScope = f.value;
|
|
if(f.key =='compilationScope') compilationScope = f.value;
|
|
|
if(f.key == 'engineering') engineering = f.value;
|
|
if(f.key == 'engineering') engineering = f.value;
|
|
|
}
|
|
}
|
|
|
|
|
+ if(project.property.progressiveType) progressiveType = project.property.progressiveType;
|
|
|
|
|
+ progressiveInterval = project.property.progressiveInterval;
|
|
|
}
|
|
}
|
|
|
for(let b of bills){
|
|
for(let b of bills){
|
|
|
let commonFee =_.find(b._doc.fees,{"fieldName":"common"});
|
|
let commonFee =_.find(b._doc.fees,{"fieldName":"common"});
|
|
@@ -527,13 +578,16 @@ async function getBillsByProjectID(projectID){
|
|
|
let quantityMap={};
|
|
let quantityMap={};
|
|
|
let unitPrices ={};
|
|
let unitPrices ={};
|
|
|
let rationCommons={};
|
|
let rationCommons={};
|
|
|
|
|
+ let baseProgressiveFees ={};
|
|
|
let rationFee = _.find(b._doc.fees,{"fieldName":"rationCommon"});
|
|
let rationFee = _.find(b._doc.fees,{"fieldName":"rationCommon"});
|
|
|
if(commonFee&&commonFee.totalFee) prices[projectName] = commonFee.totalFee;
|
|
if(commonFee&&commonFee.totalFee) prices[projectName] = commonFee.totalFee;
|
|
|
if(commonFee&&commonFee.unitFee) unitPrices[projectName] = commonFee.unitFee;
|
|
if(commonFee&&commonFee.unitFee) unitPrices[projectName] = commonFee.unitFee;
|
|
|
if(rationFee&&rationFee.totalFee) rationCommons[projectName] = rationFee.totalFee;
|
|
if(rationFee&&rationFee.totalFee) rationCommons[projectName] = rationFee.totalFee;
|
|
|
|
|
+ baseProgressiveFees = baseProgressiveFees[projectName] = b.baseProgressiveFee;
|
|
|
|
|
+
|
|
|
quantityMap[projectName] = b.quantity;
|
|
quantityMap[projectName] = b.quantity;
|
|
|
let flagIndex = _.find(b._doc.flags,{'fieldName':'fixed'});
|
|
let flagIndex = _.find(b._doc.flags,{'fieldName':'fixed'});
|
|
|
- let doc = {ID:b.ID,name:b.name,code:b.code,unit:b.unit,projectID:b.projectID, ParentID:b.ParentID,NextSiblingID:b.NextSiblingID,unitPrices:unitPrices,quantity:b.quantity,prices:prices,rationCommons:rationCommons,quantityMap:quantityMap,flag:flagIndex?flagIndex.flag:-99,remark:b.remark};//选取有用字段
|
|
|
|
|
|
|
+ let doc = {ID:b.ID,name:b.name,code:b.code,unit:b.unit,projectID:b.projectID, ParentID:b.ParentID,NextSiblingID:b.NextSiblingID,unitPrices:unitPrices,quantity:b.quantity,prices:prices,rationCommons:rationCommons,quantityMap:quantityMap,flag:flagIndex?flagIndex.flag:-99,remark:b.remark,calcBase:b.calcBase,baseProgressiveFees:baseProgressiveFees};//选取有用字段
|
|
|
if(b.ParentID == -1) roots.push(doc);
|
|
if(b.ParentID == -1) roots.push(doc);
|
|
|
parentMap[b.ParentID]?parentMap[b.ParentID].push(doc):parentMap[b.ParentID]=[doc];
|
|
parentMap[b.ParentID]?parentMap[b.ParentID].push(doc):parentMap[b.ParentID]=[doc];
|
|
|
}//设置子节点
|
|
}//设置子节点
|
|
@@ -541,7 +595,7 @@ async function getBillsByProjectID(projectID){
|
|
|
setChildren(r,parentMap,1);
|
|
setChildren(r,parentMap,1);
|
|
|
}
|
|
}
|
|
|
roots = sortChildren(roots);
|
|
roots = sortChildren(roots);
|
|
|
- return {name:projectName,roots:roots,author:author,auditor:auditor,compilationScope:compilationScope,ParentID:project.ParentID,prjTypeName:engineering}
|
|
|
|
|
|
|
+ return {name:projectName,roots:roots,author:author,auditor:auditor,compilationScope:compilationScope,ParentID:project.ParentID,prjTypeName:engineering,progressiveType:progressiveType,progressiveInterval:progressiveInterval}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function setChildren(bill,parentMap,level) {
|
|
function setChildren(bill,parentMap,level) {
|