|  | @@ -31,8 +31,8 @@
 | 
	
		
			
				|  |  |  		from
 | 
	
		
			
				|  |  |  		(
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -		select t4.cInvCode,t4.goodsName,max(t4.dosage) as dosage,max(t4.usageQuantity) as usageQuantity,STRING_AGG(t4.supper,',') as supper,sum(t4.rmbAmount) as rmbAmount,sum(t4.usdAmount) as usdAmount,sum(t4.priceExcludingtax) as priceExcludingtax,sum(t4.cost) as cost from(
 | 
	
		
			
				|  |  | -		SELECT t3.ccode,t3.cInvCode,t3.goodsName,t3.cVenAbbName AS supper,max( t3.dosage ) AS dosage,SUM ( t3.usageQuantity ) AS usageQuantity,
 | 
	
		
			
				|  |  | +		select t4.cInvCode,t4.goodsName,max(t4.dosage) as dosage,sum(t4.usageQuantity) as usageQuantity,STRING_AGG(t4.supper,',') as supper,sum(t4.rmbAmount) as rmbAmount,sum(t4.usdAmount) as usdAmount,sum(t4.priceExcludingtax) as priceExcludingtax,sum(t4.cost) as cost from(
 | 
	
		
			
				|  |  | +		SELECT t3.ccode,t3.cInvCode,t3.goodsName,t3.cVenAbbName AS supper,avg( t3.dosage ) AS dosage,SUM ( t3.usageQuantity ) AS usageQuantity,
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		SUM ( t3.rmbAmount ) AS rmbAmount,SUM ( t3.usdAmount ) AS usdAmount,SUM ( t3.priceExcludingtax ) AS priceExcludingtax,
 | 
	
		
			
				|  |  |  		SUM ( t3.totalCost )/sum(totalSum) AS cost
 | 
	
	
		
			
				|  | @@ -65,41 +65,8 @@
 | 
	
		
			
				|  |  |  		JOIN UFDATA_103_2021.dbo.Vendor ven ON bm.cVenCode = ven.cVenCode
 | 
	
		
			
				|  |  |  		JOIN UFDATA_103_2021.dbo.Inventory oti ON oti.cInvCode= pod.cInvCode
 | 
	
		
			
				|  |  |  		GROUP BY bi.cInvCode,pod.isosid,ven.cVenAbbName
 | 
	
		
			
				|  |  | -		) AS t2
 | 
	
		
			
				|  |  | -		on
 | 
	
		
			
				|  |  | -		t1.cInvCode= t2.cInvCode
 | 
	
		
			
				|  |  | -		AND t2.isosid= t1.isosid
 | 
	
		
			
				|  |  | -		) t3
 | 
	
		
			
				|  |  | -		GROUP BY
 | 
	
		
			
				|  |  | -		t3.ccode,t3.cInvCode,t3.goodsName,t3.cVenAbbName
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  		union all
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		SELECT t3.ccode as ccode,t3.cInvCode,t3.goodsName,t3.cVenAbbName AS supper,max( t3.dosage ) AS dosage,SUM ( t3.usageQuantity ) AS usageQuantity,
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		SUM ( t3.rmbAmount ) AS rmbAmount,SUM ( t3.usdAmount ) AS usdAmount,SUM ( t3.priceExcludingtax ) AS priceExcludingtax,
 | 
	
		
			
				|  |  | -		SUM ( t3.totalCost )/sum(totalSum) AS cost
 | 
	
		
			
				|  |  | -		FROM(
 | 
	
		
			
				|  |  | -		SELECT t1.ccode,t1.cInvCode,t1.goodsName,t1.dosage,t1.usageQuantity,t2.cVenAbbName,t2.rmbAmount,t2.usdAmount,t2.priceExcludingtax,t2.totalCost,t2.totalSum
 | 
	
		
			
				|  |  | -		FROM
 | 
	
		
			
				|  |  | -		(
 | 
	
		
			
				|  |  | -		SELECT ot.cInvCode,od.isosid,om.ccode,oti.cInvName AS goodsName,SUM (ot.iUnitQuantity) AS dosage,SUM (ot.iSendQTY) AS usageQuantity
 | 
	
		
			
				|  |  | -		FROM UFDATA_103_2021.dbo.cost_allocation_accessories_view vif
 | 
	
		
			
				|  |  | -		join UFDATA_103_2021.dbo.om_momain om on om.ccode = vif.cCode
 | 
	
		
			
				|  |  | -		JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.moid= od.moid
 | 
	
		
			
				|  |  | -		JOIN UFDATA_103_2021.dbo.OM_MOMaterials ot ON ot.MoDetailsID= od.MODetailsID and ot.cInvCode = vif.cInvCode
 | 
	
		
			
				|  |  | -		JOIN UFDATA_103_2021.dbo.Vendor v ON om.cVenCode= v.cVenCode
 | 
	
		
			
				|  |  | -		JOIN UFDATA_103_2021.dbo.Inventory oti ON oti.cInvCode= ot.cInvCode
 | 
	
		
			
				|  |  | -		JOIN UFDATA_103_2021.dbo.Inventory omi ON omi.cInvCode= od.cInvCode
 | 
	
		
			
				|  |  | -		WHERE
 | 
	
		
			
				|  |  | -		om.iVerifyStateNew = 2
 | 
	
		
			
				|  |  | -		AND omi.cInvCcode LIKE '19%'
 | 
	
		
			
				|  |  | -		AND om.cCode LIKE CONCAT(#{code},'%')
 | 
	
		
			
				|  |  | -	GROUP BY om.ccode,ot.cInvCode,od.isosid,om.ccode,oti.cInvName) AS t1
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		left join (
 | 
	
		
			
				|  |  | -		SELECT oti.cinvName,ven.cVenAbbName AS cVenAbbName,bi.cInvCode,SUM ( bi.iSum ) AS rmbAmount,SUM ( bi.iOriSum ) AS usdAmount,
 | 
	
		
			
				|  |  | +		SELECT ven.cVenAbbName AS cVenAbbName,bi.cInvCode,pod.iorderdid as isosid,SUM ( bi.iSum ) AS rmbAmount,SUM ( bi.iOriSum ) AS usdAmount,
 | 
	
		
			
				|  |  |  		SUM ( bi.iMoney ) AS priceExcludingtax,sum ( bi.iCost*bi.iPBVQuantity) AS totalCost ,sum ( bi.iPBVQuantity) AS totalSum
 | 
	
		
			
				|  |  |  		FROM
 | 
	
		
			
				|  |  |  		UFDATA_103_2021.dbo.PO_Pomain pom
 | 
	
	
		
			
				|  | @@ -110,10 +77,11 @@
 | 
	
		
			
				|  |  |  		JOIN UFDATA_103_2021.dbo.Inventory oti ON oti.cInvCode= pod.cInvCode
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		where pom.cPOID like CONCAT(#{code},'%')
 | 
	
		
			
				|  |  | -		GROUP BY oti.cinvName,bi.cInvCode,ven.cVenAbbName
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +		GROUP BY bi.cInvCode,pod.iorderdid,ven.cVenAbbName
 | 
	
		
			
				|  |  |  		) AS t2
 | 
	
		
			
				|  |  | -		on t1.cInvCode= t2.cInvCode
 | 
	
		
			
				|  |  | +		on
 | 
	
		
			
				|  |  | +		t1.cInvCode= t2.cInvCode
 | 
	
		
			
				|  |  | +		AND t2.isosid= t1.isosid
 | 
	
		
			
				|  |  |  		) t3
 | 
	
		
			
				|  |  |  		GROUP BY
 | 
	
		
			
				|  |  |  		t3.ccode,t3.cInvCode,t3.goodsName,t3.cVenAbbName
 | 
	
	
		
			
				|  | @@ -183,7 +151,7 @@
 | 
	
		
			
				|  |  |  		(
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		select t4.cInvCode,max(t4.goodsName) as goodsName,max(t4.dosage) as dosage,max(t4.usageQuantity) as usageQuantity,STRING_AGG(t4.supper,',') as supper,sum(t4.rmbAmount) as rmbAmount,sum(t4.usdAmount) as usdAmount,sum(t4.priceExcludingtax) as priceExcludingtax,sum(t4.cost) as cost from (
 | 
	
		
			
				|  |  | -		select t3.ccode as ccode,t3.cInvCode,t3.goodsName,max(t3.dosage) as dosage,sum(t3.usageQuantity) as usageQuantity,max(t3.cVenAbbName) as supper,sum(t3.rmbAmount) as rmbAmount,sum(t3.usdAmount) as usdAmount,sum(t3.priceExcludingtax) as priceExcludingtax,sum(t3.iCost) as cost from (
 | 
	
		
			
				|  |  | +		select t3.ccode as ccode,t3.cInvCode,t3.goodsName,avg(t3.dosage) as dosage,sum(t3.usageQuantity) as usageQuantity,max(t3.cVenAbbName) as supper,sum(t3.rmbAmount) as rmbAmount,sum(t3.usdAmount) as usdAmount,sum(t3.priceExcludingtax) as priceExcludingtax,sum(t3.iCost) as cost from (
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		select t1.ccode as ccode,t1.cInvCode,t1.goodsName,t1.dosage,t1.usageQuantity,t2.cVenAbbName,t2.rmbAmount,t2.usdAmount,t2.priceExcludingtax,t2.iCost from (select ot.cInvCode,od.isosid,om.ccode,oti.cInvName as goodsName,sum(ot.iUnitQuantity) as dosage,sum(ot.iSendQTY) as usageQuantity
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -214,7 +182,7 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		union all
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -		select t3.ccode,t3.cInvCode,t3.goodsName,max(t3.dosage) as dosage,sum(t3.usageQuantity) as usageQuantity,max(t3.cVenAbbName) as supper,sum(t3.rmbAmount) as rmbAmount,sum(t3.usdAmount) as usdAmount,sum(t3.priceExcludingtax) as priceExcludingtax,sum(t3.iCost) as cost from (
 | 
	
		
			
				|  |  | +		select t3.ccode,t3.cInvCode,t3.goodsName,avg(t3.dosage) as dosage,sum(t3.usageQuantity) as usageQuantity,max(t3.cVenAbbName) as supper,sum(t3.rmbAmount) as rmbAmount,sum(t3.usdAmount) as usdAmount,sum(t3.priceExcludingtax) as priceExcludingtax,sum(t3.iCost) as cost from (
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		select t1.ccode,t1.cInvCode,t1.goodsName,t1.dosage,t1.usageQuantity,t2.cVenAbbName,t2.rmbAmount,t2.usdAmount,t2.priceExcludingtax,t2.iCost from (select ot.cInvCode,od.isosid,om.ccode,oti.cInvName as goodsName,sum(ot.iUnitQuantity) as dosage,sum(ot.iSendQTY) as usageQuantity
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -248,7 +216,7 @@
 | 
	
		
			
				|  |  |  		) t3  GROUP BY t3.ccode,t3.cInvCode,t3.goodsName
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		union all
 | 
	
		
			
				|  |  | -		select t3.ccode,t3.cInvCode,t3.goodsName,max(t3.dosage) as dosage,sum(t3.usageQuantity) as usageQuantity,max(t3.cVenAbbName) as supper,sum(t3.rmbAmount) as rmbAmount,sum(t3.usdAmount) as usdAmount,sum(t3.priceExcludingtax) as priceExcludingtax,sum(t3.iCost) as cost from (
 | 
	
		
			
				|  |  | +		select t3.ccode,t3.cInvCode,t3.goodsName,avg(t3.dosage) as dosage,sum(t3.usageQuantity) as usageQuantity,max(t3.cVenAbbName) as supper,sum(t3.rmbAmount) as rmbAmount,sum(t3.usdAmount) as usdAmount,sum(t3.priceExcludingtax) as priceExcludingtax,sum(t3.iCost) as cost from (
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		select t1.ccode,t1.cInvCode,t1.goodsName,t1.dosage,t1.usageQuantity,t2.cVenAbbName,t2.rmbAmount,t2.usdAmount,t2.priceExcludingtax,t2.iCost from (select ot.cInvCode,od.isosid,om.ccode,oti.cInvName as goodsName,sum(ot.iUnitQuantity) as dosage,sum(ot.iSendQTY) as usageQuantity
 | 
	
		
			
				|  |  |  
 |