Browse Source

成本报表 面料

liuchaohui 1 năm trước cách đây
mục cha
commit
2e4d619e76

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

@@ -135,139 +135,79 @@
 	</select>
 
 	<select id="queryTransferByFabric" resultType="org.jeecg.modules.cost.entity.SyTransfer">
-        select tab1.cInvName as goodsName,tab1.cFree1 as color,tab1.cCode as planCode,
-				tab1.purchaseQuantity-tab2.jian as number
+		select
+		tab2.cinvName as goodsName,tab2.cFree1 as color,tab2.cBatch as planCode,
+		case when tab2.jian-isnull(tab1.purchaseQuantity,0) <![CDATA[<=]]> 0 then 0
+		else tab2.jian-isnull(tab1.purchaseQuantity,0) end as number
 		from
 		(
-				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch,rs.cFree1,(
-						select distinct om.cCode
-						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 od.csocode=rs.iordercode
-				) as ccode
-				from UFDATA_901_2021.dbo.rdrecords01 rs
-				join UFDATA_901_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
-				where (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
-				GROUP BY i.cInvName,rs.cBatch,rs.cFree1,rs.iordercode
+		select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch,rs.cFree1 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,rs.cFree1
 		)tab1
-		 join
+		right join
 		(
-				select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch,rs.cFree1 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'
-				and i.cInvName = #{goodName}
-				GROUP BY i.cInvName,rs.cBatch,rs.cFree1
-		)tab2 on tab2.cInvName=tab1.cInvName and tab1.cBatch=tab2.cBatch and tab1.cFree1=tab2.cFree1
-		where tab1.purchaseQuantity-tab2.jian>0
+		select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch,rs.cFree1 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,rs.cFree1
+		)tab2 on tab2.cInvName=tab1.cInvName and tab2.cBatch=tab1.cBatch and tab1.cfree1=tab2.cfree1
+		where tab2.jian-isnull(tab1.purchaseQuantity,0) > 0
 
 		union all
 
-		select tab1.cInvName as goodsName,tab1.cFree1 as color,tab1.cCode as planCode,
-				tab1.purchaseQuantity-tab2.jian as number
+		select
+		tab2.cinvName as goodsName,tab2.cFree1 as color,tab2.cBatch as planCode,
+		case when tab2.jian-isnull(tab1.purchaseQuantity,0) <![CDATA[<=]]> 0 then 0
+		else tab2.jian-isnull(tab1.purchaseQuantity,0) end as number
 		from
 		(
-				select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch,rs.cFree1,(
-						select distinct om.cCode
-						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 od.csocode=rs.iordercode
-				) as ccode
-				from UFDATA_903_2021.dbo.rdrecords01 rs
-				join UFDATA_903_2021.dbo.Inventory i on rs.cInvCode=i.cInvCode
-				where (i.cInvCcode like '03%' or i.cInvCcode like '04%') and i.cInvCCode != '0399' and i.cInvCCode != '0499'
-				GROUP BY i.cInvName,rs.cBatch,rs.cFree1,rs.iordercode
+		select i.cInvName,sum(rs.iQuantity) as purchaseQuantity,rs.cBatch,rs.cFree1 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,rs.cFree1
 		)tab1
-		 join
+		right join
 		(
-				select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch,rs.cFree1 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'
-				and i.cInvName = #{goodName}
-				GROUP BY i.cInvName,rs.cBatch,rs.cFree1
-		)tab2 on tab2.cInvName=tab1.cInvName and tab1.cBatch=tab2.cBatch and tab1.cFree1=tab2.cFree1
-		where tab1.purchaseQuantity-tab2.jian>0
+		select i.cInvName,sum(rs.iQuantity) as jian,rs.cBatch,rs.cFree1 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,rs.cFree1
+		)tab2 on tab2.cInvName=tab1.cInvName and tab2.cBatch=tab1.cBatch and tab1.cfree1=tab2.cfree1
+		where tab2.jian-isnull(tab1.purchaseQuantity,0) > 0
     </select>
 
 	<select id="queryRemainingByFabric" resultType="org.jeecg.modules.cost.entity.SyRemaining">
