|  | @@ -17,28 +17,96 @@
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	<select id="queryByCostFabric" parameterType="java.lang.String" resultType="org.jeecg.modules.cost.entity.SyCostAllocationFabric">
 | 
	
		
			
				|  |  | -		select oti.cInvName as goodsName,sum(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as usageQuantity,sum(ot.iSendQTY) as planQuantity,sum(rs.iQuantity) as purchaseQuantity
 | 
	
		
			
				|  |  | -		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
 | 
	
		
			
				|  |  | -		join UFDATA_903_2021.dbo.rdrecords01 rs on rs.iOMoDID=od.MODetailsID
 | 
	
		
			
				|  |  | -		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 '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
 | 
	
		
			
				|  |  | -		GROUP BY oti.cInvName
 | 
	
		
			
				|  |  | +		select tab.*,tab1.purchaseQuantity,tab2.jian-tab1.purchaseQuantity as fabrictransferQuantity,
 | 
	
		
			
				|  |  | +				tab1.purchaseQuantity-tab.usageQuantity as fabricremainingQuantity,
 | 
	
		
			
				|  |  | +				(tab1.purchaseQuantity-tab.usageQuantity)/tab1.purchaseQuantity as loss
 | 
	
		
			
				|  |  | +		from 
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select oti.cInvName as goodsName,sum(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as usageQuantity,
 | 
	
		
			
				|  |  | +						sum(ot.iSendQTY) as planQuantity
 | 
	
		
			
				|  |  | +				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
 | 
	
		
			
				|  |  | +				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 '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
 | 
	
		
			
				|  |  | +				GROUP BY oti.cInvName
 | 
	
		
			
				|  |  | +		) tab
 | 
	
		
			
				|  |  | +		left join 
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity from 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 '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
 | 
	
		
			
				|  |  | +				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  | +		)tab1 on tab1.cInvName=tab.goodsName
 | 
	
		
			
				|  |  | +		left join 
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select i.cInvName,sum(rs.iQuantity) as jian from rdrecords11 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 '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
 | 
	
		
			
				|  |  | +				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  | +		)tab2 on tab2.cInvName=tab.goodsName
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		union all
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -		select oti.cInvName as goodsName,sum(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as usageQuantity,sum(ot.iSendQTY) as planQuantity,sum(rs.iQuantity) as purchaseQuantity
 | 
	
		
			
				|  |  | -		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
 | 
	
		
			
				|  |  | -		join UFDATA_901_2021.dbo.rdrecords01 rs on rs.iOMoDID=od.MODetailsID 
 | 
	
		
			
				|  |  | -		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 '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
 | 
	
		
			
				|  |  | -		GROUP BY oti.cInvName
 | 
	
		
			
				|  |  | +		select tab.*,tab1.purchaseQuantity,tab2.jian-tab1.purchaseQuantity as fabrictransferQuantity,
 | 
	
		
			
				|  |  | +				tab1.purchaseQuantity-tab.usageQuantity as fabricremainingQuantity,
 | 
	
		
			
				|  |  | +				(tab1.purchaseQuantity-tab.usageQuantity)/tab1.purchaseQuantity as loss
 | 
	
		
			
				|  |  | +		from
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select oti.cInvName as goodsName,sum(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as usageQuantity,
 | 
	
		
			
				|  |  | +						sum(ot.iSendQTY) as planQuantity
 | 
	
		
			
				|  |  | +				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
 | 
	
		
			
				|  |  | +				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 '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
 | 
	
		
			
				|  |  | +				GROUP BY oti.cInvName
 | 
	
		
			
				|  |  | +		) tab
 | 
	
		
			
				|  |  | +		left join
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity from 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 '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
 | 
	
		
			
				|  |  | +				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  | +		)tab1 on tab1.cInvName=tab.goodsName
 | 
	
		
			
				|  |  | +		left join
 | 
	
		
			
				|  |  | +		(
 | 
	
		
			
				|  |  | +				select i.cInvName,sum(rs.iQuantity) as jian from rdrecords11 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 '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
 | 
	
		
			
				|  |  | +				GROUP BY i.cInvName,rs.cBatch
 | 
	
		
			
				|  |  | +		)tab2 on tab2.cInvName=tab.goodsName
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  </mapper>
 |