|
|
@@ -301,8 +301,90 @@ function round(v,e){
|
|
|
return Math.round(v*t)/t;
|
|
|
}
|
|
|
|
|
|
+function calcRation(gljArr) {
|
|
|
+ let labourPrc = [],
|
|
|
+ materialPrc = [],
|
|
|
+ machinePrc = [],
|
|
|
+ managePrc = [],
|
|
|
+ profitPrc = [],
|
|
|
+ riskPrc = [],
|
|
|
+ singlePrc,
|
|
|
+ updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0, basePrice: 0};
|
|
|
+ gljArr.forEach(function (gljItem) {
|
|
|
+ if(gljItem.gljParentType !== -1){
|
|
|
+ singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
|
|
|
+ if(gljItem.gljParentType === 1){
|
|
|
+ labourPrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ else if(gljItem.gljParentType ===2){
|
|
|
+ materialPrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ else if(gljItem.gljParentType === 3){
|
|
|
+ machinePrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ else if(gljItem.gljParentType === 6){
|
|
|
+ managePrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ else if(gljItem.gljParentType === 7){
|
|
|
+ profitPrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ else if(gljItem.gljParentType === 8){
|
|
|
+ riskPrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(labourPrc.length > 0){
|
|
|
+ let sumLaP = 0;
|
|
|
+ for(let i=0; i<labourPrc.length; i++){
|
|
|
+ sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], -6);
|
|
|
+ }
|
|
|
+ updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.labourPrice, -2);
|
|
|
+ }
|
|
|
+ if(materialPrc.length > 0){
|
|
|
+ let sumMtP = 0;
|
|
|
+ for(let i= 0; i<materialPrc.length; i++){
|
|
|
+ sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], -6);
|
|
|
+ }
|
|
|
+ updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.materialPrice, -2);
|
|
|
+ }
|
|
|
+ if(machinePrc.length > 0){
|
|
|
+ let sumMaP = 0;
|
|
|
+ for(let i =0; i< machinePrc.length; i++){
|
|
|
+ sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], -6);
|
|
|
+ }
|
|
|
+ updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.machinePrice, -2);
|
|
|
+ }
|
|
|
+ if(managePrc.length > 0){
|
|
|
+ let sumMgP = 0;
|
|
|
+ for(let i =0; i< managePrc.length; i++){
|
|
|
+ sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], -6);
|
|
|
+ }
|
|
|
+ updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.managePrice, -2);
|
|
|
+ }
|
|
|
+ if(profitPrc.length > 0){
|
|
|
+ let sumPfP = 0;
|
|
|
+ for(let i =0; i< profitPrc.length; i++){
|
|
|
+ sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], -6);
|
|
|
+ }
|
|
|
+ updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.profitPrice, -2);
|
|
|
+ }
|
|
|
+ if(riskPrc.length > 0){
|
|
|
+ let sumRkP = 0;
|
|
|
+ for(let i =0; i< riskPrc.length; i++){
|
|
|
+ sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], -6);
|
|
|
+ }
|
|
|
+ updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.riskPrice, -2);
|
|
|
+ }
|
|
|
+ return updatePrc;
|
|
|
+}
|
|
|
|
|
|
-rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
+rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, overWriteUrl, callback) {
|
|
|
async.each(basePrcArr, function (basePrcObj, finalCb) {
|
|
|
let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
|
|
|
async.waterfall([
|
|
|
@@ -379,7 +461,6 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
}
|
|
|
}
|
|
|
gljDao.getStdCompleGljItems(compleGljIds, stdGljIds, function (err, allGljs) {
|
|
|
- const processDecimal = -6;
|
|
|
if(err){
|
|
|
cb(err);
|
|
|
}
|
|
|
@@ -400,35 +481,25 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
}
|
|
|
if(theGlj.gljType <= 3){
|
|
|
gljParentType = theGlj.gljType;
|
|
|
- }
|
|
|
- if(theGlj.gljType > 200 && theGlj.gljType < 300){
|
|
|
+ } else if(theGlj.gljType > 200 && theGlj.gljType < 300){
|
|
|
gljParentType = 2;
|
|
|
- }
|
|
|
- if(theGlj.gljType > 300 && theGlj.gljType < 400){
|
|
|
+ } else if(theGlj.gljType > 300 && theGlj.gljType < 400){
|
|
|
gljParentType = 3;
|
|
|
- }
|
|
|
- //管理费
|
|
|
- if(theGlj.gljType === 6){
|
|
|
+ } else if(theGlj.gljType === 6){ //管理费
|
|
|
gljParentType = 6;
|
|
|
- }
|
|
|
- //利润
|
|
|
- if(theGlj.gljType === 7){
|
|
|
+ } else if(theGlj.gljType === 7){ //利润
|
|
|
gljParentType = 7;
|
|
|
- }
|
|
|
- //风险费
|
|
|
- if(theGlj.gljType === 8){
|
|
|
+ } else if(theGlj.gljType === 8){ //风险费
|
|
|
gljParentType = 8;
|
|
|
}
|
|
|
if(theGlj)
|
|
|
if(theGlj.ID === adjGljId){
|
|
|
gljArr.push({gljId: theGlj.ID, basePrice: adjBasePrice, gljParentType: gljParentType});
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
if(theGlj.priceProperty && Object.keys(theGlj.priceProperty).length > 0){
|
|
|
let priceKeys = Object.keys(theGlj.priceProperty);
|
|
|
gljArr.push({gljId: theGlj.ID, basePrice: parseFloat(theGlj.priceProperty[priceKeys[0]]), gljParentType: gljParentType});
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
gljArr.push({gljId: theGlj.ID, basePrice: parseFloat(theGlj.basePrice), gljParentType: gljParentType});
|
|
|
}
|
|
|
}
|
|
|
@@ -441,82 +512,18 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
}
|
|
|
})
|
|
|
});
|
|
|
- //recalculate the price of ration
|
|
|
- let labourPrc = [],
|
|
|
- materialPrc = [],
|
|
|
- machinePrc = [],
|
|
|
- managePrc = [],
|
|
|
- profitPrc = [],
|
|
|
- riskPrc = [],
|
|
|
- singlePrc,
|
|
|
- updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0, basePrice: 0};
|
|
|
- gljArr.forEach(function (gljItem) {
|
|
|
- if(gljItem.gljParentType !== -1){
|
|
|
- singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
|
|
|
- if(gljItem.gljParentType === 1){
|
|
|
- labourPrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(gljItem.gljParentType ===2){
|
|
|
- materialPrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(gljItem.gljParentType === 3){
|
|
|
- machinePrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(gljItem.gljParentType === 6){
|
|
|
- managePrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(gljItem.gljParentType === 7){
|
|
|
- profitPrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(gljItem.gljParentType === 8){
|
|
|
- riskPrc.push(singlePrc);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- if(labourPrc.length > 0){
|
|
|
- let sumLaP = 0;
|
|
|
- for(let i=0; i<labourPrc.length; i++){
|
|
|
- sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], processDecimal);
|
|
|
+ let updatePrc = null;
|
|
|
+ let overWriteCalc = false; //需要重写算法
|
|
|
+ if (overWriteUrl) {
|
|
|
+ let overWriteExports = require(overWriteUrl);
|
|
|
+ if (typeof overWriteExports.calcRation !== 'undefined') {
|
|
|
+ overWriteCalc = true;
|
|
|
+ updatePrc = overWriteExports.calcRation(gljArr, scMathUtil);
|
|
|
}
|
|
|
- updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
|
|
|
}
|
|
|
- if(materialPrc.length > 0){
|
|
|
- let sumMtP = 0;
|
|
|
- for(let i= 0; i<materialPrc.length; i++){
|
|
|
- sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
|
|
|
- }
|
|
|
- if(machinePrc.length > 0){
|
|
|
- let sumMaP = 0;
|
|
|
- for(let i =0; i< machinePrc.length; i++){
|
|
|
- sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
|
|
|
- }
|
|
|
- if(managePrc.length > 0){
|
|
|
- let sumMgP = 0;
|
|
|
- for(let i =0; i< managePrc.length; i++){
|
|
|
- sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
|
|
|
- }
|
|
|
- if(profitPrc.length > 0){
|
|
|
- let sumPfP = 0;
|
|
|
- for(let i =0; i< profitPrc.length; i++){
|
|
|
- sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
|
|
|
- }
|
|
|
- if(riskPrc.length > 0){
|
|
|
- let sumRkP = 0;
|
|
|
- for(let i =0; i< riskPrc.length; i++){
|
|
|
- sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
|
|
|
+ if (!overWriteCalc) {
|
|
|
+ updatePrc = calcRation(gljArr);
|
|
|
}
|
|
|
- updatePrc.basePrice = scMathUtil.roundTo(
|
|
|
- updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2);
|
|
|
let task = {
|
|
|
updateOne: {
|
|
|
filter: {
|
|
|
@@ -710,126 +717,40 @@ rationItemDAO.prototype.updateRationTemplate = async function (rationRepId, rati
|
|
|
};
|
|
|
|
|
|
//计算导入数据的价格
|
|
|
-rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
|
|
|
- const processDecimal = -6;
|
|
|
- //根据工料机类型划分价格
|
|
|
- const labour = [1],
|
|
|
- material = [201, 202, 203, 204, 205, 206, 207],
|
|
|
- machine = [301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312],
|
|
|
- manage = [6],
|
|
|
- profit = [7],
|
|
|
- risk = [8];
|
|
|
- let labourPrc = [], materialPrc = [], machinePrc = [], managePrc = [], profitPrc = [], riskPrc = [],
|
|
|
- singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0};
|
|
|
- let rationGljList = ration.rationGljList;
|
|
|
- for(let rationGlj of rationGljList){
|
|
|
+rationItemDAO.prototype.calcForRation = function (stdGljList, ration, overWriteUrl) {
|
|
|
+ let rationGljList = ration.rationGljList,
|
|
|
+ gljArr = [];
|
|
|
+ for(let rationGlj of rationGljList) {
|
|
|
let glj = stdGljList[rationGlj.gljId];
|
|
|
- let prcType = isDef(glj) ? getParentType(glj.gljType) : null;
|
|
|
- if(isDef(prcType)){
|
|
|
- singlePrc = scMathUtil.roundTo(parseFloat(glj.basePrice) * parseFloat(rationGlj.consumeAmt), -3);
|
|
|
- if(prcType === 'labour'){
|
|
|
- labourPrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(prcType === 'material'){
|
|
|
- materialPrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(prcType === 'machine'){
|
|
|
- machinePrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(prcType === 'manage'){
|
|
|
- managePrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(prcType === 'profit'){
|
|
|
- profitPrc.push(singlePrc);
|
|
|
- }
|
|
|
- else if(prcType === 'risk'){
|
|
|
- riskPrc.push(singlePrc);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //计算人工费
|
|
|
- if(labourPrc.length > 0){
|
|
|
- let sumLaP = 0;
|
|
|
- for(let i = 0, len = labourPrc.length; i < len; i++){
|
|
|
- sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
|
|
|
- }
|
|
|
- //材料费
|
|
|
- if(materialPrc.length > 0){
|
|
|
- let sumMtP = 0;
|
|
|
- for(let i = 0, len = materialPrc.length; i < len; i++){
|
|
|
- sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
|
|
|
- }
|
|
|
- //机械费
|
|
|
- if(machinePrc.length > 0){
|
|
|
- let sumMaP = 0;
|
|
|
- for(let i = 0, len = machinePrc.length; i < len; i++){
|
|
|
- sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
|
|
|
- }
|
|
|
- //管理费
|
|
|
- if(managePrc.length > 0){
|
|
|
- let sumMgP = 0;
|
|
|
- for(let i = 0, len = managePrc.length; i < len; i++){
|
|
|
- sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
|
|
|
- }
|
|
|
- //利润
|
|
|
- if(profitPrc.length > 0){
|
|
|
- let sumPfP = 0;
|
|
|
- for(let i = 0, len = profitPrc.length; i < len; i++){
|
|
|
- sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
|
|
|
- }
|
|
|
- //风险费
|
|
|
- if(riskPrc.length > 0){
|
|
|
- let sumRkP = 0;
|
|
|
- for(let i = 0, len = riskPrc.length; i < len; i++){
|
|
|
- sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], processDecimal);
|
|
|
- }
|
|
|
- updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
|
|
|
- }
|
|
|
- //基价
|
|
|
- updatePrc.basePrice = scMathUtil.roundTo(
|
|
|
- updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2);
|
|
|
- //更新定额数据
|
|
|
- ration.labourPrice = updatePrc.labourPrice.toString();
|
|
|
- ration.materialPrice = updatePrc.materialPrice.toString();
|
|
|
- ration.machinePrice = updatePrc.machinePrice.toString();
|
|
|
- ration.basePrice = updatePrc.basePrice.toString();
|
|
|
-
|
|
|
- function isDef(v){
|
|
|
- return v !== undefined && v !== null;
|
|
|
- }
|
|
|
- //是否属于人工、材料、机械类型
|
|
|
- function getParentType(type){
|
|
|
- if(labour.includes(type)){
|
|
|
- return 'labour';
|
|
|
- }
|
|
|
- if(material.includes(type)){
|
|
|
- return 'material';
|
|
|
- }
|
|
|
- if(machine.includes(type)){
|
|
|
- return 'machine';
|
|
|
- }
|
|
|
- if(manage.includes(type)){
|
|
|
- return 'manage';
|
|
|
+ let gljPType = parseInt(glj.gljType.toString().match(/\d+?/)[0]);
|
|
|
+ if (glj.priceProperty && Object.keys(glj.priceProperty).length > 0) {
|
|
|
+ let priceKeys = Object.keys(glj.priceProperty);
|
|
|
+ gljArr.push({
|
|
|
+ gljId: glj.ID,
|
|
|
+ basePrice: parseFloat(glj.priceProperty[priceKeys[0]]),
|
|
|
+ consumeAmt: rationGlj.consumeAmt,
|
|
|
+ gljParentType: gljPType
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ gljArr.push({gljId: glj.ID, basePrice: parseFloat(glj.basePrice), consumeAmt: rationGlj.consumeAmt, gljParentType: gljPType});
|
|
|
}
|
|
|
- if(profit.includes(type)){
|
|
|
- return 'profit';
|
|
|
+ let updatePrc = null;
|
|
|
+ let overWriteCalc = false; //需要重写算法
|
|
|
+ if (overWriteUrl) {
|
|
|
+ let overWriteExports = require(overWriteUrl);
|
|
|
+ if (typeof overWriteExports.calcRation !== 'undefined') {
|
|
|
+ overWriteCalc = true;
|
|
|
+ updatePrc = overWriteExports.calcRation(gljArr, scMathUtil);
|
|
|
+ }
|
|
|
}
|
|
|
- if(risk.includes(type)){
|
|
|
- return 'risk'
|
|
|
+ if (!overWriteCalc) {
|
|
|
+ updatePrc = calcRation(gljArr);
|
|
|
}
|
|
|
- return null;
|
|
|
+ ration.labourPrice = updatePrc.labourPrice.toString();
|
|
|
+ ration.materialPrice = updatePrc.materialPrice.toString();
|
|
|
+ ration.machinePrice = updatePrc.machinePrice.toString();
|
|
|
+ ration.basePrice = updatePrc.basePrice.toString();
|
|
|
}
|
|
|
-
|
|
|
};
|
|
|
|
|
|
/**
|