-		select tab.*,tab2.jian-tab.usageQuantity as number
-		from
-		(
-				select oti.cInvName as goodsName,ot.cFree1 as color,max(om.ccode) as planCode,sum(ot.iQuantity) 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.cInvName = #{goodName}
-						and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
-				GROUP BY oti.cInvName,ot.cFree1
-		) tab
-		left join
-		(
-				select i.cInvName,sum(rs.iQuantity) as jian,rs.cfree1 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.cFree1
-		)tab2 on tab2.cInvName=tab.goodsName and tab.color=tab2.cfree1
-
-		union all
-
-		select tab.*,tab2.jian-tab.usageQuantity as number
-		from
-		(
-				select oti.cInvName as goodsName,ot.cFree1 as color,max(om.ccode) as planCode,sum(ot.iQuantity) 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.cInvName = #{goodName}
-						and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
-				GROUP BY oti.cInvName,ot.cFree1
-		) tab
-		left join
-		(
-				select i.cInvName,sum(rs.iQuantity) as jian,rs.cfree1 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.cFree1
-		)tab2 on tab2.cInvName=tab.goodsName and tab.color=tab2.cfree1
-	</select>
-<!--	select oti.cInvName as goodsName,ot.cFree1 as color,max(om.ccode) as planCode,sum(ot.iQuantity) as number
+		select oti.cInvName as goodsName,ot.cFree1 as color,max(om.ccode) as planCode,sum(ot.iQuantity) as number
 	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
@@ -287,5 +227,6 @@
 	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.cInvName = #{goodName}
 	and (oti.cInvCcode like '03%' or oti.cInvCcode like '04%') and oti.cInvCCode != '0399' and oti.cInvCCode != '0499'
-	GROUP BY oti.cInvName,ot.cFree1-->
+	GROUP BY oti.cInvName,ot.cFree1
+	</select>
 </mapper>

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

@@ -12,10 +12,7 @@ import org.jeecg.modules.cost.mapper.*;
 import org.jeecg.modules.cost.service.*;
 import org.jeecg.modules.openApi.service.ISenYuDataSourceOne;
 import org.jeecg.modules.openApi.service.ISenYuDataSourceThree;
-import org.jeecg.modules.report.entity.FabricLoss;
-import org.jeecg.modules.report.entity.FabricMoOrderCK;
-import org.jeecg.modules.report.entity.FabricOMOrder;
-import org.jeecg.modules.report.entity.SyFabricLossReport;
+import org.jeecg.modules.report.entity.*;
 import org.jeecg.modules.report.service.ISyFabricLossReportService;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
@@ -26,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -174,25 +172,6 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
             }
         }
 
-        //查询单证面损数据
-//        SyFabricLossReport syFabricLossReport = null;
-//        QueryWrapper<SyFabricLossReport> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.eq("plan_code", plannum);
-//        List<SyFabricLossReport> syFabricLossReportList = syFabricLossReportService.list(queryWrapper);
-//        if (syFabricLossReportList.size()>0){
-//            syFabricLossReport = syFabricLossReportList.get(0);
-//        }
-//
-//        FabricLoss fabricLoss = null;
-//        if (syFabricLossReport != null){
-//            fabricLoss = JSON.parseObject(JSON.toJSONString(syFabricLossReport.getContent()), FabricLoss.class);
-//        }
-//        List<FabricMoOrderCK> fabricMoOrderCK = new ArrayList<>();
-//        for (FabricOMOrder fabricOMOrder:fabricLoss.getFabricOMOrderList2()) {
-//            for (FabricMoOrderCK f:fabricOMOrder.getFabricMoOrderCKList()) {
-//                fabricMoOrderCK.add(f);
-//            }
-//        }
 
         /*查询U8数据 面料*/
         List<SyCostAllocationFabric> list3 = syCostAllocationFabricMapper.queryByCostFabric(plannum);
