|  | @@ -17,9 +17,9 @@
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	<select id="queryByCostShipdetail" resultType="org.jeecg.modules.cost.entity.SyCostAllocationShipdetail">
 | 
	
		
			
				|  |  | -	select t.* from (
 | 
	
		
			
				|  |  | -					select sbv.cDefine10 AS invoiceNum,CONVERT(varchar(50), min(sbv.dDate), 23) as outdata,sum(pbv.iQuantity) as shipQuantity,pbv.cExchRate AS exchangeRate,sbv.cSOCode AS orderNum,max(pbv.cdefine22) AS poStyleNum,max(pbv.cDefine28) AS smallPo,max(sbv.exportUnitPrice) AS exportUnitPrice,sum(sbv.exportPrice) as exportPrice,sum(sbv.rmbAmount) as rmbAmount,
 | 
	
		
			
				|  |  | -case when max(sbv.cexch_name)='人民币' then max(pbv.iOriTaxCost) else round(max(pbv.iOriTaxCost)*pbv.cExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | +select t.* from (
 | 
	
		
			
				|  |  | +					select sbv.cDefine10 AS invoiceNum,CONVERT(varchar(50), min(sbv.dDate), 23) as outdata,sum(pbv.iQuantity) as shipQuantity,sbv.iExchRate AS exchangeRate,sbv.cSOCode AS orderNum,max(pbv.cdefine22) AS poStyleNum,max(pbv.cDefine28) AS smallPo,max(sbv.exportUnitPrice) AS exportUnitPrice,sum(sbv.exportPrice) as exportPrice,sum(sbv.rmbAmount) as rmbAmount,
 | 
	
		
			
				|  |  | +case when max(sbv.cexch_name)='人民币' then max(pbv.iOriTaxCost) else round(max(pbv.iOriTaxCost)*max(pbv.cExchRate),4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  |  			case when max(sbv.cexch_name)='人民币' then 0 else max(pbv.iOriTaxCost) end as procesUnitPriceusd,
 | 
	
		
			
				|  |  |  		sum(pbv.processCost) as processCost,
 | 
	
		
			
				|  |  |  			case when max(sbv.cexch_name)='人民币' then 0 else max(pbv.iOriTaxCost) end * sum(pbv.iQuantity) as processCostUsd,
 | 
	
	
		
			
				|  | @@ -42,7 +42,7 @@ from UFDATA_101_2021.dbo.SaleBillVouchs sbvs  left join UFDATA_101_2021.dbo.Sale
 | 
	
		
			
				|  |  |  group by  sbv.cDefine10,sbvs.cInvCode,sbvs.cFree1,sbvs.cFree2,sbv.cSOCode
 | 
	
		
			
				|  |  |  ) as sbv on sbv.cInvCode=pbv.cInvCode and sbv.cFree1=pbv.cFree1 and sbv.cFree2=pbv.cFree2 and pbv.iQuantity=sbv.iQuantity -- 自由项+合计数量做匹配
 | 
	
		
			
				|  |  |  LEFT JOIN UFDATA_101_2021.dbo.Vendor v ON pbv.cVenCode= v.cVenCode
 | 
	
		
			
				|  |  | -GROUP BY sbv.cDefine10,pbv.cExchRate,sbv.cSOCode
 | 
	
		
			
				|  |  | +GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		 union all
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -50,16 +50,16 @@ GROUP BY sbv.cDefine10,pbv.cExchRate,sbv.cSOCode
 | 
	
		
			
				|  |  |  			sh.cDefine10 AS invoiceNum,
 | 
	
		
			
				|  |  |  			CONVERT(varchar(50), min(sh.dDate), 23) as outdata ,
 | 
	
		
			
				|  |  |  		  sum(shs.iQuantity) as shipQuantity,
 | 
	
		
			
				|  |  | -			so.cExchRate AS exchangeRate,
 | 
	
		
			
				|  |  | +			sh.iExchRate AS exchangeRate,
 | 
	
		
			
				|  |  |  			sh.cSOCode AS orderNum,
 | 
	
		
			
				|  |  |  			max(so.cdefine22) AS poStyleNum,
 | 
	
		
			
				|  |  |  			max(so.cDefine28) AS smallPo,
 | 
	
		
			
				|  |  |  			max(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  |  			sum(shs.iSum) as exportPrice,
 | 
	
		
			
				|  |  |  			sum(iNatSum) as rmbAmount,
 | 
	
		
			
				|  |  | -			case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*so.cExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | +			case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*max(so.cExchRate),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)*so.cExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | +				case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*max(so.cExchRate),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
 | 
	
	
		
			
				|  | @@ -100,7 +100,7 @@ GROUP BY sbv.cDefine10,pbv.cExchRate,sbv.cSOCode
 | 
	
		
			
				|  |  |  						GROUP BY s.iSOsID
 | 
	
		
			
				|  |  |  			) so ON so.iSOsID = rd.iorderdid
 | 
	
		
			
				|  |  |  		LEFT JOIN UFDATA_102_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | -		group by sh.cDefine10,so.cExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  | +		group by sh.cDefine10,sh.iExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		union all
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -108,17 +108,17 @@ GROUP BY sbv.cDefine10,pbv.cExchRate,sbv.cSOCode
 | 
	
		
			
				|  |  |  		sh.cDefine10 AS invoiceNum,
 | 
	
		
			
				|  |  |  		CONVERT(varchar(50), min(sh.dDate), 23) as outdata ,
 | 
	
		
			
				|  |  |  	  sum(shs.iQuantity) as shipQuantity,
 | 
	
		
			
				|  |  | -		so.cExchRate AS exchangeRate,
 | 
	
		
			
				|  |  | +		sh.iExchRate AS exchangeRate,
 | 
	
		
			
				|  |  |  		sh.cSOCode AS orderNum,
 | 
	
		
			
				|  |  |  		max(so.cdefine22) AS poStyleNum,
 | 
	
		
			
				|  |  |  		max(so.cDefine28) AS smallPo,
 | 
	
		
			
				|  |  |  		max(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  |  		sum(shs.iSum) as exportPrice,
 | 
	
		
			
				|  |  |  		sum(iNatSum) as rmbAmount,
 | 
	
		
			
				|  |  | -		case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*so.cExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | +		case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*max(so.cExchRate),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)*so.cExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | +		case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*max(so.cExchRate),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
 | 
	
	
		
			
				|  | @@ -155,11 +155,11 @@ GROUP BY sbv.cDefine10,pbv.cExchRate,sbv.cSOCode
 | 
	
		
			
				|  |  |  						inner join UFDATA_101_2021.dbo.po_podetails g on g.POID=f.POID and g.ivouchrowno=a.iRowNo
 | 
	
		
			
				|  |  |  						inner join UFDATA_101_2021.dbo.SO_SODetails s on s.iSOsID=g.iorderdid
 | 
	
		
			
				|  |  |  						inner join UFDATA_101_2021.dbo.so_somain ss on ss.id=s.id
 | 
	
		
			
				|  |  | -						WHERE b.cCusCode in ('T020001','0001') and ss.cCusCode not in ('T020001','0001') and c.cInvCcode like '19%'
 | 
	
		
			
				|  |  | +						WHERE b.cCusCode in ('T020001') and ss.cCusCode not in ('T020001','0001') and c.cInvCcode like '19%'
 | 
	
		
			
				|  |  |  						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,so.cExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  | +		group by sh.cDefine10,sh.iExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		
 | 
	
		
			
				|  |  |  UNION ALL
 | 
	
	
		
			
				|  | @@ -168,17 +168,17 @@ UNION ALL
 | 
	
		
			
				|  |  |  		sh.cDefine10 AS invoiceNum,
 | 
	
		
			
				|  |  |  		CONVERT(varchar(50), min(sh.dDate), 23) as outdata ,
 | 
	
		
			
				|  |  |  	  sum(shs.iQuantity) as shipQuantity,
 | 
	
		
			
				|  |  | -		so.cExchRate AS exchangeRate,
 | 
	
		
			
				|  |  | +		sh.iExchRate AS exchangeRate,
 | 
	
		
			
				|  |  |  		sh.cSOCode AS orderNum,
 | 
	
		
			
				|  |  |  		max(so.cdefine22) AS poStyleNum,
 | 
	
		
			
				|  |  |  		max(so.cDefine28) AS smallPo,
 | 
	
		
			
				|  |  |  		max(shs.iTaxUnitPrice) AS exportUnitPrice ,
 | 
	
		
			
				|  |  |  		sum(shs.iSum) as exportPrice,
 | 
	
		
			
				|  |  |  		sum(iNatSum) as rmbAmount,
 | 
	
		
			
				|  |  | -		case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*so.cExchRate,4) end as procesUnitPricermb,
 | 
	
		
			
				|  |  | +		case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*max(so.cExchRate),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)*so.cExchRate,4) end * sum(shs.iQuantity) as processCost,
 | 
	
		
			
				|  |  | +		case when max(so.cexch)='人民币' then max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*max(so.cExchRate),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
 | 
	
	
		
			
				|  | @@ -219,14 +219,14 @@ UNION ALL
 | 
	
		
			
				|  |  |  						inner join UFDATA_101_2021.dbo.po_podetails g1 on g1.POID=f1.POID and g.ivouchrowno=a.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%'
 | 
	
		
			
				|  |  | +						WHERE b.cCusCode in ('0001') and ss.cCusCode in ('T020001') and c.cInvCcode like '19%'
 | 
	
		
			
				|  |  | +				
 | 
	
		
			
				|  |  |  						GROUP BY s1.iSOsID
 | 
	
		
			
				|  |  |  			) so ON so.iSOsID = rd.iorderdid
 | 
	
		
			
				|  |  |  		LEFT JOIN UFDATA_101_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | -		group by sh.cDefine10,so.cExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  | +		group by sh.cDefine10,sh.iExchRate,sh.cSOCode,c.cInvName, v.cVenName
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  		 ) t order by t.outdata
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  </mapper>
 |