소스 검색

成本报表 面料

liuchaohui 2 년 전
부모
커밋
1000388d4a
1개의 변경된 파일102개의 추가작업 그리고 78개의 파일을 삭제
  1. 102 78
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/mapper/xml/SyCostAllocationFabricMapper.xml

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

@@ -17,97 +17,121 @@
 	</select>
 
 	<select id="queryByCostFabric" parameterType="java.lang.String" resultType="org.jeecg.modules.cost.entity.SyCostAllocationFabric">
-		select tab.*,isnull(tab1.purchaseQuantity,0) as purchaseQuantity,tab2.jian-isnull(tab1.purchaseQuantity,0) as fabrictransferQuantity,
-				tab2.jian-tab.usageQuantity as fabricremainingQuantity,
-				isnull((tab2.jian-tab.usageQuantity)/tab1.purchaseQuantity,0) as loss
-		from 
+		select
+		tab.*,isnull(tab3.purchaseQuantity,0) as purchaseQuantity,
+		case when tab3.jian-isnull(tab3.purchaseQuantity,0) <![CDATA[<=]]> 0 then 0
+		else tab3.jian-isnull(tab3.purchaseQuantity,0) end as fabrictransferQuantity,
+		case when tab3.jian-isnull(tab3.purchaseQuantity,0) <![CDATA[<=]]> 0 then isnull(tab3.purchaseQuantity,0)-tab.usageQuantity
+		else (tab3.jian-isnull(tab3.purchaseQuantity,0))+isnull(tab3.purchaseQuantity,0)-tab.usageQuantity end
+		as 	fabricremainingQuantity,
+		isnull((
+		case when tab3.jian-isnull(tab3.purchaseQuantity,0) <![CDATA[<=]]> 0
+		then isnull(tab3.purchaseQuantity,0)-tab.usageQuantity
+		else (tab3.jian-isnull(tab3.purchaseQuantity,0))+isnull(tab3.purchaseQuantity,0)-tab.usageQuantity end
+		)/tab3.purchaseQuantity,0) as loss
+		from
 		(
-				select oti.cInvName as goodsName,max(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as planQuantity,
-						sum(ot.iSendQTY) as usageQuantity
-				from UFDATA_903_2021.dbo.om_momain om
-				join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
-				join UFDATA_903_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID
-				join UFDATA_903_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
-				join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
-				WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%' and om.cCode LIKE CONCAT(#{code},'%')
-						and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
-				GROUP BY oti.cInvName
+		select oti.cInvName as goodsName,max(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as planQuantity,
+		sum(ot.iSendQTY) as usageQuantity
+		from UFDATA_901_2021.dbo.om_momain om
+		join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_901_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID
+		join UFDATA_901_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
+		join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%' and om.cCode LIKE CONCAT(#{code},'%')
+		and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
+		GROUP BY oti.cInvName
 		) tab
-		left join 
+		left join
+		( select tab2.cinvName,sum(tab1.purchaseQuantity) as purchaseQuantity,sum(tab2.jian) as jian from
 		(
-				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity from UFDATA_903_2021.dbo.rdrecords01 rs
-				join UFDATA_903_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
-				where iordercode in (
-						select distinct od.csocode
-						from UFDATA_903_2021.dbo.om_momain om  
-						join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
-						join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
-						WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') 
-									and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
-				) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
-				GROUP BY i.cInvName,rs.cBatch
-		)tab1 on tab1.cInvName=tab.goodsName
-		left join 
+		select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch from UFDATA_901_2021.dbo.rdrecords01 rs
+		join UFDATA_901_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
+		where iordercode in (
+		select distinct od.csocode
+		from UFDATA_901_2021.dbo.om_momain om
+		join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
+		and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
+		) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
+		GROUP BY i.cInvName,rs.cBatch
+		)tab1
+		right join
 		(
-				select i.cInvName,sum(rs.iQuantity) as jian from UFDATA_903_2021.dbo.rdrecords11 rs
-				join UFDATA_903_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
-				where iordercode in (
-						select distinct od.csocode
-						from UFDATA_903_2021.dbo.om_momain om  
-						join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
-						join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
-						WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') 
-									and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
-				) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
-				GROUP BY i.cInvName,rs.cBatch
-		)tab2 on tab2.cInvName=tab.goodsName
+		select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch from UFDATA_901_2021.dbo.rdrecords11 rs
+		join UFDATA_901_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
+		where iordercode in (
+		select distinct od.csocode
+		from UFDATA_901_2021.dbo.om_momain om
+		join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
+		and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
+		) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
+		GROUP BY i.cInvName,rs.cBatch
+		)tab2 on tab2.cInvName=tab1.cInvName and tab2.cBatch=tab1.cBatch
+		GROUP BY tab2.cInvName
+		) tab3 on tab3.cInvName=tab.goodsName
 
 		union all
 
