Browse Source

成本报表 辅料余下

liuchaohui 2 years ago
parent
commit
1d2861abfd

+ 3 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/mapper/SyCostAllocationIngredientMapper.java

@@ -6,6 +6,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.cost.entity.SyCostAllocationIngredient;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.cost.entity.SyRemaining;
 import org.jeecg.modules.cost.entity.SyTransfer;
 
 /**
@@ -24,4 +25,6 @@ public interface SyCostAllocationIngredientMapper extends BaseMapper<SyCostAlloc
 	List<SyCostAllocationIngredient> queryByCostIngredient(String code);
 	@DS("multi-three")
 	List<SyTransfer> queryTransferByIngredient(@Param("code") String code, @Param("goodName") String goodName);
+	@DS("multi-three")
+	List<SyRemaining> queryRemainingByIngredient(@Param("code") String code, @Param("goodName") String goodName);
 }

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

@@ -18,7 +18,7 @@
 
 	<select id="queryByCostIngredient" resultType="org.jeecg.modules.cost.entity.SyCostAllocationIngredient">
 		select tab.*,isnull(tab1.purchaseQuantity,0) as purchaseQuantity,isnull(tab1.purchaseQuantity,0)-tab2.jian as ingredientsTransferQuantity,
-				isnull(tab1.purchaseQuantity,0)-tab.usageQuantity as ingredientsRemainingQuantity,
+				tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as ingredientsRemainingQuantity,
 				(tab1.purchaseQuantity-tab.usageQuantity)/tab1.purchaseQuantity as loss,(isnull(tab1.purchaseQuantity,0)-tab2.jian)*tab.cost as transferCost
 		from 
 		(
@@ -75,7 +75,7 @@
 		union all
 
 		select tab.*,isnull(tab1.purchaseQuantity,0) as purchaseQuantity,isnull(tab1.purchaseQuantity,0)-tab2.jian as ingredientsTransferQuantity,
-				isnull(tab1.purchaseQuantity,0)-tab.usageQuantity as ingredientsRemainingQuantity,
+				tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as ingredientsRemainingQuantity,
 				(tab1.purchaseQuantity-tab.usageQuantity)/tab1.purchaseQuantity as loss,(isnull(tab1.purchaseQuantity,0)-tab2.jian)*tab.cost as transferCost
 		from
 		(
@@ -245,4 +245,86 @@
 		)tab2 on tab2.cInvName=tab1.cInvName and tab1.cBatch=tab2.cBatch
 		 where tab1.purchaseQuantity-tab2.jian>0
     </select>
+
+	<select id="queryRemainingByIngredient" resultType="org.jeecg.modules.cost.entity.SyRemaining">
+		select tab.goodsName,ccode as planCode,tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as number,
+				tab.cost as unitCost,(tab.usageQuantity-isnull(tab1.purchaseQuantity,0))*tab.cost as cost
+		from
+		(
+				select oti.cInvName as goodsName,max(om.cCode) as ccode,sum(ot.iQuantity) as usageQuantity,sum(pb.iCost) as cost
+				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
+				left join (
+						SELECT p.cInvCode,p.iorderdid,sum(bi.iCost) as iCost
+						from UFDATA_901_2021.dbo.PO_Podetails p
+						join UFDATA_901_2021.dbo.PurBillVouchs bi  on bi.iPOsID=p.ID
+						GROUP BY p.cInvCode,p.iorderdid
+				 ) pb on pb.cInvCode=ot.cInvCode and pb.iorderdid=od.isosid
+				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 '05%' or oti.cInvCcode like '06%'
+							or oti.cInvCcode like '07%' or oti.cInvCCode = '0399' or oti.cInvCCode = '0499')
+							and oti.cInvName = #{goodName}
+				GROUP BY oti.cInvName
+		) tab
+		left join
+		(
+				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 '05%' or i.cInvCcode like '06%' or i.cInvCcode like '07%'
+						or i.cInvCCode = '0399' or i.cInvCCode = '0499')
+				GROUP BY i.cInvName,rs.cBatch
+		)tab1 on tab1.cInvName=tab.goodsName
+		where usageQuantity-isnull(tab1.purchaseQuantity,0)>0
+
+		union all
+
+		select tab.goodsName,ccode as planCode,tab.usageQuantity-isnull(tab1.purchaseQuantity,0) as number,
+				tab.cost as unitCost,(tab.usageQuantity-isnull(tab1.purchaseQuantity,0))*tab.cost as cost
+		from
+		(
+				select oti.cInvName as goodsName,max(om.cCode) as ccode,sum(ot.iQuantity) as usageQuantity,sum(pb.iCost) as cost
+				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
+				left join (
+						SELECT p.cInvCode,p.iorderdid,sum(bi.iCost) as iCost
+						from UFDATA_903_2021.dbo.PO_Podetails p
+						join UFDATA_903_2021.dbo.PurBillVouchs bi  on bi.iPOsID=p.ID
+						GROUP BY p.cInvCode,p.iorderdid
+				 ) pb on pb.cInvCode=ot.cInvCode and pb.iorderdid=od.isosid
+				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 '05%' or oti.cInvCcode like '06%'
+							or oti.cInvCcode like '07%' or oti.cInvCCode = '0399' or oti.cInvCCode = '0499')
+							and oti.cInvName = #{goodName}
+				GROUP BY oti.cInvName
+		) tab
+		left join
+		(
+				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 '05%' or i.cInvCcode like '06%' or i.cInvCcode like '07%'
+						or i.cInvCCode = '0399' or i.cInvCCode = '0499')
+				GROUP BY i.cInvName,rs.cBatch
+		)tab1 on tab1.cInvName=tab.goodsName
+		where usageQuantity-isnull(tab1.purchaseQuantity,0)>0
+    </select>
 </mapper>

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/service/impl/SyCostAllocationServiceImpl.java

@@ -230,6 +230,11 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
                 List<SyTransfer> transferlist  = syCostAllocationIngredientMapper.queryTransferByIngredient(plannum,Ingredient.getGoodsName());
                 Ingredient.setSyTransfers(transferlist);
             }
+            //若转入数量不为0则给转入数据对象赋值
+            if(0!=Ingredient.getIngredientsRemainingQuantity().compareTo(BigDecimal.ZERO)){
+                List<SyRemaining> remaininglist  = syCostAllocationIngredientMapper.queryRemainingByIngredient(plannum,Ingredient.getGoodsName());
+                Ingredient.setSyRemaining(remaininglist);
+            }
             //辅料含税成本 美元
             if(Ingredient.getUsdAmount()!=null){
                 if(syCostAllocation.getExcipiencostIncludestax()==null){