|
|
@@ -296,6 +296,7 @@ ProjectGLJ.prototype.updateCalcMaterial =async function (projectGLJ,updateField,
|
|
|
ext['purchaseStorageRate_n'] = glj.unit_price.purchaseStorageRate;
|
|
|
ext['offSiteTransportLossRate_n'] = glj.unit_price.offSiteTransportLossRate;
|
|
|
ext['handlingLossRate_n'] = glj.unit_price.handlingLossRate;
|
|
|
+ ext['totalLoadingTimes'] = '1';
|
|
|
}else if(value == 0){//删除操作,恢复单位毛重/采购保管费率等数据
|
|
|
ext['supplyLocation'] = '';
|
|
|
ext['originalPrice'] = '0';
|
|
|
@@ -335,22 +336,97 @@ ProjectGLJ.prototype.updateCalcMaterial =async function (projectGLJ,updateField,
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-ProjectGLJ.prototype.materialCal = function (id,dataMap) {
|
|
|
+ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs) {//当材料发生改变时重算所有计算材料的价格
|
|
|
+ let priceMap = {};
|
|
|
+ for(let unitPrice of unitPriecs){
|
|
|
+ if(unitPrice && gljUtil.isDef(unitPrice.doc.market_price)) priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
|
|
|
+ }
|
|
|
+ let freightListMap = _.groupBy(this.datas.freightList,'connect_key');//取运费计算项映射表
|
|
|
+ let originalListMap = _.groupBy(this.datas.originalList,'connect_key');//取原价计算项映射表
|
|
|
+ let sumFreightUpdateMap = {}; //存放所有材料下的运费更新信息;
|
|
|
+ let sumOriginalUpdateMap = {};//存放所有材料下的原价更新信息;
|
|
|
+
|
|
|
+ for(let g of this.datas.gljList){
|
|
|
+ if(g.quantity !== 0 && g.quantity !== '0' && g.unit_price.calcMaterial == 1&&!priceMap[g.id]){//工料机本身不包含在要计算的列表内
|
|
|
+ //先判断要不要重算,只有包含相关工料机的定额的材料,才需要重新计算
|
|
|
+ let fOrPDataMap = {};
|
|
|
+ let tIndex = gljUtil.getIndex(g);
|
|
|
+ //运费和原价中的工料机只要有一个包含该材料,就要重算
|
|
|
+ if(freightListMap[tIndex]){ //运费重算
|
|
|
+ let freightUpdateMap = {};
|
|
|
+ for(let f of freightListMap[tIndex]){
|
|
|
+ if(f.conveyance != "自办运输") continue;//不是自办运输的不用管
|
|
|
+ let calf = ifNeedReCalc(f,priceMap);
|
|
|
+ if(calf){
|
|
|
+ let f_task = this.calcEachFreightOrPrice(f,"freight",priceMap);
|
|
|
+ if(f_task){
|
|
|
+ freightUpdateMap[f_task.ID] = f_task.doc;
|
|
|
+ sumFreightUpdateMap[f_task.ID] = f_task.doc;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!_.isEmpty(freightUpdateMap)) fOrPDataMap["freight"] = {update:freightUpdateMap};
|
|
|
+ }
|
|
|
+ //原价重算
|
|
|
+ if(originalListMap[tIndex]){ //运费重算
|
|
|
+ let originalUpdateMap = {};
|
|
|
+ for(let o of originalListMap[tIndex]){
|
|
|
+ let calo = ifNeedReCalc(o,priceMap);
|
|
|
+ if(calo){
|
|
|
+ let o_task = this.calcEachFreightOrPrice(o,"price",priceMap);
|
|
|
+ if(o_task){
|
|
|
+ originalUpdateMap[o_task.ID] = o_task.doc;
|
|
|
+ sumOriginalUpdateMap[o_task.ID] = o_task.doc;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!_.isEmpty(originalUpdateMap)) fOrPDataMap["price"] = {update:originalUpdateMap};
|
|
|
+ }
|
|
|
+ //判断映射表是否为空,如果为空则说明不用计算
|
|
|
+ if(!_.isEmpty(fOrPDataMap)){
|
|
|
+ let t_unipPrice = this.materialCal(g.id,fOrPDataMap,g,freightListMap[tIndex],originalListMap[tIndex]);
|
|
|
+ if(t_unipPrice) unitPriecs.push(t_unipPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let sumUpdateMap = {};
|
|
|
+ if(!_.isEmpty(sumFreightUpdateMap))sumUpdateMap["freight"] = {update:sumFreightUpdateMap};
|
|
|
+ if(!_.isEmpty(sumOriginalUpdateMap))sumUpdateMap["price"] = {update:sumOriginalUpdateMap};
|
|
|
+ return [unitPriecs,sumUpdateMap];
|
|
|
+
|
|
|
+
|
|
|
+ function ifNeedReCalc(obj,IDMap) {
|
|
|
+ let calcf = false;
|
|
|
+ if(obj.ration_gljs){
|
|
|
+ for(let rg of obj.ration_gljs){
|
|
|
+ if(IDMap[rg.projectGLJID]){//判断是否关联了该项目工料机
|
|
|
+ calcf = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return calcf;
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+ProjectGLJ.prototype.materialCal = function (id,dataMap,tglj,tfreightList,tpriceList) {
|
|
|
let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
|
|
|
let unitPirceDecimal = getDecimal("glj.unitPrice");
|
|
|
let process = getDecimal("process");
|
|
|
- let glj = _.find(this.datas.gljList,{'id':id});
|
|
|
+ let glj = tglj?tglj: _.find(this.datas.gljList,{'id':id});
|
|
|
let doc = dataMap['material']&&dataMap['material']['update']?dataMap['material']['update']:{};//材料的update结构不同,不用ID做key
|
|
|
if(!glj) return;
|
|
|
- let unitPrice = {id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
|
|
|
+ let unitPrice = {projectGLJID:glj.id,id:glj.unit_price.id,'unit_price_file_id':glj.unit_price.unit_price_file_id,doc:{}};
|
|
|
//先计算原价
|
|
|
- let [originalPrice,supplyLocation] = this.priceCalc(glj,dataMap);
|
|
|
+ let [originalPrice,supplyLocation] = this.priceCalc(glj,dataMap,tpriceList);
|
|
|
doc['originalPrice'] = originalPrice+'';
|
|
|
doc['supplyLocation'] = supplyLocation;
|
|
|
//再计算运费
|
|
|
let grossWeightCoe_n = doc['grossWeightCoe_n']?doc['grossWeightCoe_n']:glj.unit_price.grossWeightCoe_n;
|
|
|
grossWeightCoe_n = scMathUtil.roundForObj(grossWeightCoe_n,process);
|
|
|
- let unitFreight = this.freightCalc(glj,grossWeightCoe_n,dataMap);
|
|
|
+ let unitFreight = this.freightCalc(glj,grossWeightCoe_n,dataMap,tfreightList);
|
|
|
doc['unitFreight'] = unitFreight+'';
|
|
|
//计算场外运输损耗
|
|
|
let sum_o_f = scMathUtil.roundForObj(originalPrice+unitFreight,process);//(原价+单位运费)
|
|
|
@@ -386,15 +462,15 @@ ProjectGLJ.prototype.materialCal = function (id,dataMap) {
|
|
|
return unitPrice
|
|
|
};
|
|
|
|
|
|
-ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap) {
|
|
|
+ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap,tfreightList) {
|
|
|
let process = getDecimal("process");
|
|
|
let unitPirce = getDecimal("glj.unitPrice");
|
|
|
let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");//这里暂时没用到
|
|
|
let sum = 0;
|
|
|
- let freightList = _.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
|
|
|
+ let freightList = tfreightList?tfreightList:_.filter(this.datas.freightList,{"connect_key":gljUtil.getIndex(glj)});
|
|
|
if(dataMap["freight"] && dataMap["freight"]["add"]) freightList = freightList.concat(dataMap["freight"]["add"]); //把添加的加进去
|
|
|
for(let f of freightList){
|
|
|
- let unitFreight = f.unitFreight,kmDistance = f.kmDistance,freightIncreaseRate = f.freightIncreaseRate,unitLoadingFee= f.unitLoadingFee,loadingTimes = f.loadingTimes,otherFee = f.otherFee,weightCoe = f.weightCoe;
|
|
|
+ let unitFreight = f.unitFreight,kmDistance = f.kmDistance,freightIncreaseRate = f.freightIncreaseRate,unitLoadingFee= f.unitLoadingFee,loadingTimes = f.loadingTimes,otherFee = f.otherFee,weightCoe = f.weightCoe,conveyance = f.conveyance,calcType=f.calcType,materialType=f.materialType;
|
|
|
if(dataMap["freight"] && dataMap["freight"]["update"]){//覆盖更新的数据
|
|
|
let t = dataMap["freight"]["update"][f.ID];
|
|
|
if(t){
|
|
|
@@ -405,17 +481,22 @@ ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap) {
|
|
|
if(t['loadingTimes']) loadingTimes = t['loadingTimes'];
|
|
|
if(t['otherFee']) otherFee = t['otherFee'];
|
|
|
if(t['weightCoe']) weightCoe = t['weightCoe'];
|
|
|
+ if(t['conveyance']) conveyance = t['conveyance'];
|
|
|
+ if(t['calcType']) calcType = t['calcType'];
|
|
|
+ if(t['materialType']) materialType = t['materialType'];
|
|
|
}
|
|
|
}
|
|
|
if(dataMap["freight"] && dataMap["freight"]["delete"]){//忽略删除的数据
|
|
|
- if(f.ID ==dataMap["freight"]["delete"]) continue;
|
|
|
+ if(dataMap["freight"]["delete"][f.ID]) continue;
|
|
|
}
|
|
|
//开始计算
|
|
|
freightIncreaseRate = scMathUtil.roundForObj(freightIncreaseRate,unitPirce);
|
|
|
freightIncreaseRate = scMathUtil.roundForObj(1+freightIncreaseRate/100,process);//(1+运距增加率%)
|
|
|
unitFreight = scMathUtil.roundForObj(unitFreight,unitPirce);
|
|
|
kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
|
|
|
- let t = scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
|
|
|
+
|
|
|
+ let t = getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process);//单位运价×km运距
|
|
|
+ console.log(t);
|
|
|
t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
|
|
|
unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
|
|
|
loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
|
|
|
@@ -434,16 +515,25 @@ ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap) {
|
|
|
}
|
|
|
return scMathUtil.roundForObj(sum,unitPirce);
|
|
|
|
|
|
+
|
|
|
+ function getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process){
|
|
|
+ //如果运输方式为自办运输,则直接返回单位运价即可;
|
|
|
+ let price = conveyance == "自办运输"|| calcType =="内蒙古"? scMathUtil.roundForObj(unitFreight,process):scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
|
|
|
+
|
|
|
+ return price
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
};
|
|
|
|
|
|
-ProjectGLJ.prototype.priceCalc = function (glj,dataMap) {
|
|
|
+ProjectGLJ.prototype.priceCalc = function (glj,dataMap,tpriceList) {
|
|
|
let process = getDecimal("process");
|
|
|
let unitPirce = getDecimal("glj.unitPrice");
|
|
|
let unitPriceHasMix = getDecimal("glj.unitPriceHasMix");
|
|
|
let original_price = 0;
|
|
|
let supplyList = [];
|
|
|
let supplyLocation = "";
|
|
|
- let priceList = _.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
|
|
|
+ let priceList = tpriceList?tpriceList:_.filter(this.datas.originalList,{"connect_key":gljUtil.getIndex(glj)});
|
|
|
if(dataMap["price"] && dataMap["price"]["add"]) priceList = priceList.concat(dataMap["price"]["add"]); //把添加的加进去
|
|
|
for(let p of priceList){
|
|
|
let supplyPrice = p.supplyPrice ,coe = p.coe,supplyLocation=p.supplyLocation;
|
|
|
@@ -454,7 +544,7 @@ ProjectGLJ.prototype.priceCalc = function (glj,dataMap) {
|
|
|
if(t && t["supplyLocation"]) supplyLocation = t["supplyLocation"];
|
|
|
}
|
|
|
if(dataMap["price"] && dataMap["price"]["delete"]){//忽略删除的数据
|
|
|
- if(p.ID ==dataMap["price"]["delete"]) continue;
|
|
|
+ if(dataMap["price"]["delete"][p.ID]) continue;
|
|
|
}
|
|
|
supplyPrice = scMathUtil.roundForObj(supplyPrice,unitPirce);
|
|
|
coe = scMathUtil.roundForObj(coe,unitPirce);
|
|
|
@@ -476,7 +566,7 @@ ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
|
|
|
let me = this;
|
|
|
let gljList = [];
|
|
|
for(let d of datas){
|
|
|
- let g = updateUnit(d.id,d.unitPrice);
|
|
|
+ let g = updateUnit(d.projectGLJID,d);
|
|
|
if(g) gljList.push(g);
|
|
|
}
|
|
|
this.calcQuantity();
|
|
|
@@ -484,13 +574,19 @@ ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
|
|
|
projectGljObject.refreshDataSheet();
|
|
|
//重新计算相关节点
|
|
|
|
|
|
- let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
|
|
|
- projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
|
|
|
+ /* 2019-10-29 这里改成修改材料计算后先不自动计算,先在项目属性上做标记,切换到其它标签页时才做自动计算
|
|
|
+
|
|
|
+ let nodes = me.getImpactRationNodes(gljList);//取到因为改变工料机价格而受影响的定额
|
|
|
+ projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
|
|
|
+
|
|
|
+ */
|
|
|
|
|
|
//刷新定额工料机
|
|
|
gljOprObj.refreshView();
|
|
|
+ //项目单价文件修改标记
|
|
|
+ projectObj.project.projectInfo.changeMark = 'unitFile';
|
|
|
//socket推送更新信息
|
|
|
- projectGljObject.onUnitFileChange();
|
|
|
+ projectGljObject.onUnitFileChange(true);
|
|
|
|
|
|
|
|
|
function updateUnit(id,unitPrice) {
|
|
|
@@ -506,37 +602,27 @@ ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
|
|
|
};
|
|
|
|
|
|
ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
|
|
|
- this.m_updateUnitPrice([{id:id,unitPrice:unitPrice}]);
|
|
|
+ this.m_updateUnitPrice([unitPrice]);
|
|
|
};
|
|
|
|
|
|
ProjectGLJ.prototype.addPriceCalc = async function (datas,pgljID) {
|
|
|
- try {
|
|
|
- let unitPrice = this.materialCal(pgljID,{price:{add:datas}});
|
|
|
- $.bootstrapLoading.start();
|
|
|
- let result = await ajaxPost('/glj/addOriginalCalc',{datas:datas,unitPrice:unitPrice});
|
|
|
- this.datas.originalList = this.datas.originalList.concat(result);
|
|
|
- this.updateUnitPrice(pgljID,unitPrice);
|
|
|
- materialCalcObj.showDatas();
|
|
|
- }catch (e){
|
|
|
- console.log(e)
|
|
|
- }finally {
|
|
|
- $.bootstrapLoading.end();
|
|
|
- }
|
|
|
+ await this.updateMaterialCalcTasks(pgljID,datas,"add","price");
|
|
|
};
|
|
|
|
|
|
ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
|
|
|
- let tasks = [];
|
|
|
let updateDatas=[];
|
|
|
try {
|
|
|
for(let d of datas){
|
|
|
let unitPrice = this.materialCal(d.id,{material:{update:d.doc}});
|
|
|
if(_.isEmpty(unitPrice.doc)) continue;
|
|
|
- tasks.push({updateOne: {filter: {id: unitPrice.id,unit_price_file_id:unitPrice.unit_price_file_id}, update: unitPrice.doc}})
|
|
|
- updateDatas.push({id:d.id,unitPrice:unitPrice})
|
|
|
+ updateDatas.push(unitPrice);
|
|
|
}
|
|
|
+ if(updateDatas.length ==0 ) return;
|
|
|
+ let [unitPrices,sumMap] = this.calcAllMaterial(updateDatas);
|
|
|
+ sumMap = {"unitPrice":unitPrices};
|
|
|
$.bootstrapLoading.start();
|
|
|
- let result = await ajaxPost('/glj/updateMaterialCalc',{tasks:tasks});
|
|
|
- this.m_updateUnitPrice(updateDatas);
|
|
|
+ let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
|
|
|
+ this.refreshMaterialCalcCache(sumMap);
|
|
|
materialCalcObj.showDatas();
|
|
|
}catch (e){
|
|
|
console.log(e)
|
|
|
@@ -547,111 +633,342 @@ ProjectGLJ.prototype.updateMaterialCalc = async function (datas) {
|
|
|
};
|
|
|
|
|
|
ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
|
|
|
+ let updateMap = {};
|
|
|
+ for(let d of datas){
|
|
|
+ updateMap[d.ID] = d.doc;
|
|
|
+ }
|
|
|
+ await this.updateMaterialCalcTasks(pgljID,updateMap,"update","freight");
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,actionType,model){
|
|
|
+ //为了统一接口, 参数dataMap 在添加操作时是一个数组,在修改的时候是一个ID - doc 映射表,在删除的时候传入的是一个ID
|
|
|
+
|
|
|
try {
|
|
|
- let updateMap = {};
|
|
|
- let tasks = [];
|
|
|
- for(let d of datas){
|
|
|
- updateMap[d.ID] = d.doc;
|
|
|
- tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
|
|
|
- }
|
|
|
- let unitPrice = this.materialCal(pgljID,{freight:{update:updateMap}});
|
|
|
- $.bootstrapLoading.start();
|
|
|
- let result = await ajaxPost('/glj/updateFreightCalc',{tasks:tasks,unitPrice:unitPrice});
|
|
|
- for(let o of this.datas.freightList){
|
|
|
- if(updateMap[o.ID]){
|
|
|
- gljUtil.updateProperty(o,updateMap[o.ID]);
|
|
|
+ let actionMap={};
|
|
|
+ let calMap = {};
|
|
|
+ actionMap[actionType] = dataMap;
|
|
|
+ calMap[model] = actionMap;//{freight:{update:updateMap}
|
|
|
+ let unitPrice = this.materialCal(pgljID,calMap);//计算当前这一条材料
|
|
|
+ let [unitPrices,sumMap] = this.calcAllMaterial([unitPrice]);//计算完一条材料后,还要计算因为这条材料而受影响的其它所有材料
|
|
|
+ if(actionType == "update") {//更新情况
|
|
|
+ if (sumMap[model] && sumMap[model][actionType]) {//这一步,合并需要提交后台修改的数据
|
|
|
+ let tt = sumMap[model][actionType];
|
|
|
+ for (let d of datas) {
|
|
|
+ tt[d.ID] = d.doc;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sumMap[model] = actionMap;
|
|
|
}
|
|
|
+ }else if(actionType == "delete"){
|
|
|
+ let IDMap = {};
|
|
|
+ IDMap[dataMap] = true;
|
|
|
+ sumMap[model] = {"delete":IDMap};
|
|
|
+ }else {
|
|
|
+ sumMap[model] = actionMap
|
|
|
}
|
|
|
- this.updateUnitPrice(pgljID,unitPrice);
|
|
|
+ sumMap["unitPrice"] = unitPrices;
|
|
|
+
|
|
|
+ $.bootstrapLoading.start();
|
|
|
+ let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
|
|
|
+ this.refreshMaterialCalcCache(sumMap);
|
|
|
materialCalcObj.showDatas();
|
|
|
}catch (e){
|
|
|
console.log(e)
|
|
|
}finally {
|
|
|
$.bootstrapLoading.end();
|
|
|
}
|
|
|
+
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap){
|
|
|
+ if(updateMap["freight"]) updateList(this.datas.freightList,updateMap["freight"]);
|
|
|
+ if(updateMap["price"]) updateList(this.datas.originalList,updateMap["price"]);
|
|
|
+ if(updateMap["unitPrice"]) {
|
|
|
+ if(Array.isArray(updateMap["unitPrice"])){
|
|
|
+ this.m_updateUnitPrice(updateMap["unitPrice"]);
|
|
|
+ }else {
|
|
|
+ this.m_updateUnitPrice([updateMap["unitPrice"]]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateList(list,updateMap) {
|
|
|
+ if(updateMap["update"]){
|
|
|
+ let map = updateMap["update"];
|
|
|
+ for(let o of list){
|
|
|
+ if(map[o.ID]){
|
|
|
+ gljUtil.updateProperty(o,map[o.ID]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(updateMap["add"]){
|
|
|
+ for(let a of updateMap["add"]){
|
|
|
+ list.push(a);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(updateMap["delete"]){
|
|
|
+ for(let ID in updateMap["delete"]){
|
|
|
+ _.remove(list,{'ID':ID});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
ProjectGLJ.prototype.updatePriceCalc = async function (datas,pgljID) {
|
|
|
- try {
|
|
|
- let updateMap = {};
|
|
|
- let tasks = [];
|
|
|
- for(let d of datas){
|
|
|
- updateMap[d.ID] = d.doc;
|
|
|
- tasks.push({updateOne: {filter: {ID: d.ID}, update: d.doc}})
|
|
|
- }
|
|
|
- let unitPrice = this.materialCal(pgljID,{price:{update:updateMap}});
|
|
|
- $.bootstrapLoading.start();
|
|
|
- let result = await ajaxPost('/glj/updateOriginalCalc',{tasks:tasks,unitPrice:unitPrice});
|
|
|
- for(let o of this.datas.originalList){
|
|
|
- if(updateMap[o.ID]){
|
|
|
- gljUtil.updateProperty(o,updateMap[o.ID]);
|
|
|
- }
|
|
|
- }
|
|
|
- this.updateUnitPrice(pgljID,unitPrice);
|
|
|
- materialCalcObj.showDatas();
|
|
|
- }catch (e){
|
|
|
- console.log(e)
|
|
|
- }finally {
|
|
|
- $.bootstrapLoading.end();
|
|
|
+ let updateMap = {};
|
|
|
+ for(let d of datas){
|
|
|
+ updateMap[d.ID] = d.doc;
|
|
|
}
|
|
|
+ await this.updateMaterialCalcTasks(pgljID,updateMap,"update","price");
|
|
|
};
|
|
|
|
|
|
|
|
|
ProjectGLJ.prototype.addFreightCalc = async function (datas,pgljID) {
|
|
|
+ await this.updateMaterialCalcTasks(pgljID,datas,"add","freight");
|
|
|
+};
|
|
|
+
|
|
|
+ProjectGLJ.prototype.addMaterialRation = async function (code,type,parentID,connect_key){
|
|
|
+ let libIDs = rationLibObj.getStdRationLibIDs();
|
|
|
+ let defaultLibID = rationLibObj.getDefaultStdRationLibID();
|
|
|
+ let selectedLib = sessionStorage.getItem("stdRationLib");
|
|
|
+ selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
|
|
|
+ let datas = {userID: userID,defaultLibID:defaultLibID, rationRepIds: libIDs, code: code,type:type,parentID:parentID,quantityDecimal:getDecimal("ration.quantity"),connect_key:connect_key,projectID:projectObj.project.ID()};
|
|
|
+ datas.actionType="add";
|
|
|
+ await this.updateMaterialRation(datas);
|
|
|
+};
|
|
|
+
|
|
|
+ProjectGLJ.prototype.changeAssistProductionFeeRate = async function (newFeeRate) {
|
|
|
+ $.bootstrapLoading.start();
|
|
|
try {
|
|
|
- let unitPrice = this.materialCal(pgljID,{freight:{add:datas}});
|
|
|
- $.bootstrapLoading.start();
|
|
|
- let result = await ajaxPost('/glj/addFreightCalc',{datas:datas,unitPrice:unitPrice});
|
|
|
- this.datas.freightList = this.datas.freightList.concat(result);
|
|
|
- this.updateUnitPrice(pgljID,unitPrice);
|
|
|
+ await ajaxPost("/glj/changeAssistProductionFeeRate",{unitFileID:projectObj.project.property.unitPriceFile.id,assistProductionFeeRate:newFeeRate});
|
|
|
+ this.datas.constData.assistProductionFeeRate = newFeeRate;
|
|
|
+ //todo 调用材料计算方法,所有材料重算一遍
|
|
|
+ let [unitPrices,sumMap] = this.calcAllMaterial([]);
|
|
|
+ sumMap["unitPrice"] = unitPrices;
|
|
|
+ let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
|
|
|
+ this.refreshMaterialCalcCache(sumMap);
|
|
|
materialCalcObj.showDatas();
|
|
|
-
|
|
|
- }catch (e){
|
|
|
- console.log(e)
|
|
|
+ }catch (err){
|
|
|
+ console.log(err);
|
|
|
}finally {
|
|
|
$.bootstrapLoading.end();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
|
|
|
+ProjectGLJ.prototype.updateMaterialRation = async function (datas){
|
|
|
try {
|
|
|
- let data={ID:ID};
|
|
|
- // 计算预算价
|
|
|
- let unitPrice = this.materialCal(pgljID,{price:{'delete':ID}});
|
|
|
- data.unitPrice = unitPrice;
|
|
|
+ let lists = datas.type == "freight"?this.datas.freightList:this.datas.originalList;
|
|
|
$.bootstrapLoading.start();
|
|
|
- await ajaxPost('/glj/deletePriceCalc',data);
|
|
|
- _.remove(this.datas.originalList,{'ID':data.ID});
|
|
|
- //更新单价文件的值
|
|
|
- this.updateUnitPrice(pgljID,unitPrice);
|
|
|
- materialCalcObj.showDatas();
|
|
|
-
|
|
|
+ let result = await ajaxPost('/ration/updateMaterialRation',datas);
|
|
|
+ if(datas.actionType=="add" && result.projectGLJDatas) this.refreshByDatas(result.projectGLJDatas);//这一步已经更新了运费和原价数据
|
|
|
+ if(datas.actionType == "delete"){
|
|
|
+ let parent = _.find(lists,{ID:datas.parentID}) ;
|
|
|
+ if(parent){
|
|
|
+ _.remove(parent.rations,{ID:datas.rationID});
|
|
|
+ _.remove(parent.ration_gljs,{rationID:datas.rationID});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(datas.actionType == "update"){
|
|
|
+ let parent = _.find(lists,{ID:datas.parentID}) ;
|
|
|
+ let ration = parent?_.find(parent.rations,{ID:datas.rationID}):null;
|
|
|
+ if(ration){
|
|
|
+ if(datas.field == "code" && result.projectGLJDatas){
|
|
|
+ this.refreshByDatas(result.projectGLJDatas);
|
|
|
+ }else {
|
|
|
+ ration[datas.field] = datas.value;
|
|
|
+ if(datas.ext){
|
|
|
+ for(let key in datas.ext){
|
|
|
+ ration[key] = datas.ext[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(datas.ration_gljs){//更新定额工料机数量
|
|
|
+ let gljMap = _.indexBy(parent.ration_gljs,"ID");
|
|
|
+ for(let g of datas.ration_gljs){
|
|
|
+ if(gljMap[g.ID]) gljMap[g.ID].quantity = g.quantity;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}catch (e){
|
|
|
console.log(e)
|
|
|
}finally {
|
|
|
+ //materialCalcObj.showDatas();
|
|
|
+ this.calcMaterialRation(datas.parentID,datas.type);
|
|
|
$.bootstrapLoading.end();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
|
|
|
- try {
|
|
|
- let data={ID:ID};
|
|
|
- // 计算预算价
|
|
|
- let unitPrice = this.materialCal(pgljID,{freight:{'delete':ID}});
|
|
|
- data.unitPrice = unitPrice;
|
|
|
- $.bootstrapLoading.start();
|
|
|
- let result = await ajaxPost('/glj/deleteFreightCalc',data);
|
|
|
- console.log(result);
|
|
|
- _.remove(this.datas.freightList,{'ID':data.ID});
|
|
|
- // 更新单价文件的值
|
|
|
- this.updateUnitPrice(pgljID,unitPrice);
|
|
|
- materialCalcObj.showDatas();
|
|
|
+ProjectGLJ.prototype.getHighlandFee = function (feeType) {
|
|
|
+ let rates = projectObj.project.FeeRate.getActivateFeeRate().rates;
|
|
|
+ let matchType = false;
|
|
|
+ let rate = 0;
|
|
|
+ //获取高原取费类别,是先按feeType取顶层的费率,然后取子项中的“高原地区施工增加费”
|
|
|
+ if(!feeType||feeType=="") return 0;//空时为0
|
|
|
+ let hightlandRate = null;
|
|
|
+ let topParentID = null;
|
|
|
+ for(let r of rates){//费率是按顺序排的,所以先取到顶层,之后的就是目标了。
|
|
|
+ if(matchType && r.ParentID == topParentID) break; //如果feeType已经匹配过了,又经过了下一个顶层节点,那说明该feeType下没有高原费率
|
|
|
+ if(r.name == feeType){
|
|
|
+ matchType = true;
|
|
|
+ topParentID = r.ParentID;
|
|
|
+ }
|
|
|
+ if(matchType && r.name == "高原地区施工增加费"){
|
|
|
+ //顶层先匹配上了,第一个就是要找的费率
|
|
|
+ hightlandRate = r;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(hightlandRate){
|
|
|
+ rate = scMathUtil.roundForObj(hightlandRate.rate,getDecimal("feeRate"));
|
|
|
+ }
|
|
|
+ return rate*0.01
|
|
|
+};
|
|
|
|
|
|
- }catch (e){
|
|
|
- console.log(e)
|
|
|
- }finally {
|
|
|
- $.bootstrapLoading.end();
|
|
|
+ProjectGLJ.prototype.calcEachFreightOrPrice = function (temp,type,priceMap) {//
|
|
|
+ if(temp){
|
|
|
+ if(type == "freight" && temp.conveyance !="自办运输") return null;
|
|
|
+ let sum =0;
|
|
|
+ let gljMap = {};
|
|
|
+ let pgljMap =_.indexBy(this.datas.gljList, 'id');
|
|
|
+ for(let g of temp.ration_gljs){
|
|
|
+ gljMap[g.rationID]?gljMap[g.rationID].push(g):gljMap[g.rationID]=[g];
|
|
|
+ }
|
|
|
+ for(let r of temp.rations){
|
|
|
+ sum = scMathUtil.roundForObj(sum + calcRation(r,gljMap[r.ID],pgljMap,priceMap),6);
|
|
|
+ }
|
|
|
+ sum = scMathUtil.roundForObj(sum,getDecimal("glj.unitPrice"))+"";
|
|
|
+ if(type == "freight" && temp.unitFreight!= sum) return {ID:temp.ID,doc:{unitFreight:sum}};
|
|
|
+ if(type == "price" && temp.supplyPrice !=sum) return {ID:temp.ID,doc:{supplyPrice:sum}};
|
|
|
}
|
|
|
+ return null;
|
|
|
+
|
|
|
+
|
|
|
+ function calcRation(ration,gljs,pMap,priceMap){
|
|
|
+ let result = 0;
|
|
|
+ if(gljs){
|
|
|
+ //to do 计算有辅助定额的情况
|
|
|
+ let processDecimal = getDecimal("process");
|
|
|
+ let hightFeeRate = projectObj.project.projectGLJ.getHighlandFee(ration.feeType);//高原取费类别费率
|
|
|
+ let assFeeRate = scMathUtil.roundForObj(projectObj.project.projectGLJ.datas.constData.assistProductionFeeRate,getDecimal("feeRate")) * 0.01;//辅助生产间接费费率
|
|
|
+ let laberSum = 0;
|
|
|
+ let machineSum = 0;
|
|
|
+ let rationQuantity = scMathUtil.roundForObj(ration.quantity,getDecimal("ration.quantity"));
|
|
|
+ for(let g of gljs){
|
|
|
+ gljOprObj.setGLJPrice(g,pMap[g.projectGLJID]);
|
|
|
+ if(priceMap && priceMap[g.projectGLJID]) g.marketPrice = scMathUtil.roundForObj(priceMap[g.projectGLJID]);
|
|
|
+ let quantity = scMathUtil.roundForObj(g.quantity,getDecimal("glj.quantity"));
|
|
|
+ let t = scMathUtil.roundForObj(quantity * g.marketPrice * rationQuantity,processDecimal);//市场价
|
|
|
+ let rt = scMathUtil.roundForObj(quantity * g.basePrice * rationQuantity,processDecimal);//定额价
|
|
|
+ if(g.type == gljUtil.gljType.LABOUR) laberSum = scMathUtil.roundForObj(laberSum+rt,processDecimal);
|
|
|
+ if(gljUtil.getMainType(g.type) == 3) machineSum = scMathUtil.roundForObj(machineSum+rt,processDecimal);
|
|
|
+ result = scMathUtil.roundForObj(result + t,processDecimal);
|
|
|
+ }
|
|
|
+ let as = scMathUtil.roundForObj(laberSum * assFeeRate,processDecimal);//人工消耗量*定额价*定额工程量*辅助生产间接费费率
|
|
|
+ let tt = scMathUtil.roundForObj(laberSum + machineSum,processDecimal);//人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量
|
|
|
+ let hs = scMathUtil.roundForObj(tt*hightFeeRate,processDecimal);//(人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量)*高原取费类别费率
|
|
|
+ result = scMathUtil.roundForObj(as + result,processDecimal);
|
|
|
+ result = scMathUtil.roundForObj(hs + result,processDecimal);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+ProjectGLJ.prototype.calcMaterialAssQuantity = function (parent,ration,newAssList) {
|
|
|
+ let updateList = [];
|
|
|
+ let assList = calcAssList(newAssList);
|
|
|
+ for(let glj of parent.ration_gljs){
|
|
|
+ if(glj.rationID == ration.ID){
|
|
|
+ updateList.push(calcAssGljQuantity(glj,assList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return updateList;
|
|
|
+
|
|
|
+
|
|
|
+ function calcAssGljQuantity(g,assList) {
|
|
|
+ g.quantity = scMathUtil.roundForObj(g.rationItemQuantity,getDecimal("glj.quantity"));
|
|
|
+ for(let a of assList){
|
|
|
+ let ass = a.ass;
|
|
|
+ let matchGlj = null;
|
|
|
+ for(let aglj of ass.rationGljList){
|
|
|
+ if(aglj.gljId == g.GLJID){
|
|
|
+ matchGlj = aglj;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(matchGlj){
|
|
|
+ let calQuantity =scMathUtil.roundForObj(matchGlj.consumeAmt*a.times,6);
|
|
|
+ g.quantity = scMathUtil.roundForObj(calQuantity + g.quantity,getDecimal("glj.quantity"))+"";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {ID:g.ID,quantity:g.quantity}
|
|
|
+ }
|
|
|
+
|
|
|
+ function calcAssList(rationAssList){
|
|
|
+ let calAss = [];
|
|
|
+ for(let ass of rationAssList){
|
|
|
+ let times = calculateTimes(ass);
|
|
|
+ if(times!=0){
|
|
|
+ calAss.push({ass:ass.assRation,times:times});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return calAss;
|
|
|
+ }
|
|
|
+
|
|
|
+ function calculateTimes(ass){
|
|
|
+ if(ass.name != "运距m") return 0;//只计算运距;
|
|
|
+ let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
|
|
|
+ let r = false;
|
|
|
+ if(times<0){
|
|
|
+ r=true;
|
|
|
+ times=times*-1;
|
|
|
+ }
|
|
|
+ if(ass.carryBit=='四舍五入'){
|
|
|
+ times = _.round(times,ass.decimal);
|
|
|
+ }else if (ass.carryBit=='进一'){
|
|
|
+ times =_.ceil(times,ass.decimal);
|
|
|
+ }else if(ass.carryBit == '舍一'){
|
|
|
+ times = _.floor(times,ass.decimal);
|
|
|
+ }
|
|
|
+ if(r){
|
|
|
+ times=times*-1;
|
|
|
+ }
|
|
|
+ return scMathUtil.roundTo(times,-6);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+ProjectGLJ.prototype.calcMaterialRation = function(ID,type){//计算带定额的运费或者原价
|
|
|
+ let lists = type == "freight"?this.datas.freightList:this.datas.originalList;
|
|
|
+ let temp = _.find(lists,{ID:ID});
|
|
|
+ if(temp){
|
|
|
+ let task = this.calcEachFreightOrPrice(temp,type);
|
|
|
+ let material = materialCalcObj.getMaterialSelected();
|
|
|
+ if(task && material){
|
|
|
+ if(type == "freight") projectObj.project.projectGLJ.updateFreightCalc([task],material.id);
|
|
|
+ if(type == "price") projectObj.project.projectGLJ.updatePriceCalc([task],material.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
|
|
|
+ await this.updateMaterialCalcTasks(pgljID,ID,"delete","price");
|
|
|
+};
|
|
|
+
|
|
|
+ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
|
|
|
+ await this.updateMaterialCalcTasks(pgljID,ID,"delete","freight");
|
|
|
};
|
|
|
|
|
|
ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {
|
|
|
@@ -703,7 +1020,6 @@ ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
|
|
|
CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
|
|
|
$.bootstrapLoading.end();
|
|
|
let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
|
|
|
- console.log(updateMap);
|
|
|
for(let idKey in updateMap){
|
|
|
let gljID = parseInt(idKey);
|
|
|
let glj = me.getByID(gljID);
|
|
|
@@ -769,7 +1085,6 @@ ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- console.log(updateData);
|
|
|
if(updateData.length > 0){
|
|
|
$.bootstrapLoading.start();
|
|
|
CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
|