|
|
@@ -36,63 +36,83 @@ if(typeof materialComponent !== 'undefined'){
|
|
|
//可以作为材料工料机组成物的工料机类型:普通材料
|
|
|
materialComponent = [201];
|
|
|
}
|
|
|
+
|
|
|
+// 计算单个人材机定额价小数位数
|
|
|
+let singleDecimal = -6,
|
|
|
+ // 汇总小数位数
|
|
|
+ summaryDecimal = -2,
|
|
|
+ // 中间过程
|
|
|
+ processDecimal = -6;
|
|
|
+
|
|
|
//覆盖前端定额基价计算
|
|
|
//基价=人工费+材料费+机械费+管理费利润
|
|
|
//管理费利润=Round(人工费*(管理费消耗量+利润消耗量)%,2) 注:书中管理费、利润的单位都是“%”
|
|
|
+//材料费相关:应该是先算单位不是%的,算一个临时材料费,然后%的单个材料费算法是临时材料费*消耗量*0.01,然后最终的材料费是临时材料费+%的单个材料费
|
|
|
if (typeof rationGLJOprObj !== 'undefined' && typeof rationGLJOprObj.rationCal !== 'undefined') {
|
|
|
rationGLJOprObj.rationCal = function () {
|
|
|
let me = rationGLJOprObj;
|
|
|
let price = {gljType1: [], gljType2: [], gljType3: []},
|
|
|
+ // 临时材料费(非%单位的材料)
|
|
|
+ tempPrice = {gljType1: 0, gljType2: 0, gljType3: 0},
|
|
|
rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0},
|
|
|
rationBasePrc = 0;
|
|
|
let manageProfitConsume = 0; //管理费、利润消耗量
|
|
|
if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
|
|
|
let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
|
|
|
+ // 获取临时材料费
|
|
|
cacheArr.forEach(function (gljData) {
|
|
|
- if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
|
|
|
+ if(gljData.gljType && gljData.consumeAmt && gljData.unit !== '%'){
|
|
|
let parentGLJType = parseInt(String(gljData.gljType)[0]);
|
|
|
if (parentGLJType <= 3) { // 人工、材料、机械
|
|
|
- // 单位为%,单条基价计算为定额价*消耗量*0.01
|
|
|
- if (gljData.unit === '%') {
|
|
|
- price['gljType' + parentGLJType].push(scMathUtil.roundTo(gljData.basePrice * gljData.consumeAmt * 0.01, -3));//取三位
|
|
|
- } else {
|
|
|
- price['gljType' + parentGLJType].push(scMathUtil.roundTo(gljData.basePrice * gljData.consumeAmt, -3));//取三位
|
|
|
- }
|
|
|
+ let single = scMathUtil.roundTo(gljData.basePrice * gljData.consumeAmt, singleDecimal);
|
|
|
+ tempPrice['gljType' + parentGLJType] = scMathUtil.roundTo(tempPrice['gljType' + parentGLJType] + single, processDecimal);
|
|
|
}
|
|
|
- if([6, 7].includes(gljData.gljType)){
|
|
|
- manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljData.consumeAmt, -6);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 临时材料费放入待汇总价格数组中
|
|
|
+ for (let attr in price) {
|
|
|
+ price[attr].push(tempPrice[attr])
|
|
|
+ }
|
|
|
+ cacheArr.forEach(function (gljData) {
|
|
|
+ if(gljData.gljType && gljData.consumeAmt){
|
|
|
+ let parentGLJType = parseInt(String(gljData.gljType)[0]);
|
|
|
+ if (parentGLJType <= 3 && gljData.unit === '%') { // 人工、材料、机械
|
|
|
+ // %的单个材料费算法是临时材料费*消耗量*0.01
|
|
|
+ price['gljType' + parentGLJType].push(scMathUtil.roundTo(tempPrice['gljType' + parentGLJType] * gljData.consumeAmt * 0.01, singleDecimal));
|
|
|
+ } else if([6, 7].includes(gljData.gljType)){
|
|
|
+ manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljData.consumeAmt, processDecimal);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
if(price.gljType1.length > 0){
|
|
|
let labourPrice = 0;
|
|
|
price.gljType1.forEach(function (singlePrc) {
|
|
|
- labourPrice = scMathUtil.roundTo(labourPrice + singlePrc, me.processDecimal);
|
|
|
+ labourPrice = scMathUtil.roundTo(labourPrice + singlePrc, processDecimal);
|
|
|
});
|
|
|
- let roundPrice = scMathUtil.roundTo(labourPrice, -2);
|
|
|
+ let roundPrice = scMathUtil.roundTo(labourPrice, summaryDecimal);
|
|
|
rst.labourPrice = roundPrice;
|
|
|
- rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
|
|
|
+ rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, summaryDecimal);
|
|
|
//管理费利润
|
|
|
- let manageProfitPrc = scMathUtil.roundTo(roundPrice * manageProfitConsume * 0.01, -2);
|
|
|
- rationBasePrc = scMathUtil.roundTo(rationBasePrc + manageProfitPrc, -2);
|
|
|
+ let manageProfitPrc = scMathUtil.roundTo(roundPrice * manageProfitConsume * 0.01, summaryDecimal);
|
|
|
+ rationBasePrc = scMathUtil.roundTo(rationBasePrc + manageProfitPrc, summaryDecimal);
|
|
|
}
|
|
|
if(price.gljType2.length > 0){
|
|
|
let materialPrice = 0;
|
|
|
price.gljType2.forEach(function (singlePrc) {
|
|
|
- materialPrice = scMathUtil.roundTo(materialPrice + singlePrc, me.processDecimal);
|
|
|
+ materialPrice = scMathUtil.roundTo(materialPrice + singlePrc, processDecimal);
|
|
|
});
|
|
|
- let roundPrice = scMathUtil.roundTo(materialPrice, -2);
|
|
|
+ let roundPrice = scMathUtil.roundTo(materialPrice, summaryDecimal);
|
|
|
rst.materialPrice = roundPrice;
|
|
|
- rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
|
|
|
+ rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, summaryDecimal);
|
|
|
}
|
|
|
if(price.gljType3.length > 0){
|
|
|
let machinePrice = 0;
|
|
|
price.gljType3.forEach(function (singlePrc) {
|
|
|
- machinePrice = scMathUtil.roundTo(machinePrice + singlePrc, me.processDecimal);
|
|
|
+ machinePrice = scMathUtil.roundTo(machinePrice + singlePrc, processDecimal);
|
|
|
});
|
|
|
- let roundPrice = scMathUtil.roundTo(machinePrice, -2);
|
|
|
+ let roundPrice = scMathUtil.roundTo(machinePrice, summaryDecimal);
|
|
|
rst.machinePrice = roundPrice;
|
|
|
- rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
|
|
|
+ rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, summaryDecimal);
|
|
|
}
|
|
|
rst.rationBasePrc = rationBasePrc;
|
|
|
}
|
|
|
@@ -100,62 +120,123 @@ if (typeof rationGLJOprObj !== 'undefined' && typeof rationGLJOprObj.rationCal !
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-if (typeof module !== 'undefined') {
|
|
|
- module.exports = {
|
|
|
- // 计算定额基价
|
|
|
- calcRation: function (gljArr, scMathUtil) {
|
|
|
- let labourPrc = [],
|
|
|
- materialPrc = [],
|
|
|
- machinePrc = [],
|
|
|
- manageProfitConsume = 0,
|
|
|
- singlePrc,
|
|
|
- updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, manageProfitPrice: 0, basePrice: 0};
|
|
|
- gljArr.forEach(function (gljItem) {
|
|
|
- if(gljItem.gljParentType !== -1){
|
|
|
- if (gljItem.gljParentType <= 3 && gljItem.unit === '%') {
|
|
|
- singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt * 0.01, -3);
|
|
|
- } else {
|
|
|
- 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){
|
|
|
- manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, -6);
|
|
|
- } else if(gljItem.gljParentType === 7){
|
|
|
- manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, -6);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- 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.manageProfitPrice = scMathUtil.roundTo(updatePrc.labourPrice * manageProfitConsume * 0.01, -2);
|
|
|
- updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.manageProfitPrice, -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);
|
|
|
+// 后端用 计算定额基价
|
|
|
+function calcRation(gljArr, scMathUtil) {
|
|
|
+ let labourPrc = [],
|
|
|
+ materialPrc = [],
|
|
|
+ machinePrc = [],
|
|
|
+ manageProfitConsume = 0,
|
|
|
+ updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, manageProfitPrice: 0, basePrice: 0};
|
|
|
+ // 临时材料费
|
|
|
+ let tempPrice = {gljType1: 0, gljType2: 0, gljType3: 0};
|
|
|
+ gljArr.forEach(function (gljItem) {
|
|
|
+ if (gljItem.gljParentType !== -1 &&
|
|
|
+ gljItem.gljParentType <= 3 &&
|
|
|
+ gljItem.unit !== '%') {
|
|
|
+ let single = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, singleDecimal);
|
|
|
+ tempPrice['gljType' + gljItem.gljParentType] = scMathUtil.roundTo(tempPrice['gljType' + gljItem.gljParentType] + single, processDecimal);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ labourPrc.push(tempPrice.gljType1);
|
|
|
+ materialPrc.push(tempPrice.gljType2);
|
|
|
+ machinePrc.push(tempPrice.gljType3);
|
|
|
+ gljArr.forEach(function (gljItem) {
|
|
|
+ let singlePrc = 0;
|
|
|
+ if(gljItem.gljParentType !== -1){
|
|
|
+ if (gljItem.gljParentType <= 3 && gljItem.unit === '%') {
|
|
|
+ singlePrc = scMathUtil.roundTo(tempPrice['gljType' + gljItem.gljParentType] * gljItem.consumeAmt * 0.01, singleDecimal);
|
|
|
+ } else if (gljItem.gljParentType > 3) {
|
|
|
+ singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, singleDecimal);
|
|
|
}
|
|
|
- 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(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){
|
|
|
+ manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, processDecimal);
|
|
|
+ } else if(gljItem.gljParentType === 7){
|
|
|
+ manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, processDecimal);
|
|
|
}
|
|
|
- return updatePrc;
|
|
|
}
|
|
|
+ });
|
|
|
+ if(labourPrc.length > 0){
|
|
|
+ let sumLaP = 0;
|
|
|
+ for(let i=0; i<labourPrc.length; i++){
|
|
|
+ sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], processDecimal);
|
|
|
+ }
|
|
|
+ updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, summaryDecimal);
|
|
|
+ updatePrc.manageProfitPrice = scMathUtil.roundTo(updatePrc.labourPrice * manageProfitConsume * 0.01, summaryDecimal);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.manageProfitPrice, summaryDecimal);
|
|
|
+ }
|
|
|
+ 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, summaryDecimal);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.materialPrice, summaryDecimal);
|
|
|
+ }
|
|
|
+ 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, summaryDecimal);
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.machinePrice, summaryDecimal);
|
|
|
+ }
|
|
|
+ return updatePrc;
|
|
|
+}
|
|
|
+
|
|
|
+//计税方式
|
|
|
+const taxModel = {'common': 1, 'simple': 2};
|
|
|
+//价格属性:计税方式
|
|
|
+const pricePropertiesTemplate = [
|
|
|
+ {
|
|
|
+ region: '全省',
|
|
|
+ taxModel: taxModel.common,
|
|
|
+ price: {
|
|
|
+ dataCode: 'price1',
|
|
|
+ dataName: '单价-一般'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ region: '全省',
|
|
|
+ taxModel: taxModel.simple,
|
|
|
+ price: {
|
|
|
+ dataCode: 'price2',
|
|
|
+ dataName: '单价-简易'
|
|
|
+ }
|
|
|
+ }
|
|
|
+];
|
|
|
+
|
|
|
+//消耗量属性:计税方式
|
|
|
+const consumeAmtPropertiesTemplate = [
|
|
|
+ {
|
|
|
+ region: '全省',
|
|
|
+ taxModel: taxModel.common,
|
|
|
+ consumeAmt: {
|
|
|
+ dataCode: 'consumeAmt1',
|
|
|
+ dataName: '消耗-一般',
|
|
|
+ refPrice: 'price1' //关联的单价字段
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ region: '全省',
|
|
|
+ taxModel: taxModel.simple,
|
|
|
+ consumeAmt: {
|
|
|
+ dataCode: 'consumeAmt2',
|
|
|
+ dataName: '消耗-简易',
|
|
|
+ refPrice: 'price2' //关联的单价字段
|
|
|
+ }
|
|
|
+ }
|
|
|
+];
|
|
|
+
|
|
|
+if(typeof module !== 'undefined'){
|
|
|
+ module.exports = {
|
|
|
+ pricePropertiesTemplate: pricePropertiesTemplate,
|
|
|
+ consumeAmtPropertiesTemplate: consumeAmtPropertiesTemplate,
|
|
|
+ calcRation: calcRation
|
|
|
};
|
|
|
}
|