zengtx пре 1 година
родитељ
комит
838ba27e28

+ 9 - 8
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/mapper/xml/SyCostAllocationFabricMapper.xml

@@ -117,25 +117,26 @@ where trim(cSOCode) like CONCAT(#{code},'%') and cSOCode not like '%样%'
 		)/tab3.purchaseQuantity,0) as loss
 		from
 		(
-		select vim.cInvCode, max(vim.goodsName) as goodsName,sum(vim.unitConsumption) as unitConsumption,sum(vim.planQuantity) as planQuantity,
-		sum(vim.usageQuantity) as usageQuantity from UFDATA_103_2021.dbo.cost_allocation_fabric_view vif
-		join(
-		select om.cCode as cCode,oti.cInvCode as cInvCode,max(oti.cInvName) as goodsName,sum(ot.iQuantity)/sum(od.iQuantity) as unitConsumption,sum(ot.iQuantity) as planQuantity,
+		select vif.cInvCode, max(vim.goodsName) as goodsName,sum(vim.unitConsumption) as unitConsumption,sum(vim.planQuantity) as planQuantity,
+		sum(vim.usageQuantity) as usageQuantity from (
+		select cInvCode from UFDATA_103_2021.dbo.cost_allocation_fabric_view
+		where trim(cCode) like CONCAT(#{code},'%')
+		GROUP BY cInvCode ) vif
+		join (
+		select oti.cInvCode as cInvCode,max(oti.cInvName) as goodsName,sum(ot.iQuantity)/sum(od.iQuantity) as unitConsumption,sum(ot.iQuantity) as planQuantity,
 		sum(ot.iSendQTY) as usageQuantity
 		from UFDATA_103_2021.dbo.om_momain om
 		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
 		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 om.cCode like CONCAT(#{code},'%')
 		and omi.cInvCcode like '19%'
 		and (om.cCloser is null or ( (od.iReceivedQTY is not null or od.iReceivedQTY != 0) and (ot.iSendQTY is not null or ot.iSendQTY !=0) ) or om.cCloser='asuser')
-		GROUP BY om.cCode,oti.cInvCode
+		GROUP BY oti.cInvCode
 		) vim on vim.cInvCode = vif.cInvCode
-		where trim(vif.cCode) like CONCAT(#{code},'%')
-		GROUP BY vim.cInvCode
+		GROUP BY vif.cInvCode
 		) tab
 		left join
 		( select tab2.cInvCode,max(tab2.cinvName) as cinvName,sum(tab1.purchaseQuantity) as purchaseQuantity,sum(tab2.jian) as jian from

+ 10 - 42
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/mapper/xml/SyCostAllocationIngredientMapper.xml

@@ -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