@@ -209,12 +188,62 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
             //若余下数量不为0则给转入数据对象赋值
             if(0!=Fabric.getFabricremainingQuantity().compareTo(BigDecimal.ZERO)){
                 List<SyRemaining> syRemaining  = syCostAllocationFabricMapper.queryRemainingByFabric(plannum,Fabric.getGoodsName());
+                BigDecimal cost = new BigDecimal(BigInteger.ZERO);
+                for (SyRemaining syRemain:syRemaining) {
+                    //查询单证面损数据
+                    SyFabricLossReport syFabricLossReport = null;
+                    QueryWrapper<SyFabricLossReport> queryWrapper = new QueryWrapper<>();
+                    queryWrapper.eq("plan_code", syRemain.getPlanCode());
+                    List<SyFabricLossReport> syFabricLossReportList = syFabricLossReportService.list(queryWrapper);
+                    if (syFabricLossReportList.size()>0){
+                        syFabricLossReport = syFabricLossReportList.get(0);
+                    }
+
+                    FabricLoss fabricLoss = null;
+                    if (syFabricLossReport != null){
+                        fabricLoss = JSON.parseObject(JSON.toJSONString(syFabricLossReport.getContent()), FabricLoss.class);
+                        for (FabricOMOrder fabricOMOrder:fabricLoss.getFabricOMOrderList2()) {
+                            if(fabricOMOrder.getCInvName().equals(syRemain.getGoodsName())){
+                                Double unitCost=fabricOMOrder.getFabricMoOrderRKList().stream().mapToDouble(FabricMoOrderRK::getIPrice).average().orElse(0d);
+                                syRemain.setUnitCost(new BigDecimal(unitCost));
+                                syRemain.setCost(syRemain.getUnitCost().multiply(new BigDecimal(syRemain.getNumber())));
+                                cost=cost.add(syRemain.getCost());
+                            }
+                        }
+                    }
+                }
+                Fabric.setRemainingQuantitycost(cost);
                 Fabric.setSyRemaining(syRemaining);
             }
             //若转入数量不为0则给转入数据对象赋值
             if(0!=Fabric.getFabrictransferQuantity().compareTo(BigDecimal.ZERO)){
                 List<SyTransfer> transferlist  = syCostAllocationFabricMapper.queryTransferByFabric(plannum,Fabric.getGoodsName());
+                BigDecimal cost = new BigDecimal(BigInteger.ZERO);
+                for (SyTransfer syTransfer:transferlist) {
+                    //查询单证面损数据
+                    SyFabricLossReport syFabricLossReport = null;
+                    QueryWrapper<SyFabricLossReport> queryWrapper = new QueryWrapper<>();
+                    queryWrapper.eq("plan_code", syTransfer.getPlanCode());
+                    List<SyFabricLossReport> syFabricLossReportList = syFabricLossReportService.list(queryWrapper);
+                    if (syFabricLossReportList.size()>0){
+                        syFabricLossReport = syFabricLossReportList.get(0);
+                    }
+
+                    FabricLoss fabricLoss = null;
+                    if (syFabricLossReport != null){
+                        fabricLoss = JSON.parseObject(JSON.toJSONString(syFabricLossReport.getContent()), FabricLoss.class);
+                        for (FabricOMOrder fabricOMOrder:fabricLoss.getFabricOMOrderList2()) {
+                            if(fabricOMOrder.getCInvName().equals(syTransfer.getGoodsName())){
+                                Double unitCost=fabricOMOrder.getFabricMoOrderRKList().stream().mapToDouble(FabricMoOrderRK::getIPrice).average().orElse(0d);
+                                syTransfer.setUnitCost(new BigDecimal(unitCost));
+                                syTransfer.setCost(syTransfer.getUnitCost().multiply(new BigDecimal(syTransfer.getNumber())));
+                                cost=cost.add(syTransfer.getCost());
+                            }
+                        }
+                    }
+                }
                 Fabric.setSyTransfers(transferlist);
+                Fabric.setTransferCost(cost);
             }
         }