-		select tab.*,isnull(tab1.purchaseQuantity,0) as purchaseQuantity,tab2.jian-isnull(tab1.purchaseQuantity,0) as fabrictransferQuantity,
-				tab2.jian-tab.usageQuantity as fabricremainingQuantity,
-				isnull((tab2.jian-tab.usageQuantity)/tab1.purchaseQuantity,0) as loss
+		select
+		tab.*,isnull(tab3.purchaseQuantity,0) as purchaseQuantity,
+		case when tab3.jian-isnull(tab3.purchaseQuantity,0) <![CDATA[<=]]> 0 then 0
+		else tab3.jian-isnull(tab3.purchaseQuantity,0) end as fabrictransferQuantity,
+		case when tab3.jian-isnull(tab3.purchaseQuantity,0) <![CDATA[<=]]> 0 then isnull(tab3.purchaseQuantity,0)-tab.usageQuantity
+		else (tab3.jian-isnull(tab3.purchaseQuantity,0))+isnull(tab3.purchaseQuantity,0)-tab.usageQuantity end
+		as 	fabricremainingQuantity,
+		isnull((
+		case when tab3.jian-isnull(tab3.purchaseQuantity,0) <![CDATA[<=]]> 0
+		then isnull(tab3.purchaseQuantity,0)-tab.usageQuantity
+		else (tab3.jian-isnull(tab3.purchaseQuantity,0))+isnull(tab3.purchaseQuantity,0)-tab.usageQuantity end
+		)/tab3.purchaseQuantity,0) as loss
 		from
 		(
-				select oti.cInvName as goodsName,max(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as planQuantity,
-						sum(ot.iSendQTY) as usageQuantity
-				from UFDATA_901_2021.dbo.om_momain om
-				join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
-				join UFDATA_901_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID
-				join UFDATA_901_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
-				join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
-				WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%' and om.cCode LIKE CONCAT(#{code},'%')
-						and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
-				GROUP BY oti.cInvName
+		select oti.cInvName as goodsName,max(ot.iUnitQuantity) as unitConsumption,sum(ot.iQuantity) as planQuantity,
+		sum(ot.iSendQTY) as usageQuantity
+		from UFDATA_903_2021.dbo.om_momain om
+		join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_903_2021.dbo.OM_MOMaterials ot on ot.MoDetailsID=od.MODetailsID
+		join UFDATA_903_2021.dbo.Inventory oti on oti.cInvCode=ot.cInvCode
+		join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser') and omi.cInvCcode like '19%' and om.cCode LIKE CONCAT(#{code},'%')
+		and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
+		GROUP BY oti.cInvName
 		) tab
 		left join
+		( select tab2.cinvName,sum(tab1.purchaseQuantity) as purchaseQuantity,sum(tab2.jian) as jian from
 		(
-				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity from UFDATA_901_2021.dbo.rdrecords01 rs
-				join UFDATA_901_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
-				where iordercode in (
-						select distinct od.csocode
-						from UFDATA_901_2021.dbo.om_momain om
-						join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
-						join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
-						WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
-									and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
-				) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
-				GROUP BY i.cInvName,rs.cBatch
-		)tab1 on tab1.cInvName=tab.goodsName
-		left join
+		select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch from UFDATA_903_2021.dbo.rdrecords01 rs
+		join UFDATA_903_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
+		where iordercode in (
+		select distinct od.csocode
+		from UFDATA_903_2021.dbo.om_momain om
+		join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
+		and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
+		) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
+		GROUP BY i.cInvName,rs.cBatch
+		)tab1
+		right join
 		(
-				select i.cInvName,sum(rs.iQuantity) as jian from UFDATA_901_2021.dbo.rdrecords11 rs
-				join UFDATA_901_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
-				where iordercode in (
-						select distinct od.csocode
-						from UFDATA_901_2021.dbo.om_momain om
-						join UFDATA_901_2021.dbo.OM_MODetails od on om.moid=od.moid
-						join UFDATA_901_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
-						WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
-									and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
-				) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
-				GROUP BY i.cInvName,rs.cBatch
-		)tab2 on tab2.cInvName=tab.goodsName
+		select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch from UFDATA_903_2021.dbo.rdrecords11 rs
+		join UFDATA_903_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
+		where iordercode in (
+		select distinct od.csocode
+		from UFDATA_903_2021.dbo.om_momain om
+		join UFDATA_903_2021.dbo.OM_MODetails od on om.moid=od.moid
+		join UFDATA_903_2021.dbo.Inventory omi on omi.cInvCode=od.cInvCode
+		WHERE om.iVerifyStateNew = 2 and (om.cCloser is null or om.cCloser='asuser')
+		and omi.cInvCcode like '19%' and om.cCode like CONCAT(#{code},'%')
+		) and (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
+		GROUP BY i.cInvName,rs.cBatch
+		)tab2 on tab2.cInvName=tab1.cInvName and tab2.cBatch=tab1.cBatch
+		GROUP BY tab2.cInvName
+		) tab3 on tab3.cInvName=tab.goodsName
 	</select>
 
 	<select id="queryTransferByFabric" resultType="org.jeecg.modules.cost.entity.SyTransfer">