| 
														
															@@ -18,22 +18,23 @@ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	<select id="queryByCostShipdetail" resultType="org.jeecg.modules.cost.entity.SyCostAllocationShipdetail"> 
														 | 
														
														 | 
														
															 	<select id="queryByCostShipdetail" resultType="org.jeecg.modules.cost.entity.SyCostAllocationShipdetail"> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	select t.* from ( 
														 | 
														
														 | 
														
															 	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)*sbv.iExchRate,4) end as procesUnitPricermb, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					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, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			case when max(sbv.cexch_name)='人民币' then 0 else max(pbv.iOriTaxCost) end as procesUnitPriceusd, 
														 | 
														
														 | 
														
															 			case when max(sbv.cexch_name)='人民币' then 0 else max(pbv.iOriTaxCost) end as procesUnitPriceusd, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				case when max(sbv.cexch_name)='人民币' then max(pbv.iOriTaxCost) else round(max(pbv.iOriTaxCost)*sbv.iExchRate,4) end * sum(pbv.iQuantity) as processCost, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		sum(pbv.processCost) as processCost, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			case when max(sbv.cexch_name)='人民币' then 0 else max(pbv.iOriTaxCost) end * sum(pbv.iQuantity) as processCostUsd, 
														 | 
														
														 | 
														
															 			case when max(sbv.cexch_name)='人民币' then 0 else max(pbv.iOriTaxCost) end * sum(pbv.iQuantity) as processCostUsd, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			max(v.cVenName) AS processUnit 
														 | 
														
														 | 
														
															 			max(v.cVenName) AS processUnit 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 from 
														 | 
														
														 | 
														
															 from 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-(select pbv.cDefine10,pbvs.cInvCode,pbvs.cFree1,pbvs.cFree2,pbv.cBusType,sum(pbvs.iPBVQuantity) as iQuantity,ommo.ccode,max(sd.cdefine22) as cdefine22,max(sd.cdefine28) as cdefine28,max(pbvs.iOriTaxCost) as iOriTaxCost,ommo.cVenCode as cVenCode 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+(select pbv.cDefine10,pbvs.cInvCode,pbvs.cFree1,pbvs.cFree2,pbv.cBusType,sum(pbvs.iPBVQuantity) as iQuantity,ommo.ccode,max(sd.cdefine22) as cdefine22,max(sd.cdefine28) as cdefine28,max(pbvs.iOriTaxCost) as iOriTaxCost,ommo.cVenCode as cVenCode,max(pbv.cExchRate) as cExchRate,sum(pbvs.iSum) as processCost 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 from UFDATA_101_2021.dbo.PurBillVouchs pbvs left join UFDATA_101_2021.dbo.PurBillVouch pbv 
														 | 
														
														 | 
														
															 from UFDATA_101_2021.dbo.PurBillVouchs pbvs left join UFDATA_101_2021.dbo.PurBillVouch pbv 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 on pbv.PBVID=pbvs.PBVID 
														 | 
														
														 | 
														
															 on pbv.PBVID=pbvs.PBVID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 left join UFDATA_101_2021.dbo.OM_MODetails ommos on ommos.MODetailsID=pbvs.iPOsID 
														 | 
														
														 | 
														
															 left join UFDATA_101_2021.dbo.OM_MODetails ommos on ommos.MODetailsID=pbvs.iPOsID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 left join UFDATA_101_2021.dbo.om_momain ommo on ommo.moid=ommos.moid 
														 | 
														
														 | 
														
															 left join UFDATA_101_2021.dbo.om_momain ommo on ommo.moid=ommos.moid 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 left join UFDATA_101_2021.dbo.SO_SODetails sd on sd.iSOsID = ommos.isosid 
														 | 
														
														 | 
														
															 left join UFDATA_101_2021.dbo.SO_SODetails sd on sd.iSOsID = ommos.isosid 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-group by pbv.cDefine10,pbvs.cInvCode,pbvs.cFree1,pbvs.cFree2,pbv.cBusType,ommo.ccode,ommo.cVenCode 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-having ommo.ccode like CONCAT(#{code},'%') AND pbv.cBusType='委外加工') as pbv 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	left join UFDATA_101_2021.dbo.Inventory inv on pbvs.cInvCode = inv.cInvCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+group by pbv.cDefine10,pbvs.cInvCode,pbvs.cFree1,pbvs.cFree2,pbv.cBusType,inv.cInvCCode,ommo.ccode,ommo.cVenCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+having ommo.ccode like CONCAT(#{code},'%') AND pbv.cBusType='委外加工' and inv.cInvCCode like '19%') as pbv 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 left join 
														 | 
														
														 | 
														
															 left join 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 -- 根据外销发票号 加物料编码以及自由项组合计算 销售发票合计数量 
														 | 
														
														 | 
														
															 -- 根据外销发票号 加物料编码以及自由项组合计算 销售发票合计数量 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 (select sbv.cDefine10,sum(sbvs.iQuantity) as iQuantity,sbvs.cInvCode,sbvs.cFree1,sbvs.cFree2,min(sbv.dDate) as dDate,max(sbv.iExchRate) as iExchRate,sbv.cSOCode as cSOCode,max(sbvs.iTaxUnitPrice) AS exportUnitPrice,sum(sbvs.iSum) as exportPrice,sum(sbvs.iNatSum) as rmbAmount,max(sbv.cexch_name) as cexch_name 
														 | 
														
														 | 
														
															 (select sbv.cDefine10,sum(sbvs.iQuantity) as iQuantity,sbvs.cInvCode,sbvs.cFree1,sbvs.cFree2,min(sbv.dDate) as dDate,max(sbv.iExchRate) as iExchRate,sbv.cSOCode as cSOCode,max(sbvs.iTaxUnitPrice) AS exportUnitPrice,sum(sbvs.iSum) as exportPrice,sum(sbvs.iNatSum) as rmbAmount,max(sbv.cexch_name) as cexch_name 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -41,24 +42,24 @@ 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 
														 | 
														
														 | 
														
															 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 -- 自由项+合计数量做匹配 
														 | 
														
														 | 
														
															 ) 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 
														 | 
														
														 | 
														
															 LEFT JOIN UFDATA_101_2021.dbo.Vendor v ON pbv.cVenCode= v.cVenCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+GROUP BY sbv.cDefine10,pbv.cExchRate,sbv.cSOCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		 union all 
														 | 
														
														 | 
														
															 		 union all 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		 SELECT 
														 | 
														
														 | 
														
															 		 SELECT 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			sh.cDefine10 AS invoiceNum, 
														 | 
														
														 | 
														
															 			sh.cDefine10 AS invoiceNum, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			CONVERT(varchar(50), min(sh.dDate), 23) as outdata , 
														 | 
														
														 | 
														
															 			CONVERT(varchar(50), min(sh.dDate), 23) as outdata , 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			sum(shs.iQuantity) as shipQuantity, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			sh.iExchRate AS exchangeRate, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		  sum(shs.iQuantity) as shipQuantity, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			so.cExchRate AS exchangeRate, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			sh.cSOCode AS orderNum, 
														 | 
														
														 | 
														
															 			sh.cSOCode AS orderNum, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			max(so.cdefine22) AS poStyleNum, 
														 | 
														
														 | 
														
															 			max(so.cdefine22) AS poStyleNum, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			max(so.cDefine28) AS smallPo, 
														 | 
														
														 | 
														
															 			max(so.cDefine28) AS smallPo, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			max(shs.iTaxUnitPrice) AS exportUnitPrice , 
														 | 
														
														 | 
														
															 			max(shs.iTaxUnitPrice) AS exportUnitPrice , 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			sum(shs.iSum) as exportPrice, 
														 | 
														
														 | 
														
															 			sum(shs.iSum) as exportPrice, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			sum(iNatSum) as rmbAmount, 
														 | 
														
														 | 
														
															 			sum(iNatSum) as rmbAmount, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			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 max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*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 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 max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*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, 
														 | 
														
														 | 
														
															 			case when max(so.cexch)='人民币' then 0 else max(so.iOriTaxCost) end * sum(shs.iQuantity) as processCostUsd, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			v.cVenName AS processUnit 
														 | 
														
														 | 
														
															 			v.cVenName AS processUnit 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		FROM 
														 | 
														
														 | 
														
															 		FROM 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -67,12 +68,14 @@ GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			LEFT JOIN UFDATA_102_2021.dbo.Inventory c ON c.cInvCode= shs.cInvCode 
														 | 
														
														 | 
														
															 			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 
														 | 
														
														 | 
														
															 			LEFT JOIN UFDATA_102_2021.dbo.rdrecords32 rd ON rd.AutoID = shs.isaleoutid 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		JOIN ( 
														 | 
														
														 | 
														
															 		JOIN ( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			 SELECT  max(supplierCode) as supplierCode,s.iSOsID,max(o.iOriTaxCost) as iOriTaxCost,max(o.cexch) as cexch, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			 SELECT max(o.cExchRate) as cExchRate,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 
														 | 
														
														 | 
														
															 					max(o.iNatUnitPrice) as iNatUnitPrice,max(s.cdefine22) as cdefine22,max(s.cDefine28) as cDefine28 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						FROM  UFDATA_103_2021.dbo.SO_SODetails a 
														 | 
														
														 | 
														
															 						FROM  UFDATA_103_2021.dbo.SO_SODetails a 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID 
														 | 
														
														 | 
														
															 						inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						inner JOIN ( 
														 | 
														
														 | 
														
															 						inner JOIN ( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 SELECT max(om.cexch_name) as cexch, 
														 | 
														
														 | 
														
															 									 SELECT max(om.cexch_name) as cexch, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									 max(pb.cExchRate) as cExchRate, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 od.csoordercode as csoordercode, 
														 | 
														
														 | 
														
															 									 od.csoordercode as csoordercode, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 max(om.cVenCode) AS supplierCode,max(od.cInvCode) as cInvCode,max(od.isosid) as isosid,sum(od.iQuantity) as iQuantity , 
														 | 
														
														 | 
														
															 									 max(om.cVenCode) AS supplierCode,max(od.cInvCode) as cInvCode,max(od.isosid) as isosid,sum(od.iQuantity) as iQuantity , 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 max(bi.iOriTaxCost) as iOriTaxCost,max(od.iNatUnitPrice) as iNatUnitPrice 
														 | 
														
														 | 
														
															 									 max(bi.iOriTaxCost) as iOriTaxCost,max(od.iNatUnitPrice) as iNatUnitPrice 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -80,8 +83,10 @@ GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 UFDATA_103_2021.dbo.OM_MOMain om 
														 | 
														
														 | 
														
															 									 UFDATA_103_2021.dbo.OM_MOMain om 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID 
														 | 
														
														 | 
														
															 									 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 
														 | 
														
														 | 
														
															 									 left join UFDATA_103_2021.dbo.PurBillVouchs bi  on bi.iPOsID=od.MODetailsID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									 left join UFDATA_103_2021.dbo.PurBillVouch pb  on bi.PBVID =pb.PBVID  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									 	left join UFDATA_103_2021.dbo.Inventory inv on bi.cInvCode = inv.cInvCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 WHERE 
														 | 
														
														 | 
														
															 									 WHERE 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-									 om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and om.cCode like CONCAT(#{code},'%')  
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									 om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and om.cCode like CONCAT(#{code},'%') and inv.cInvCCode like '19%' 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 GROUP BY od.csoordercode 
														 | 
														
														 | 
														
															 									 GROUP BY od.csoordercode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 ) o ON a.csocode = o.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.Vendor v ON o.supplierCode= v.cVenCode 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -95,25 +100,25 @@ GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						GROUP BY s.iSOsID 
														 | 
														
														 | 
														
															 						GROUP BY s.iSOsID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			) so ON so.iSOsID = rd.iorderdid 
														 | 
														
														 | 
														
															 			) so ON so.iSOsID = rd.iorderdid 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		LEFT JOIN UFDATA_102_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode 
														 | 
														
														 | 
														
															 		LEFT JOIN UFDATA_102_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		group by sh.cDefine10,sh.iExchRate,sh.cSOCode,c.cInvName, v.cVenName 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		group by sh.cDefine10,so.cExchRate,sh.cSOCode,c.cInvName, v.cVenName 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		union all 
														 | 
														
														 | 
														
															 		union all 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		SELECT 
														 | 
														
														 | 
														
															 		SELECT 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sh.cDefine10 AS invoiceNum, 
														 | 
														
														 | 
														
															 		sh.cDefine10 AS invoiceNum, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		CONVERT(varchar(50), min(sh.dDate), 23) as outdata , 
														 | 
														
														 | 
														
															 		CONVERT(varchar(50), min(sh.dDate), 23) as outdata , 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		sum(shs.iQuantity) as shipQuantity, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		sh.iExchRate AS exchangeRate, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	  sum(shs.iQuantity) as shipQuantity, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		so.cExchRate AS exchangeRate, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sh.cSOCode AS orderNum, 
														 | 
														
														 | 
														
															 		sh.cSOCode AS orderNum, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		max(so.cdefine22) AS poStyleNum, 
														 | 
														
														 | 
														
															 		max(so.cdefine22) AS poStyleNum, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		max(so.cDefine28) AS smallPo, 
														 | 
														
														 | 
														
															 		max(so.cDefine28) AS smallPo, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		max(shs.iTaxUnitPrice) AS exportUnitPrice , 
														 | 
														
														 | 
														
															 		max(shs.iTaxUnitPrice) AS exportUnitPrice , 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sum(shs.iSum) as exportPrice, 
														 | 
														
														 | 
														
															 		sum(shs.iSum) as exportPrice, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sum(iNatSum) as rmbAmount, 
														 | 
														
														 | 
														
															 		sum(iNatSum) as rmbAmount, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		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 max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*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 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 max(so.iOriTaxCost) else round(max(so.iOriTaxCost)*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, 
														 | 
														
														 | 
														
															 		case when max(so.cexch)='人民币' then 0 else max(so.iOriTaxCost) end * sum(shs.iQuantity) as processCostUsd, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		v.cVenName AS processUnit 
														 | 
														
														 | 
														
															 		v.cVenName AS processUnit 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		 FROM 
														 | 
														
														 | 
														
															 		 FROM 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -122,12 +127,14 @@ GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			LEFT JOIN UFDATA_101_2021.dbo.Inventory c ON c.cInvCode= shs.cInvCode 
														 | 
														
														 | 
														
															 			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 
														 | 
														
														 | 
														
															 			LEFT JOIN UFDATA_101_2021.dbo.rdrecords32 rd ON rd.AutoID = shs.isaleoutid 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		  JOIN ( 
														 | 
														
														 | 
														
															 		  JOIN ( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			 SELECT  max(supplierCode) as supplierCode,s.iSOsID,max(o.iOriTaxCost) as iOriTaxCost,max(o.cexch) as cexch, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			 SELECT max(o.cExchRate) as cExchRate,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 
														 | 
														
														 | 
														
															 					max(o.iNatUnitPrice) as iNatUnitPrice,max(s.cdefine22) as cdefine22,max(s.cDefine28) as cDefine28 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						FROM  UFDATA_103_2021.dbo.SO_SODetails a 
														 | 
														
														 | 
														
															 						FROM  UFDATA_103_2021.dbo.SO_SODetails a 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID 
														 | 
														
														 | 
														
															 						inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						inner JOIN ( 
														 | 
														
														 | 
														
															 						inner JOIN ( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 SELECT max(om.cexch_name) as cexch, 
														 | 
														
														 | 
														
															 									 SELECT max(om.cexch_name) as cexch, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									 max(pb.cExchRate) as cExchRate, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 od.csoordercode as csoordercode, 
														 | 
														
														 | 
														
															 									 od.csoordercode as csoordercode, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 max(om.cVenCode) AS supplierCode,max(od.cInvCode) as cInvCode,max(od.isosid) as isosid,sum(od.iQuantity) as iQuantity , 
														 | 
														
														 | 
														
															 									 max(om.cVenCode) AS supplierCode,max(od.cInvCode) as cInvCode,max(od.isosid) as isosid,sum(od.iQuantity) as iQuantity , 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 max(bi.iOriTaxCost) as iOriTaxCost,max(od.iNatUnitPrice) as iNatUnitPrice 
														 | 
														
														 | 
														
															 									 max(bi.iOriTaxCost) as iOriTaxCost,max(od.iNatUnitPrice) as iNatUnitPrice 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -135,8 +142,10 @@ GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 UFDATA_103_2021.dbo.OM_MOMain om 
														 | 
														
														 | 
														
															 									 UFDATA_103_2021.dbo.OM_MOMain om 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID 
														 | 
														
														 | 
														
															 									 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 
														 | 
														
														 | 
														
															 									 left join UFDATA_103_2021.dbo.PurBillVouchs bi  on bi.iPOsID=od.MODetailsID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									  left join UFDATA_103_2021.dbo.PurBillVouch pb  on bi.PBVID =pb.PBVID  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+										left join UFDATA_103_2021.dbo.Inventory inv on bi.cInvCode = inv.cInvCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 WHERE 
														 | 
														
														 | 
														
															 									 WHERE 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-									 om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and om.cCode like CONCAT(#{code},'%')  
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+									 om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and om.cCode like CONCAT(#{code},'%') and inv.cInvCCode like '19%' 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 GROUP BY od.csoordercode 
														 | 
														
														 | 
														
															 									 GROUP BY od.csoordercode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 									 ) o ON a.csocode = o.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.Vendor v ON o.supplierCode= v.cVenCode 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -150,7 +159,7 @@ GROUP BY sbv.cDefine10,sbv.iExchRate,sbv.cSOCode 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						GROUP BY s.iSOsID 
														 | 
														
														 | 
														
															 						GROUP BY s.iSOsID 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			) so ON so.iSOsID = rd.iorderdid 
														 | 
														
														 | 
														
															 			) so ON so.iSOsID = rd.iorderdid 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		LEFT JOIN UFDATA_101_2021.dbo.Vendor v ON so.supplierCode= v.cVenCode 
														 | 
														
														 | 
														
															 		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 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		group by sh.cDefine10,so.cExchRate,sh.cSOCode,c.cInvName, v.cVenName 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		 ) t order by t.outdata 
														 | 
														
														 | 
														
															 		 ) t order by t.outdata 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 |