|
@@ -13,16 +13,82 @@ var bill_model = require('../models/bills');
|
|
|
let decimal_facade = require('./decimal_facade');
|
|
|
const uuidV1 = require('uuid/v1');
|
|
|
let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
|
|
|
+let coeMolde = mongoose.model('std_ration_lib_coe_list');
|
|
|
+
|
|
|
|
|
|
module.exports = {
|
|
|
- replaceRations: replaceRations
|
|
|
+ replaceRations: replaceRations,
|
|
|
+ addNewRation:addNewRation
|
|
|
};
|
|
|
+async function addNewRation(data) {
|
|
|
+ let query = data.itemQuery;
|
|
|
+ let stdRation = null;
|
|
|
+ if(query){
|
|
|
+ let searchDao = new SearchDao();
|
|
|
+ stdRation = await searchDao.getRationItem(query.userID,query.rationRepId,query.code);
|
|
|
+ data.newData.code = query.code;
|
|
|
+ }
|
|
|
+ if(data.brUpdate.length>0){
|
|
|
+ await updateSerialNo(data.brUpdate);
|
|
|
+ }
|
|
|
+ let newRation =await insertNewRation(data.newData,stdRation,data.calQuantity);
|
|
|
+ if(stdRation){
|
|
|
+ return await addRationSubList(stdRation,newRation);
|
|
|
+ }else {
|
|
|
+ return {ration:newRation};
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function updateSerialNo(serialNoUpdate){
|
|
|
+ let tasks=[];
|
|
|
+ for(let data of serialNoUpdate){
|
|
|
+ let task={
|
|
|
+ updateOne:{
|
|
|
+ filter:{
|
|
|
+ ID:data.ID,
|
|
|
+ projectID:data.projectID
|
|
|
+ },
|
|
|
+ update :{
|
|
|
+ serialNo:data.serialNo
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ tasks.push(task);
|
|
|
+ }
|
|
|
+ await ration_model.model.bulkWrite(tasks);
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
-async function replaceRations(uerID,data) {
|
|
|
+async function insertNewRation(newData,std,calQuantity) {//插入新的定额
|
|
|
+ if(std){
|
|
|
+ newData.name = std.name;
|
|
|
+ newData.caption = std.caption;
|
|
|
+ newData.unit = std.unit;
|
|
|
+ newData.libID = std.rationRepId;
|
|
|
+ newData.content = std.jobContent;
|
|
|
+ if (std.chapter) {
|
|
|
+ newData.comments = std.chapter.explanation;
|
|
|
+ newData.ruleText = std.chapter.ruleText;
|
|
|
+ }
|
|
|
+ newData.from = std.type === 'complementary' ? 'cpt' : 'std';
|
|
|
+ newData.programID = std.feeType;
|
|
|
+ newData.rationAssList = createRationAss(std);
|
|
|
+ // calculate ration Quantity
|
|
|
+ }
|
|
|
+ if(calQuantity){
|
|
|
+ await CalculateQuantity(newData,newData.billsItemID,newData.projectID);
|
|
|
+ }
|
|
|
+
|
|
|
+ let newRation = await ration_model.model.create(newData);
|
|
|
+ return newRation;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+async function replaceRations(userID,data) {
|
|
|
let searchDao = new SearchDao();
|
|
|
let recodes = [];
|
|
|
for(let recode of data.nodeInfo){
|
|
|
- let stdRation = await searchDao.getRationItem(uerID,data.libID,recode.newCode);
|
|
|
+ let stdRation = await searchDao.getRationItem(userID,data.libID,recode.newCode);
|
|
|
let newRecode = await replaceRation(recode,stdRation,data.projectID,data.calQuantity);
|
|
|
if(newRecode){
|
|
|
recodes.push(newRecode);
|
|
@@ -37,48 +103,69 @@ async function replaceRation(nodeInfo,stdRation,projectID,calQuantity) {
|
|
|
if(stdRation){
|
|
|
await deleRationSubRecode(projectID,nodeInfo.ID);
|
|
|
let newRation = await updateRation(stdRation,nodeInfo.ID,nodeInfo.billsItemID,projectID,calQuantity);//生成并插入新的定额
|
|
|
- let ration_gljs = await addRationGLJ(stdRation,newRation);
|
|
|
- //console.log(newRation);
|
|
|
- //ration_model.model.bulkWrite(rationTask);//删除定额
|
|
|
- console.log(newRation);
|
|
|
- return newRation;
|
|
|
+ return await addRationSubList(stdRation,newRation);
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function addRationCoe(std,newRation) {
|
|
|
- let ration_coe_list = [];
|
|
|
- if(std.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
|
|
|
-
|
|
|
- }
|
|
|
+async function addRationSubList(stdRation,newRation) {
|
|
|
+ let ration_gljs = await addRationGLJ(stdRation,newRation);
|
|
|
+ let ration_coes = await addRationCoe(stdRation,newRation);
|
|
|
+ //todo 添加增加安装费
|
|
|
|
|
|
+ return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes};
|
|
|
+}
|
|
|
|
|
|
- var criteria= {};
|
|
|
- criteria.ration_coe_list = [];
|
|
|
- var dataLength = 0;
|
|
|
- if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
|
|
|
- dataLength = data.rationCoeList.length
|
|
|
- }
|
|
|
- for(var i=0;i<=dataLength;i++){;
|
|
|
- var newCoe = {
|
|
|
- libID :data.rationRepId,
|
|
|
- rationID:newRation.ID,
|
|
|
- projectID : newRation.projectID
|
|
|
- }
|
|
|
- if(i==dataLength){
|
|
|
- newCoe.coeID=-1;
|
|
|
- newCoe.name = '自定义系数';
|
|
|
- newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
|
|
|
- newCoe.isAdjust=0;
|
|
|
- newCoe.coes = this.getCustomerCoeData();
|
|
|
- }else {
|
|
|
- newCoe.coeID= data.rationCoeList[i].ID;
|
|
|
+async function addRationCoe(std,newRation) {
|
|
|
+ let ration_coe_list = [];
|
|
|
+ let seq = 0;
|
|
|
+ if(std.hasOwnProperty('rationCoeList')&&std.rationCoeList.length>0){//添加标准库的工料机
|
|
|
+ for(let sub of std.rationCoeList){
|
|
|
+ let libCoe = await coeMolde.findOne({'libID':std.rationRepId,'ID':sub.ID,"$or": [{"isDeleted": null}, {"isDeleted": false}]});//std.rationRepId;
|
|
|
+ if(libCoe){
|
|
|
+ let newCoe = {};
|
|
|
+ newCoe.ID = uuidV1();
|
|
|
+ newCoe.coeID = sub.ID;
|
|
|
+ newCoe.seq = seq;
|
|
|
+ newCoe.name = libCoe.name;
|
|
|
+ newCoe.content = libCoe.content;
|
|
|
+ newCoe.isAdjust=0;
|
|
|
+ newCoe.coes = libCoe.coes;
|
|
|
+ newCoe.rationID = newRation.ID;
|
|
|
+ newCoe.projectID = newRation.projectID;
|
|
|
+ seq++;
|
|
|
+ ration_coe_list.push(newCoe);
|
|
|
+ }
|
|
|
}
|
|
|
- criteria.ration_coe_list.push(newCoe);
|
|
|
}
|
|
|
+ let lastCoe ={
|
|
|
+ coeID:-1,
|
|
|
+ name : '自定义系数',
|
|
|
+ content:'人工×1,材料×1,机械×1,主材×1,设备×1',
|
|
|
+ isAdjust:0,
|
|
|
+ seq:seq,
|
|
|
+ rationID : newRation.ID,
|
|
|
+ projectID : newRation.projectID
|
|
|
+ };
|
|
|
+ lastCoe.ID = uuidV1();
|
|
|
+ lastCoe.coes = getCustomerCoeData();
|
|
|
+ ration_coe_list.push(lastCoe);
|
|
|
+ await ration_coe.insertMany(ration_coe_list);
|
|
|
+ return ration_coe_list;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+function getCustomerCoeData() {
|
|
|
+ var coeList = [];
|
|
|
+ coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'定额'});
|
|
|
+ coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'人工'});
|
|
|
+ coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'材料'});
|
|
|
+ coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'机械'});
|
|
|
+ coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'主材'});
|
|
|
+ coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
|
|
|
+ return coeList;
|
|
|
+};
|
|
|
|
|
|
async function addRationGLJ(std,newRation) {
|
|
|
let newRationGLJList = [];
|
|
@@ -94,7 +181,7 @@ async function addRationGLJ(std,newRation) {
|
|
|
newGLJ.rationItemQuantity = sub.consumeAmt;
|
|
|
newGLJ.quantity = sub.consumeAmt;
|
|
|
newGLJ.glj_repository_id = std.rationRepId;
|
|
|
- let std_glj = await std_glj_lib_gljList_model.findOne({'ID': ration_glj.GLJID});
|
|
|
+ let std_glj = await std_glj_lib_gljList_model.findOne({'ID':sub.gljId});
|
|
|
if(std_glj){
|
|
|
newGLJ.name = std_glj.name;
|
|
|
newGLJ.code = std_glj.code;
|
|
@@ -139,26 +226,41 @@ async function updateRation(std,rationID,billsItemID,projectID,calQuantity) {
|
|
|
ration.libID = std.rationRepId;
|
|
|
ration.content = std.jobContent;
|
|
|
ration.adjustState = '';
|
|
|
+ ration.isFromDetail=0;
|
|
|
+ ration.isSubcontract=false;
|
|
|
+ ration.fees=[];
|
|
|
if (std.chapter) {
|
|
|
ration.comments = std.chapter.explanation;
|
|
|
ration.ruleText = std.chapter.ruleText;
|
|
|
}
|
|
|
ration.from = std.type === 'complementary' ? 'cpt' : 'std';
|
|
|
ration.programID = std.feeType;
|
|
|
- ration.rationAssList = [];//生成辅助定额
|
|
|
- if(std.hasOwnProperty('rationAssList')&&std.rationAssList.length>0){
|
|
|
- for(var i=0;i<std.rationAssList.length;i++){
|
|
|
- var ass = std.rationAssList[i];
|
|
|
- ass.actualValue = ass.stdValue;
|
|
|
- ration.rationAssList.push(ass);
|
|
|
- }
|
|
|
- }
|
|
|
+ ration.rationAssList = createRationAss(std);//生成辅助定额
|
|
|
if(calQuantity){
|
|
|
await CalculateQuantity(ration,billsItemID,projectID);
|
|
|
}
|
|
|
- let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},ration,{new: true});
|
|
|
+
|
|
|
+ let unsetObject = {
|
|
|
+ "marketUnitFee":1,
|
|
|
+ 'marketTotalFee':1,
|
|
|
+ "maskName":1
|
|
|
+ }
|
|
|
+ let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},{"$set":ration,"$unset":unsetObject},{new: true});//;
|
|
|
return newRation;
|
|
|
}
|
|
|
+
|
|
|
+function createRationAss(std) {
|
|
|
+ let rationAssList = [];//生成辅助定额
|
|
|
+ if(std.hasOwnProperty('rationAssList')&&std.rationAssList.length>0){
|
|
|
+ for(let i=0;i<std.rationAssList.length;i++){
|
|
|
+ let ass = std.rationAssList[i];
|
|
|
+ ass.actualValue = ass.stdValue;
|
|
|
+ rationAssList.push(ass);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rationAssList;
|
|
|
+}
|
|
|
+
|
|
|
async function CalculateQuantity (ration,billsItemID,projectID) {
|
|
|
// calculate ration Quantity
|
|
|
let decimalObject =await decimal_facade.getProjectDecimal(projectID);
|