|  | @@ -18,7 +18,7 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	<select id="queryByCostIngredient" resultType="org.jeecg.modules.cost.entity.SyCostAllocationIngredient">
 | 
	
		
			
				|  |  |  		select tab.*,isnull(tab1.purchaseQuantity,0) as purchaseQuantity,isnull(tab1.purchaseQuantity,0)-tab2.jian as ingredientsTransferQuantity,
 | 
	
		
			
				|  |  | -				isnull(tab1.purchaseQuantity,0)-tab.usageQuantity as ingredientsRemainingQuantity,
 | 
	
		
			
				|  |  | +				tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as ingredientsRemainingQuantity,
 | 
	
		
			
				|  |  |  				(tab1.purchaseQuantity-tab.usageQuantity)/tab1.purchaseQuantity as loss,(isnull(tab1.purchaseQuantity,0)-tab2.jian)*tab.cost as transferCost
 | 
	
		
			
				|  |  |  		from 
 | 
	
		
			
				|  |  |  		(
 | 
	
	
		
			
				|  | @@ -75,7 +75,7 @@
 | 
	
		
			
				|  |  |  		union all
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		select tab.*,isnull(tab1.purchaseQuantity,0) as purchaseQuantity,isnull(tab1.purchaseQuantity,0)-tab2.jian as ingredientsTransferQuantity,
 | 
	
		
			
				|  |  | -				isnull(tab1.purchaseQuantity,0)-tab.usageQuantity as ingredientsRemainingQuantity,
 | 
	
		
			
				|  |  | +				tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as ingredientsRemainingQuantity,
 | 
	
		
			
				|  |  |  				(tab1.purchaseQuantity-tab.usageQuantity)/tab1.purchaseQuantity as loss,(isnull(tab1.purchaseQuantity,0)-tab2.jian)*tab.cost as transferCost
 | 
	
		
			
				|  |  |  		from
 | 
	
		
			
				|  |  |  		(
 | 
	
	
		
			
				|  | @@ -245,4 +245,86 @@
 | 
	
		
			
				|  |  |  		)tab2 on tab2.cInvName=tab1.cInvName and tab1.cBatch=tab2.cBatch
 | 
	
		
			
				|  |  |  		 where tab1.purchaseQuantity-tab2.jian>0
 | 
	
		
			
				|  |  |      </select>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	<select id="queryRemainingByIngredient" resultType="org.jeecg.modules.cost.entity.SyRemaining">
 | 
	
		
			
				|  |  | +		select tab.goodsName,ccode as planCode,tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as number,
 | 
	
		
			
				|  |  | +				tab.cost as unitCost,(tab.usageQuantity-isnull(tab1.purchaseQuantity,0))*tab.cost as cost
 | 
	
		
			
				|  |  | +		from
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select oti.cInvName as goodsName,max(om.cCode) as ccode,sum(ot.iQuantity) as usageQuantity,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.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
 | 
	
		
			
				|  |  | +		left join
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity from UFDATA_901_2021.dbo.rdrecords01 rs
 | 
	
		
			
				|  |  | +				join UFDATA_901_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
 | 
	
		
			
				|  |  | +				where iordercode in (
 | 
	
		
			
				|  |  | +						select distinct od.csocode
 | 
	
		
			
				|  |  | +						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.Inventory omi on omi.cInvCode=od.cInvCode
 | 
	
		
			
				|  |  | +						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')
 | 
	
		
			
				|  |  | +				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  | +		)tab1 on tab1.cInvName=tab.goodsName
 | 
	
		
			
				|  |  | +		where usageQuantity-isnull(tab1.purchaseQuantity,0)>0
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		union all
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		select tab.goodsName,ccode as planCode,tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as number,
 | 
	
		
			
				|  |  | +				tab.cost as unitCost,(tab.usageQuantity-isnull(tab1.purchaseQuantity,0))*tab.cost as cost
 | 
	
		
			
				|  |  | +		from
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select oti.cInvName as goodsName,max(om.cCode) as ccode,sum(ot.iQuantity) as usageQuantity,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.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
 | 
	
		
			
				|  |  | +		left join
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity from UFDATA_903_2021.dbo.rdrecords01 rs
 | 
	
		
			
				|  |  | +				join UFDATA_903_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
 | 
	
		
			
				|  |  | +				where iordercode in (
 | 
	
		
			
				|  |  | +						select distinct od.csocode
 | 
	
		
			
				|  |  | +						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.Inventory omi on omi.cInvCode=od.cInvCode
 | 
	
		
			
				|  |  | +						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')
 | 
	
		
			
				|  |  | +				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  | +		)tab1 on tab1.cInvName=tab.goodsName
 | 
	
		
			
				|  |  | +		where usageQuantity-isnull(tab1.purchaseQuantity,0)>0
 | 
	
		
			
				|  |  | +    </select>
 | 
	
		
			
				|  |  |  </mapper>
 |