| 
					
				 | 
			
			
				@@ -66,8 +66,7 @@ async function calculateQuantity(query,noNeedCal,refreshRationName = false){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          gljList = sortRationGLJ(gljList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          for(let i =0;i<gljList.length;i++ ){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             let isLast = i == gljList.length -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             let r = await calculateQuantityPerGLJ(gljList[i],isLast,coeList,assList,adjustState,noNeedCal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+             let r = await calculateQuantityPerGLJ(gljList[i],gljList,coeList,assList,adjustState,noNeedCal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              result.glj_result.push(r); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -137,7 +136,7 @@ function sortRationGLJ(list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,noNeedCal) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,noNeedCal) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let decimalObject =await decimal_facade.getProjectDecimal(glj.projectID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let quantity =  scMathUtil.roundTo(parseFloat(glj.quantity),-decimal); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -155,7 +154,7 @@ async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,no 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if(!glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null||glj.customQuantity==""){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                quantity = calculateQuantityByCoes(quantity,coeList,glj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 quantity = glj.customQuantity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 result.doc.customQuantity = glj.customQuantity; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -163,11 +162,12 @@ async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,no 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let customerCoe = _.last(coeList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if(customerCoe&&customerCoe.isAdjust==1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 quantity = scMathUtil.roundToString(quantity,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             result.doc.quantity =scMathUtil.roundToString(quantity,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            glj.quantity = quantity;//这里保存中间过程计算出来的消耗量,后面处理“+*”操作符时要用到 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        generateAdjustState(glj,coeList,adjustState,isLast,result.doc.quantity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        generateAdjustState(glj,coeList,adjustState,gljList,result.doc.quantity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }catch (err){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         throw err; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -199,7 +199,7 @@ async function calculateAss(quantity,assList,glj) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return scMathUtil.roundTo(quantity,-6); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-function generateAdjustState(glj,coeList,adjustState,isLast,quantity) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function generateAdjustState(glj,coeList,adjustState,gljList,quantity) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //替换工料机 and 添加工料机 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if(glj._doc.createType=='replace'&&glj.rcode!=glj.code){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         adjustState.push({index:stateSeq.replace,content:glj.rcode+'换'+glj.code}); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -214,17 +214,21 @@ function generateAdjustState(glj,coeList,adjustState,isLast,quantity) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // to do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   //标准附注条件调整 + 自定义乘系数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if(isLast){//最后一个工料机的时候才生成,生成一次就可以了 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(_.last(gljList).ID == glj.ID){//最后一个工料机的时候才生成,生成一次就可以了 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for(let i=0;i<coeList.length;i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if(coeList[i].isAdjust==1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if(i==coeList.length-1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     adjustState.push({index:stateSeq.cusCoe,content:getContent(coeList[i].coes)});//自定义乘系数要去掉倍数为1的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if(coeList[i].select_code && coeList[i].select_code!=""){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        _.remove(adjustState,{'content':coeList[i].original_code+'换'+coeList[i].select_code});//去掉替换工料机自动生成的调整状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].original_code+'换'+coeList[i].select_code}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     for(let c of coeList[i].coes){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         if(c.coeType=='单个工料机') _.remove(adjustState,{'type':"添"+c.gljCode});//如果是单个工料机子目换算类型自动添加的,去掉前面手动生成的调整状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         if(c.coeType=='替换人材机') _.remove(adjustState,{'content':c.gljCode+'换'+c.replaceCode});//如果是替换人材机子目换算类型自动添加的,去掉前面手动生成的调整状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if(coeList[i].content) adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -295,28 +299,30 @@ function calculateTimes(ass){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return scMathUtil.roundTo(times,-6); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-function calculateQuantityByCoes(quantity,coeList,glj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let coeQuantity = quantity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if(coeList.length>1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for(let i=0;i<coeList.length-1;i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            coeQuantity = everyCoe(coeQuantity,coeList[i],glj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            coeQuantity = everyCoe(coeQuantity,coeList[i],glj,gljList,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return scMathUtil.roundTo(coeQuantity,-6); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-function everyCoe(quantity,coe,glj) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function everyCoe(quantity,coe,glj,gljList,decimal) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let coeQuantity = quantity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if(coe.isAdjust==1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for(let i=0;i<coe.coes.length;i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if(coe.coes[i].coeType=='单个工料机' &&coe.coes[i].gljCode==glj.code){//if(coe.coes[i].coeType=='单个工料机'&&coe.coes[i].gljCode==glj.code) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }else if(coe.coes[i].coeType== "替换人材机" && glj.rcode == coe.coes[i].gljCode && glj.code == coe.coes[i].replaceCode){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else if(coe.coes[i].coeType== "所选人材机" && glj.rcode == coe.original_code && glj.code == coe.select_code ){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else if(coe.coes[i].coeType=='定额'){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }else if(coeTypeMap[coe.coes[i].coeType]==getRootGLJType(glj.type).ID){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -338,7 +344,15 @@ function calculateQuantityByCustomerCoes(quantify,coe,glj) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return quantify 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-function getCalculateResult(quantify,c) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function getCoeSelectedGLJ(gljList,rcode,code) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(gljList&& code && code !=""){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let o_glj = _.find(gljList,{'rcode':rcode,'code':code}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return o_glj; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function getCalculateResult(quantify,c,coe,gljList,decimal) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let q = quantify; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     switch (c.operator){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         case '+' : 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -353,6 +367,12 @@ function getCalculateResult(quantify,c) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         case '/' : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             q = q / c.amount; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case '+*' : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let o_glj = getCoeSelectedGLJ(gljList,coe.original_code,coe.select_code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(o_glj){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              q = q +  c.amount * scMathUtil.roundForObj(o_glj.quantity,decimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         case '=' : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              q = c.amount; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             break; 
			 |