|
|
@@ -168,6 +168,7 @@ function createNewRecord(ration_glj) {
|
|
|
newRecoed.GLJID = ration_glj.GLJID;
|
|
|
newRecoed.rationID = ration_glj.rationID;
|
|
|
newRecoed.rationItemQuantity = ration_glj.rationItemQuantity;
|
|
|
+ newRecoed.customQuantity = ration_glj.customQuantity;
|
|
|
newRecoed.quantity = ration_glj.quantity;
|
|
|
newRecoed.name = ration_glj.name;
|
|
|
newRecoed.code = ration_glj.code;
|
|
|
@@ -733,7 +734,7 @@ function addMixRatioToRationGLJ(g,subList,newRecodes,GLJMap){
|
|
|
unit:mr.unit,
|
|
|
specs:mr.specs,
|
|
|
from:mr.from,
|
|
|
- createType:g.createType,
|
|
|
+ createType:'add',
|
|
|
shortName:mr.unit_price.short_name,
|
|
|
billsItemID:g.billsItemID,
|
|
|
type:mr.type,
|
|
|
@@ -749,28 +750,40 @@ function addMixRatioToRationGLJ(g,subList,newRecodes,GLJMap){
|
|
|
}
|
|
|
|
|
|
async function replaceGLJByData(data,compilation) {
|
|
|
- let projectGljModel = new GLJListModel();
|
|
|
+ let projectGljModel = new GLJListModel(),newRecodes=[],deleteList=[];
|
|
|
let [unitFileId,ext] = await prepareExtData(data.projectID,compilation);
|
|
|
let result = await projectGljModel.addList(getGLJSearchInfo(data),unitFileId,ext);
|
|
|
- let typeString = result.type+'';
|
|
|
data.projectGLJID = result.id;
|
|
|
- // CompositionGLJ=await this.getCompositionGLJByData(data,unitPriceFileId);
|
|
|
- let [newRecodes,deleteList] = await replaceMixRatio(data,result,unitFileId);
|
|
|
- let updateResult = await ration_glj.findOneAndUpdate({ID: data.ID, projectID: data.projectID}, data);//更新定额工料机
|
|
|
- //组装回传数据
|
|
|
- data.marketPrice = result.unit_price.market_price;
|
|
|
- data.adjustPrice = result.unit_price.base_price;
|
|
|
- data.basePrice = result.unit_price.base_price;
|
|
|
- data.isAdd = result.unit_price.is_add;
|
|
|
- if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
|
|
|
- data.isEstimate = result.is_evaluate;
|
|
|
- }
|
|
|
- if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
|
- data.subList = getMixRatioShowDatas(result.subList);
|
|
|
+ if(data.toCommercial == true){//从混凝土改成商品混凝土,
|
|
|
+ let [contype,newR] = await concreteTypeToCommercial(data);
|
|
|
+ newRecodes.push(newR);
|
|
|
+ data=contype;
|
|
|
+ }else {
|
|
|
+ let [newList,tdelList] = await replaceMixRatio(data,result,unitFileId);
|
|
|
+ newRecodes = newList;
|
|
|
+ deleteList = tdelList;
|
|
|
+ let updateResult = await ration_glj.findOneAndUpdate({ID: data.ID, projectID: data.projectID}, data);//更新定额工料机
|
|
|
}
|
|
|
+
|
|
|
return {data:data,newRecodes:newRecodes,deleteList:deleteList};
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+async function concreteTypeToCommercial(data) {
|
|
|
+ //旧的自定义消耗量改为0
|
|
|
+ let contype = await ration_glj.findOneAndUpdate({ID: data.originalID}, {customQuantity:'0'});
|
|
|
+ //因为商品混凝土是没有组成物的,所以不用考虑组成物的情况
|
|
|
+ let new_glj = createComercialConcreteData(data);
|
|
|
+ await ration_glj.create(new_glj);
|
|
|
+ return [contype,new_glj];
|
|
|
+}
|
|
|
+
|
|
|
+function createComercialConcreteData(data){
|
|
|
+ data.ID = uuidV1();
|
|
|
+ return createNewRecord(data);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
async function replaceMixRatio(g,result,unitFileId){
|
|
|
let newRecodes=[],deleteList = [];
|
|
|
if(gljUtil.isConcreteType(g.type)||gljUtil.isCommercialConcreteType(g.type)){//混凝土大类,商品混凝土属于相同大类,替换前和替换后只判断一个就好了
|
|
|
@@ -823,14 +836,21 @@ async function replaceGLJ(data,compilation) {
|
|
|
|
|
|
async function replaceMixRatioForMReplace(tasks,result,unitFileId) {
|
|
|
let allNewRecodes = [],allDeleteList=[];
|
|
|
- for(let t of tasks){
|
|
|
- let tem = _.cloneDeep(t.updateOne.update);
|
|
|
- tem.ID = t.updateOne.filter.ID;
|
|
|
- tem.rationID = t.updateOne.filter.rationID;
|
|
|
- delete t.updateOne.filter.rationID;
|
|
|
- let [newRecodes,deleteList] = await replaceMixRatio(tem,result,unitFileId);
|
|
|
- allNewRecodes = allNewRecodes.concat(newRecodes);
|
|
|
- allDeleteList = allDeleteList.concat(deleteList);
|
|
|
+ for(let t of tasks){//要新增一条商品混凝土
|
|
|
+ if(t.insertOne){
|
|
|
+ t.insertOne.document.projectGLJID = result.id;
|
|
|
+ t.insertOne.document = createComercialConcreteData(t.insertOne.document);
|
|
|
+ allNewRecodes.push(t.insertOne.document);
|
|
|
+ }else if(t.updateOne&&t.updateOne.update.isConcrete == true){//过滤掉只更新自定义消耗量的task
|
|
|
+ let tem = _.cloneDeep(t.updateOne.update);
|
|
|
+ tem.ID = t.updateOne.filter.ID;
|
|
|
+ tem.rationID = t.updateOne.filter.rationID;
|
|
|
+ delete t.updateOne.filter.rationID;
|
|
|
+ delete t.updateOne.update.isConcrete;
|
|
|
+ let [newRecodes,deleteList] = await replaceMixRatio(tem,result,unitFileId);
|
|
|
+ allNewRecodes = allNewRecodes.concat(newRecodes);
|
|
|
+ allDeleteList = allDeleteList.concat(deleteList);
|
|
|
+ }
|
|
|
}
|
|
|
return {newRecodes:allNewRecodes,deleteList:allDeleteList}
|
|
|
}
|
|
|
@@ -846,25 +866,17 @@ async function mReplaceGLJ(data,compilation) {
|
|
|
newDoc.projectGLJID = result.id;
|
|
|
let rationList = [];//await ration_glj.distinct('rationID', data.query);
|
|
|
for(let t of data.tasks){
|
|
|
- rationList.push(t.updateOne.filter.rationID);
|
|
|
- t.updateOne.update.projectGLJID = result.id;//更新项目工料机ID
|
|
|
+ if(t.updateOne){
|
|
|
+ rationList.push(t.updateOne.filter.rationID);
|
|
|
+ if(t.updateOne.update.code) t.updateOne.update.projectGLJID = result.id;//如果是不是只修改自定义消耗的task,更新项目工料机ID
|
|
|
+ }
|
|
|
}
|
|
|
- if(gljUtil.isConcreteType(result.unit_price.type)) {
|
|
|
+ if(gljUtil.isConcreteType(result.unit_price.type)||gljUtil.isCommercialConcreteType(result.unit_price.type)) {
|
|
|
mixResult = await replaceMixRatioForMReplace(data.tasks,result,unitFileId);
|
|
|
noNeedCal = null;
|
|
|
}
|
|
|
await ration_glj.bulkWrite(data.tasks);
|
|
|
|
|
|
- newDoc.marketPrice = result.unit_price.market_price;
|
|
|
- newDoc.adjustPrice = result.unit_price.base_price;
|
|
|
- newDoc.basePrice = result.unit_price.base_price;
|
|
|
- newDoc.isAdd = result.unit_price.is_add;
|
|
|
- if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
|
|
|
- newDoc.isEstimate = result.is_evaluate;
|
|
|
- }
|
|
|
- if (result.hasOwnProperty('subList') && result.subList.length > 0) {
|
|
|
- newDoc.subList = getMixRatioShowDatas(result.subList);
|
|
|
- }
|
|
|
let [stateList,glj_result] = await changAdjustState(data, rationList,noNeedCal);
|
|
|
data.doc = newDoc;
|
|
|
mresult.data = data;
|