|  | @@ -131,8 +131,30 @@
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	<select id="queryTransferByIngredient" resultType="org.jeecg.modules.cost.entity.SyTransfer">
 | 
	
		
			
				|  |  | -		select tab1.cInvName as goodsName,tab1.cCode as planCode,tab1.purchaseQuantity-tab2.jian as number
 | 
	
		
			
				|  |  | +		select tab1.cInvName as goodsName,tab1.cCode as planCode,tab1.purchaseQuantity-tab2.jian as number,
 | 
	
		
			
				|  |  | +				tab.cost as unitCost,(purchaseQuantity-tab2.jian)*tab.cost as cost
 | 
	
		
			
				|  |  |  		from
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select oti.cInvName as goodsName,sum(pb.iCost) as cost
 | 
	
		
			
				|  |  | +				from UFDATA_901_2021.dbo.om_momain om
 | 
	
		
			
				|  |  | +				join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
 | 
	
		
			
				|  |  | +				join UFDATA_901_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID
 | 
	
		
			
				|  |  | +				join UFDATA_901_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
 | 
	
		
			
				|  |  | +				join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
 | 
	
		
			
				|  |  | +				left join (
 | 
	
		
			
				|  |  | +						SELECT p.cInvCode,p.iorderdid,sum(bi.iMoney) as rmbAmount,sum(bi.iOriMoney) as usdAmount
 | 
	
		
			
				|  |  | +									,sum(bi.iMoney-bi.iTaxPrice) as priceExcludingtax,sum(bi.iCost) as iCost
 | 
	
		
			
				|  |  | +						from UFDATA_901_2021.dbo.PO_Podetails p
 | 
	
		
			
				|  |  | +						join UFDATA_901_2021.dbo.PurBillVouchs bi  on bi.iPOsID=p.ID
 | 
	
		
			
				|  |  | +						GROUP BY p.cInvCode,p.iorderdid
 | 
	
		
			
				|  |  | +				 ) pb on pb.cInvCode=ot.cInvCode and pb.iorderdid=od.isosid
 | 
	
		
			
				|  |  | +				WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%'
 | 
	
		
			
				|  |  | +							and om.cCode LIKE CONCAT(#{code},'%') and (oti.cInvCcode like '05%' or oti.cInvCcode like '06%'
 | 
	
		
			
				|  |  | +							or oti.cInvCcode like '07%' or oti.cInvCCode = '0399' or oti.cInvCCode = '0499')
 | 
	
		
			
				|  |  | +							and oti.cInvName = #{goodName}
 | 
	
		
			
				|  |  | +				GROUP BY oti.cInvName
 | 
	
		
			
				|  |  | +		) tab
 | 
	
		
			
				|  |  | +		join
 | 
	
		
			
				|  |  |  		(
 | 
	
		
			
				|  |  |  				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch,(
 | 
	
		
			
				|  |  |  						select distinct om.cCode
 | 
	
	
		
			
				|  | @@ -147,7 +169,7 @@
 | 
	
		
			
				|  |  |  				where (i.cInvCcode like '05%' or i.cInvCcode like '06%' or i.cInvCcode like '07%'
 | 
	
		
			
				|  |  |  						or i.cInvCCode = '0399' or i.cInvCCode = '0499')
 | 
	
		
			
				|  |  |  				GROUP BY i.cInvName,rs.cBatch,rs.iordercode
 | 
	
		
			
				|  |  | -		)tab1
 | 
	
		
			
				|  |  | +		)tab1 on tab1.cInvName=tab.goodsName
 | 
	
		
			
				|  |  |  		 join
 | 
	
		
			
				|  |  |  		(
 | 
	
		
			
				|  |  |  				select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch from UFDATA_901_2021.dbo.rdrecords11 rs
 | 
	
	
		
			
				|  | @@ -160,15 +182,37 @@
 | 
	
		
			
				|  |  |  						WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
 | 
	
		
			
				|  |  |  									and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
 | 
	
		
			
				|  |  |  				) and (i.cInvCcode like '05%' or i.cInvCcode like '06%' or i.cInvCcode like '07%'
 | 
	
		
			
				|  |  | -						or i.cInvCCode = '0399' or i.cInvCCode = '0499') and i.cInvName = #{goodName}
 | 
	
		
			
				|  |  | +						or i.cInvCCode = '0399' or i.cInvCCode = '0499')
 | 
	
		
			
				|  |  |  				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  |  		)tab2 on tab2.cInvName=tab1.cInvName and tab1.cBatch=tab2.cBatch
 | 
	
		
			
				|  |  |  		 where tab1.purchaseQuantity-tab2.jian>0
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		 union all
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -		 select tab1.cInvName as goodsName,tab1.cCode as planCode,tab1.purchaseQuantity-tab2.jian as number
 | 
	
		
			
				|  |  | +		 select tab1.cInvName as goodsName,tab1.cCode as planCode,tab1.purchaseQuantity-tab2.jian as number,
 | 
	
		
			
				|  |  | +				tab.cost as unitCost,(purchaseQuantity-tab2.jian)*tab.cost as cost
 | 
	
		
			
				|  |  |  		from
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select oti.cInvName as goodsName,sum(pb.iCost) as cost
 | 
	
		
			
				|  |  | +				from UFDATA_903_2021.dbo.om_momain om
 | 
	
		
			
				|  |  | +				join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
 | 
	
		
			
				|  |  | +				join UFDATA_903_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID
 | 
	
		
			
				|  |  | +				join UFDATA_903_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
 | 
	
		
			
				|  |  | +				join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
 | 
	
		
			
				|  |  | +				left join (
 | 
	
		
			
				|  |  | +						SELECT p.cInvCode,p.iorderdid,sum(bi.iMoney) as rmbAmount,sum(bi.iOriMoney) as usdAmount
 | 
	
		
			
				|  |  | +									,sum(bi.iMoney-bi.iTaxPrice) as priceExcludingtax,sum(bi.iCost) as iCost
 | 
	
		
			
				|  |  | +						from UFDATA_903_2021.dbo.PO_Podetails p
 | 
	
		
			
				|  |  | +						join UFDATA_903_2021.dbo.PurBillVouchs bi  on bi.iPOsID=p.ID
 | 
	
		
			
				|  |  | +						GROUP BY p.cInvCode,p.iorderdid
 | 
	
		
			
				|  |  | +				 ) pb on pb.cInvCode=ot.cInvCode and pb.iorderdid=od.isosid
 | 
	
		
			
				|  |  | +				WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%'
 | 
	
		
			
				|  |  | +							and om.cCode LIKE CONCAT(#{code},'%') and (oti.cInvCcode like '05%' or oti.cInvCcode like '06%'
 | 
	
		
			
				|  |  | +							or oti.cInvCcode like '07%' or oti.cInvCCode = '0399' or oti.cInvCCode = '0499')
 | 
	
		
			
				|  |  | +							and oti.cInvName = #{goodName}
 | 
	
		
			
				|  |  | +				GROUP BY oti.cInvName
 | 
	
		
			
				|  |  | +		) tab
 | 
	
		
			
				|  |  | +		join
 | 
	
		
			
				|  |  |  		(
 | 
	
		
			
				|  |  |  				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch,(
 | 
	
		
			
				|  |  |  						select distinct om.cCode
 | 
	
	
		
			
				|  | @@ -183,7 +227,7 @@
 | 
	
		
			
				|  |  |  				where (i.cInvCcode like '05%' or i.cInvCcode like '06%' or i.cInvCcode like '07%'
 | 
	
		
			
				|  |  |  						or i.cInvCCode = '0399' or i.cInvCCode = '0499')
 | 
	
		
			
				|  |  |  				GROUP BY i.cInvName,rs.cBatch,rs.iordercode
 | 
	
		
			
				|  |  | -		)tab1
 | 
	
		
			
				|  |  | +		)tab1 on tab1.cInvName=tab.goodsName
 | 
	
		
			
				|  |  |  		 join
 | 
	
		
			
				|  |  |  		(
 | 
	
		
			
				|  |  |  				select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch from UFDATA_903_2021.dbo.rdrecords11 rs
 | 
	
	
		
			
				|  | @@ -196,7 +240,7 @@
 | 
	
		
			
				|  |  |  						WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
 | 
	
		
			
				|  |  |  									and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
 | 
	
		
			
				|  |  |  				) and (i.cInvCcode like '05%' or i.cInvCcode like '06%' or i.cInvCcode like '07%'
 | 
	
		
			
				|  |  | -						or i.cInvCCode = '0399' or i.cInvCCode = '0499') and i.cInvName = #{goodName}
 | 
	
		
			
				|  |  | +						or i.cInvCCode = '0399' or i.cInvCCode = '0499')
 | 
	
		
			
				|  |  |  				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  |  		)tab2 on tab2.cInvName=tab1.cInvName and tab1.cBatch=tab2.cBatch
 | 
	
		
			
				|  |  |  		 where tab1.purchaseQuantity-tab2.jian>0
 |