|  | @@ -26,13 +26,13 @@
 | 
	
		
			
				|  |  |  			sh.cSOCode AS orderNum,
 | 
	
		
			
				|  |  |  			max(so.cdefine22) AS poStyleNum,
 | 
	
		
			
				|  |  |  			max(so.cDefine28) AS smallPo,
 | 
	
		
			
				|  |  | -			avg(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  | +			max(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  |  			sum(shs.iSum) as exportPrice,
 | 
	
		
			
				|  |  |  			sum(iNatSum) as rmbAmount,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then avg(so.procesUnitPriceusd) else round(avg(so.procesUnitPriceusd)*sh.iExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then 0 else avg(so.procesUnitPriceusd) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  | -				case when max(so.cexch)='人民币' then avg(so.procesUnitPriceusd) else round(avg(so.procesUnitPriceusd)*sh.iExchRate,4) end* sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then 0 else avg(so.procesUnitPriceusd) end * sum(shs.iQuantity) as processCostUsd,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then max(so.procesUnitPriceusd) else round(max(so.procesUnitPriceusd)*sh.iExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then 0 else max(so.procesUnitPriceusd) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  | +				case when max(so.cexch)='人民币' then max(so.procesUnitPriceusd) else round(max(so.procesUnitPriceusd)*sh.iExchRate,4) end* sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then 0 else max(so.procesUnitPriceusd) end * sum(shs.iQuantity) as processCostUsd,
 | 
	
		
			
				|  |  |  			v.cVenName AS processUnit
 | 
	
		
			
				|  |  |  		 FROM
 | 
	
		
			
				|  |  |  			UFDATA_101_2021.dbo.SaleBillVouch sh
 | 
	
	
		
			
				|  | @@ -49,10 +49,10 @@
 | 
	
		
			
				|  |  |  					FROM UFDATA_101_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  |  					LEFT JOIN UFDATA_101_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
		
			
				|  |  |  					left join UFDATA_101_2021.dbo.PurBillVouchs bi  on bi.iPOsID=od.MODetailsID
 | 
	
		
			
				|  |  | -					WHERE om.iVerifyStateNew = 2 AND om.cCode like CONCAT(#{code},'%') 
 | 
	
		
			
				|  |  | +					WHERE om.iVerifyStateNew = 2 AND om.cCode like CONCAT(#{code},'%')
 | 
	
		
			
				|  |  |  					GROUP BY od.csoordercode
 | 
	
		
			
				|  |  | -				) o ON s.csocode = o.csoordercode 
 | 
	
		
			
				|  |  | -			) so ON so.iSOsID = shs.iSOsID 
 | 
	
		
			
				|  |  | +				) o ON s.csocode = o.csoordercode
 | 
	
		
			
				|  |  | +			) so ON so.iSOsID = shs.iSOsID
 | 
	
		
			
				|  |  |  		 LEFT JOIN UFDATA_101_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  |  		 group by sh.cDefine10,sh.iExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -67,13 +67,13 @@
 | 
	
		
			
				|  |  |  			sh.cSOCode AS orderNum,
 | 
	
		
			
				|  |  |  			max(so.cdefine22) AS poStyleNum,
 | 
	
		
			
				|  |  |  			max(so.cDefine28) AS smallPo,
 | 
	
		
			
				|  |  | -			avg(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  | +			max(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  |  			sum(shs.iSum) as exportPrice,
 | 
	
		
			
				|  |  |  			sum(iNatSum) as rmbAmount,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then avg(so.iOriTaxCost) else round(avg(so.iOriTaxCost)*sh.iExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then 0 else avg(so.iOriTaxCost) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  | -				case when max(so.cexch)='人民币' then avg(so.iOriTaxCost) else round(avg(so.iOriTaxCost)*sh.iExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then 0 else avg(so.iOriTaxCost) end * sum(shs.iQuantity) as processCostUsd,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*sh.iExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then 0 else max(so.iOriTaxCost) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  | +				case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*sh.iExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then 0 else max(so.iOriTaxCost) end * sum(shs.iQuantity) as processCostUsd,
 | 
	
		
			
				|  |  |  			v.cVenName AS processUnit
 | 
	
		
			
				|  |  |  		FROM
 | 
	
		
			
				|  |  |  			UFDATA_102_2021.dbo.SaleBillVouch sh
 | 
	
	
		
			
				|  | @@ -81,15 +81,15 @@
 | 
	
		
			
				|  |  |  			LEFT JOIN UFDATA_102_2021.dbo.Inventory c ON c.cInvCode= shs.cInvCode
 | 
	
		
			
				|  |  |  			LEFT JOIN UFDATA_102_2021.dbo.rdrecords32 rd ON rd.AutoID = shs.isaleoutid
 | 
	
		
			
				|  |  |  		JOIN (
 | 
	
		
			
				|  |  | -			 SELECT  max(supplierCode) as supplierCode,s.iSOsID,avg(o.iOriTaxCost) as iOriTaxCost,max(o.cexch) as cexch,
 | 
	
		
			
				|  |  | -					avg(o.iNatUnitPrice) as iNatUnitPrice,max(s.cdefine22) as cdefine22,max(s.cDefine28) as cDefine28
 | 
	
		
			
				|  |  | +			 SELECT  max(supplierCode) as supplierCode,s.iSOsID,max(o.iOriTaxCost) as iOriTaxCost,max(o.cexch) as cexch,
 | 
	
		
			
				|  |  | +					max(o.iNatUnitPrice) as iNatUnitPrice,max(s.cdefine22) as cdefine22,max(s.cDefine28) as cDefine28
 | 
	
		
			
				|  |  |  						FROM  UFDATA_103_2021.dbo.SO_SODetails a
 | 
	
		
			
				|  |  |  						inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID
 | 
	
		
			
				|  |  |  						inner JOIN (
 | 
	
		
			
				|  |  |  									 SELECT max(om.cexch_name) as cexch,
 | 
	
		
			
				|  |  |  									 od.csoordercode as csoordercode,
 | 
	
		
			
				|  |  |  									 max(om.cVenCode) AS supplierCode,max(od.cInvCode) as cInvCode,max(od.isosid) as isosid,sum(od.iQuantity) as iQuantity ,
 | 
	
		
			
				|  |  | -									 avg(bi.iOriTaxCost) as iOriTaxCost,avg(od.iNatUnitPrice) as iNatUnitPrice
 | 
	
		
			
				|  |  | +									 max(bi.iOriTaxCost) as iOriTaxCost,max(od.iNatUnitPrice) as iNatUnitPrice
 | 
	
		
			
				|  |  |  									 FROM
 | 
	
		
			
				|  |  |  									 UFDATA_103_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  |  									 inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
	
		
			
				|  | @@ -121,14 +121,14 @@
 | 
	
		
			
				|  |  |  		sh.cSOCode AS orderNum,
 | 
	
		
			
				|  |  |  		max(so.cdefine22) AS poStyleNum,
 | 
	
		
			
				|  |  |  		max(so.cDefine28) AS smallPo,
 | 
	
		
			
				|  |  | -		avg(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  | +		max(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  |  		sum(shs.iSum) as exportPrice,
 | 
	
		
			
				|  |  |  		sum(iNatSum) as rmbAmount,
 | 
	
		
			
				|  |  | -		case when max(so.cexch)='人民币' then avg(so.iOriTaxCost) else round(avg(so.iOriTaxCost)*sh.iExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | -		case when max(so.cexch)='人民币' then 0 else avg(so.iOriTaxCost) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  | +		case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*sh.iExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | +		case when max(so.cexch)='人民币' then 0 else max(so.iOriTaxCost) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then avg(so.iOriTaxCost) else round(avg(so.iOriTaxCost)*sh.iExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | -		case when max(so.cexch)='人民币' then 0 else avg(so.iOriTaxCost) end * sum(shs.iQuantity) as processCostUsd,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*sh.iExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | +		case when max(so.cexch)='人民币' then 0 else max(so.iOriTaxCost) end * sum(shs.iQuantity) as processCostUsd,
 | 
	
		
			
				|  |  |  		v.cVenName AS processUnit
 | 
	
		
			
				|  |  |  		 FROM
 | 
	
		
			
				|  |  |  			UFDATA_101_2021.dbo.SaleBillVouch sh
 | 
	
	
		
			
				|  | @@ -136,15 +136,15 @@
 | 
	
		
			
				|  |  |  			LEFT JOIN UFDATA_101_2021.dbo.Inventory c ON c.cInvCode= shs.cInvCode
 | 
	
		
			
				|  |  |  			LEFT JOIN UFDATA_101_2021.dbo.rdrecords32 rd ON rd.AutoID = shs.isaleoutid
 | 
	
		
			
				|  |  |  		  JOIN (
 | 
	
		
			
				|  |  | -			 SELECT  max(supplierCode) as supplierCode,s.iSOsID,avg(o.iOriTaxCost) as iOriTaxCost,max(o.cexch) as cexch,
 | 
	
		
			
				|  |  | -					avg(o.iNatUnitPrice) as iNatUnitPrice,max(s.cdefine22) as cdefine22,max(s.cDefine28) as cDefine28
 | 
	
		
			
				|  |  | +			 SELECT  max(supplierCode) as supplierCode,s.iSOsID,max(o.iOriTaxCost) as iOriTaxCost,max(o.cexch) as cexch,
 | 
	
		
			
				|  |  | +					max(o.iNatUnitPrice) as iNatUnitPrice,max(s.cdefine22) as cdefine22,max(s.cDefine28) as cDefine28
 | 
	
		
			
				|  |  |  						FROM  UFDATA_103_2021.dbo.SO_SODetails a
 | 
	
		
			
				|  |  |  						inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID
 | 
	
		
			
				|  |  |  						inner JOIN (
 | 
	
		
			
				|  |  |  									 SELECT max(om.cexch_name) as cexch,
 | 
	
		
			
				|  |  |  									 od.csoordercode as csoordercode,
 | 
	
		
			
				|  |  |  									 max(om.cVenCode) AS supplierCode,max(od.cInvCode) as cInvCode,max(od.isosid) as isosid,sum(od.iQuantity) as iQuantity ,
 | 
	
		
			
				|  |  | -									 avg(bi.iOriTaxCost) as iOriTaxCost,avg(od.iNatUnitPrice) as iNatUnitPrice
 | 
	
		
			
				|  |  | +									 max(bi.iOriTaxCost) as iOriTaxCost,max(od.iNatUnitPrice) as iNatUnitPrice
 | 
	
		
			
				|  |  |  									 FROM
 | 
	
		
			
				|  |  |  									 UFDATA_103_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  |  									 inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
	
		
			
				|  | @@ -164,63 +164,6 @@
 | 
	
		
			
				|  |  |  						GROUP BY s.iSOsID
 | 
	
		
			
				|  |  |  			) so ON so.iSOsID = rd.iorderdid
 | 
	
		
			
				|  |  |  		LEFT JOIN UFDATA_101_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | -		group by sh.cDefine10,sh.iExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  | -		 		UNION ALL
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			 SELECT
 | 
	
		
			
				|  |  | -			sh.cDefine10 AS invoiceNum,
 | 
	
		
			
				|  |  | -			CONVERT(varchar(50), min(sh.dDate), 23) as outdata ,
 | 
	
		
			
				|  |  | -			sum(shs.iQuantity) as shipQuantity,
 | 
	
		
			
				|  |  | -			sh.iExchRate AS exchangeRate,
 | 
	
		
			
				|  |  | -			sh.cSOCode AS orderNum,
 | 
	
		
			
				|  |  | -			max(so.cdefine22) AS poStyleNum,
 | 
	
		
			
				|  |  | -			max(so.cDefine28) AS smallPo,
 | 
	
		
			
				|  |  | -			avg(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  | -			sum(shs.iSum) as exportPrice,
 | 
	
		
			
				|  |  | -			sum(iNatSum) as rmbAmount,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then avg(so.iOriTaxCost) else round(avg(so.iOriTaxCost)*sh.iExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then 0 else avg(so.iOriTaxCost) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  | -				case when max(so.cexch)='人民币' then avg(so.iOriTaxCost) else round(avg(so.iOriTaxCost)*sh.iExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then 0 else avg(so.iOriTaxCost) end * sum(shs.iQuantity) as processCostUsd,
 | 
	
		
			
				|  |  | -			v.cVenName AS processUnit
 | 
	
		
			
				|  |  | -		FROM
 | 
	
		
			
				|  |  | -			UFDATA_101_2021.dbo.SaleBillVouch sh
 | 
	
		
			
				|  |  | -			JOIN UFDATA_101_2021.dbo.SaleBillVouchs shs ON sh.SBVID = shs.SBVID
 | 
	
		
			
				|  |  | -			LEFT JOIN UFDATA_101_2021.dbo.Inventory c ON c.cInvCode= shs.cInvCode
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		JOIN (
 | 
	
		
			
				|  |  | -			 SELECT  max(supplierCode) as supplierCode,s1.iSOsID,avg(o.iOriTaxCost) as iOriTaxCost,max(o.cexch) as cexch,
 | 
	
		
			
				|  |  | -					avg(o.iNatUnitPrice) as iNatUnitPrice,max(s1.cdefine22) as cdefine22,max(s1.cDefine28) as cDefine28
 | 
	
		
			
				|  |  | -						FROM  UFDATA_103_2021.dbo.SO_SODetails a
 | 
	
		
			
				|  |  | -						inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID
 | 
	
		
			
				|  |  | -						inner JOIN (
 | 
	
		
			
				|  |  | -									 SELECT max(om.cexch_name) as cexch,
 | 
	
		
			
				|  |  | -									 od.csoordercode as csoordercode,
 | 
	
		
			
				|  |  | -									 max(om.cVenCode) AS supplierCode,max(od.cInvCode) as cInvCode,max(od.isosid) as isosid,sum(od.iQuantity) as iQuantity ,
 | 
	
		
			
				|  |  | -									 avg(bi.iOriTaxCost) as iOriTaxCost,avg(od.iNatUnitPrice) as iNatUnitPrice
 | 
	
		
			
				|  |  | -									 FROM
 | 
	
		
			
				|  |  | -									 UFDATA_103_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  | -									 inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
		
			
				|  |  | -									 left join UFDATA_103_2021.dbo.PurBillVouchs bi  on bi.iPOsID=od.MODetailsID
 | 
	
		
			
				|  |  | -									 WHERE
 | 
	
		
			
				|  |  | -									 om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and om.cCode like CONCAT(#{code},'%')
 | 
	
		
			
				|  |  | -									 GROUP BY od.csoordercode
 | 
	
		
			
				|  |  | -									 ) o ON a.csocode = o.csoordercode
 | 
	
		
			
				|  |  | -						inner JOIN UFDATA_103_2021.dbo.Vendor v ON o.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | -						inner JOIN UFDATA_103_2021.dbo.Inventory c on c.cInvCode=a.cInvCode
 | 
	
		
			
				|  |  | -						inner JOIN UFDATA_103_2021.dbo.Person  pe ON b.cPersonCode = pe.cPersonCode
 | 
	
		
			
				|  |  | -						inner join UFDATA_102_2021.dbo.PO_Pomain f on f.cPOID=o.csoordercode
 | 
	
		
			
				|  |  | -						inner join UFDATA_102_2021.dbo.po_podetails g on g.POID=f.POID and g.ivouchrowno=a.iRowNo
 | 
	
		
			
				|  |  | -						inner join UFDATA_102_2021.dbo.SO_SODetails s on s.iSOsID=g.iorderdid
 | 
	
		
			
				|  |  | -						inner join UFDATA_102_2021.dbo.so_somain ss on ss.id=s.id
 | 
	
		
			
				|  |  | -						inner join UFDATA_101_2021.dbo.PO_Pomain f1 on f1.cPOID=ss.csocode
 | 
	
		
			
				|  |  | -						inner join UFDATA_101_2021.dbo.po_podetails g1 on g1.POID=f1.POID and g1.ivouchrowno=s.iRowNo
 | 
	
		
			
				|  |  | -						inner join UFDATA_101_2021.dbo.SO_SODetails s1 on s1.iSOsID=g1.iorderdid
 | 
	
		
			
				|  |  | -						inner join UFDATA_101_2021.dbo.so_somain ss1 on ss1.id=s1.id
 | 
	
		
			
				|  |  | -						WHERE b.cCusCode in ('T020001','0001') and ss.cCusCode in ('T020001','0001') and c.cInvCcode like '19%'
 | 
	
		
			
				|  |  | -						GROUP BY s1.iSOsID
 | 
	
		
			
				|  |  | -			) so ON so.iSOsID = shs.iSOsID
 | 
	
		
			
				|  |  | -		LEFT JOIN UFDATA_101_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  |  		group by sh.cDefine10,sh.iExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		 ) t order by t.outdata
 |