Bladeren bron

面料损耗更新

fenghaifu 1 jaar geleden
bovenliggende
commit
3631ce72db

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/mapper/FabricLossMapper.java

@@ -131,6 +131,7 @@ public interface FabricLossMapper extends BaseMapper<FabricLoss> {
 	List<FabricMoOrderCK> getOmRowOutListByDetailId(@Param("detailIdList")List<Integer> detailIdList);
 	// 采购入库、委外入库、转换入库、其他入库
 	@DS("multi-three")
+	@InterceptorIgnore(tenantLine = "1")
 	List<FabricCommonIn> getInListByInvId(@Param("invIdList")List<String> invIdList);
 	// 获取成衣委外出库
 	@DS("multi-three")

+ 58 - 52
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/mapper/xml/FabricLossMapper.xml

@@ -528,63 +528,69 @@
 	</select>
 	<!-- 根据物料id获取入库信息:采购入库、委外入库、转换入库、其他入库 -->
 	<select id="getInListByInvId" resultType="org.jeecg.modules.report.entity.FabricCommonIn">
-
+		select * from (
 		(
-		select  b.AutoId,a.cCode,isnull(b.cPOID,'') as cPlanCode,a.cBusType,e.cVCName,d.cVenName,d.cVenAbbName,
-		b.cInvCode,isnull(b.cFree1,'') as cColor,isnull(b.cBatch,'') as cBatch,f.cInvName,b.iQuantity,
-		isnull(isnull((select sum(case when y.cexch_name='美元' then convert(decimal(18,4),isnull(x.cdefine27,'0'))*x.iPBVQuantity else x.iSum end)/sum(x.iPBVQuantity ) from PurBillVouchs  x inner join purbillvouch y on x.PBVID =y.PBVID where x.RdsId =b.autoid),b.iSum/b.iQuantity),0) as iPrice,
-		isnull(b.iOMoDID,0) as MODetailsID,isnull(b.iPOsID,0) as PoDetailsID,f.cInvCCode,1.0 as iRate,h.dPODate as dDate,
-		isnull(b.iSumBillQuantity,0) as iQuantityInvoice,
-		isnull(b.iSQuantity,0) as iQuantitySettle
-
-		from rdrecords01 b
-			inner join rdrecord01 a on  a.id=b.id
+			select 1 as type,b.AutoId,a.cCode,isnull(b.cPOID,'') as cPlanCode,a.cBusType,e.cVCName,d.cVenName,d.cVenAbbName,
+			b.cInvCode,isnull(b.cFree1,'') as cColor,isnull(b.cBatch,'') as cBatch,f.cInvName,b.iQuantity,
+			isnull(isnull((select sum(case when y.cexch_name='美元' then
+			convert(decimal(18,4),isnull(x.cdefine27,'0'))*x.iPBVQuantity else x.iSum end)/sum(x.iPBVQuantity ) from
+			PurBillVouchs x inner join purbillvouch y on x.PBVID =y.PBVID where x.RdsId =b.autoid),b.iSum/b.iQuantity),0) as
+			iPrice,
+			isnull(b.iOMoDID,0) as MODetailsID,isnull(b.iPOsID,0) as PoDetailsID,f.cInvCCode,1.0 as iRate,h.dPODate as
+			dDate,
+			isnull(b.iSumBillQuantity,0) as iQuantityInvoice,
+			isnull(b.iSQuantity,0) as iQuantitySettle
+
+			from rdrecords01 b
+			inner join rdrecord01 a on a.id=b.id
 			inner join PO_Podetails g on b.iposid=g.id
-			inner join PO_Pomain h on h.POID  =g.POID
+			inner join PO_Pomain h on h.POID =g.POID
 			inner join Vendor d on d.cVenCode=a.cVenCode
 			inner join VendorClass e on d.cVCCode =e.cVCCode
-			inner join Inventory  f ON b.cinvcode = f.cinvcode
-		where  b.cInvCode + isnull(b.cFree1,'') + isnull(b.cBatch,'')  in
-		<foreach  item="item" collection="invIdList" index="index"  open="(" separator="," close=")">
-			#{item}
-		</foreach>
-		) union all
-		(
-		select  b.AutoId,a.cCode,isnull(b.cPOID,'') as cPlanCode,a.cBusType,e.cVCName,d.cVenName,d.cVenAbbName,
-		b.cInvCode,isnull(b.cFree1,'') as cColor,isnull(b.cBatch,'') as cBatch,f.cInvName,b.iQuantity,
-		0 as iPrice,
-		isnull(b.iOMoDID,0) as MODetailsID,isnull(b.iPOsID,0) as PoDetailsID,f.cInvCCode,1.0 as iRate,h.dDate,
-		0 as iQuantityInvoice,
-		0 as iQuantitySettle
-		from rdrecords01 b
-		inner join rdrecord01 a on  a.id=b.id
-		inner join OM_MODetails g on b.iOMoDID=g.MODetailsID
-		inner join om_momain h on h.moid  =g.moid
-		inner join Vendor d on d.cVenCode=a.cVenCode
-		inner join VendorClass e on d.cVCCode =e.cVCCode
-		inner join Inventory  f ON b.cinvcode = f.cinvcode
-		where  b.cInvCode + isnull(b.cFree1,'') + isnull(b.cBatch,'')  in
-		<foreach  item="item" collection="invIdList" index="index"  open="(" separator="," close=")">
-			#{item}
-		</foreach>
-		)
-		 union all (
-		select  b.AutoId,a.cCode, isnull(a.cdefine9,'') as cPlanCode,a.cBusType,'' as cVCName,'' as cVenName,'' as cVenAbbName,
-		b.cInvCode,isnull(b.cFree1,'') as cColor,isnull(b.cBatch,'') as cBatch,f.cInvname,b.iQuantity,
-		isnull(case when a.cMaker='王行乔' then b.iPrice/b.iQuantity else b.iPrice*1.13/b.iQuantity end,0) as iPrice,
-		0 as MODetailsID, 0 as PoDetailsID,f.cInvCCode,1.0 as iRate,a.dDate,
-		0 as iQuantityInvoice,
-		0 as iQuantitySettle
-		from rdrecords08 b
-		inner join rdrecord08 a on  a.id=b.id
-		inner join Inventory  f ON b.cinvcode = f.cinvcode
-		where  b.iQuantity&lt;&gt;0 and a.cbustype &lt;&gt; '调拨入库' and
-		b.cInvCode + isnull(b.cFree1,'') + isnull(b.cBatch,'')  in
-		<foreach  item="item" collection="invIdList" index="index"  open="(" separator="," close=")">
-			#{item}
-		</foreach>
+			inner join Inventory f ON b.cinvcode = f.cinvcode
+			where b.cInvCode + isnull(b.cFree1,'') + isnull(b.cBatch,'') in
+			<foreach item="item" collection="invIdList" index="index" open="(" separator="," close=")">
+				#{item}
+			</foreach>
+			) union all
+			(
+			select 2 as type,b.AutoId,a.cCode,isnull(b.cPOID,'') as cPlanCode,a.cBusType,e.cVCName,d.cVenName,d.cVenAbbName,
+			b.cInvCode,isnull(b.cFree1,'') as cColor,isnull(b.cBatch,'') as cBatch,f.cInvName,b.iQuantity,
+			0 as iPrice,
+			isnull(b.iOMoDID,0) as MODetailsID,isnull(b.iPOsID,0) as PoDetailsID,f.cInvCCode,1.0 as iRate,h.dDate,
+			0 as iQuantityInvoice,
+			0 as iQuantitySettle
+			from rdrecords01 b
+			inner join rdrecord01 a on a.id=b.id
+			inner join OM_MODetails g on b.iOMoDID=g.MODetailsID
+			inner join om_momain h on h.moid =g.moid
+			inner join Vendor d on d.cVenCode=a.cVenCode
+			inner join VendorClass e on d.cVCCode =e.cVCCode
+			inner join Inventory f ON b.cinvcode = f.cinvcode
+			where b.cInvCode + isnull(b.cFree1,'') + isnull(b.cBatch,'') in
+			<foreach item="item" collection="invIdList" index="index" open="(" separator="," close=")">
+				#{item}
+			</foreach>
+			)
+			union all (
+			select 3 as type,b.AutoId,a.cCode, isnull(a.cdefine9,'') as cPlanCode,a.cBusType,'' as cVCName,'' as cVenName,''
+			as cVenAbbName,
+			b.cInvCode,isnull(b.cFree1,'') as cColor,isnull(b.cBatch,'') as cBatch,f.cInvname,b.iQuantity,
+			isnull(case when a.cMaker='王行乔' then b.iPrice/b.iQuantity else b.iPrice*1.13/b.iQuantity end,0) as iPrice,
+			0 as MODetailsID, 0 as PoDetailsID,f.cInvCCode,1.0 as iRate,a.dDate,
+			0 as iQuantityInvoice,
+			0 as iQuantitySettle
+			from rdrecords08 b
+			inner join rdrecord08 a on a.id=b.id
+			inner join Inventory f ON b.cinvcode = f.cinvcode
+			where b.iQuantity&lt;&gt;0 and a.cbustype &lt;&gt; '调拨入库' and
+			b.cInvCode + isnull(b.cFree1,'') + isnull(b.cBatch,'') in
+			<foreach item="item" collection="invIdList" index="index" open="(" separator="," close=")">
+				#{item}
+			</foreach>
 
-		)
+			)
+		) as t1 order by type, PoDetailsID,MODetailsID, AutoId
 
 
 	</select>

+ 40 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/service/impl/FabricLossServiceImpl.java

@@ -968,7 +968,7 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 		// 查询物料入库信息
 		List<FabricCommonIn> otherInList = new ArrayList<>();
 		if (otherInInvId.size()>0) {
-			otherInList = fabricLossMapper.getInListByInvId(otherInInvId);
+			otherInList = getValidInListByInvId(otherInInvId);
 			// 设置单价比例
 			otherInList.forEach(e -> {
 				e.setITempUseSum(0.0);
@@ -1190,7 +1190,7 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 			outList.forEach(e->invIdList.add(e.getInvOutId()));
 			List<FabricCommonIn> inList = new ArrayList<>();
 			if (oConvertUtils.listIsNotEmpty(invIdList)) {
-				inList = fabricLossMapper.getInListByInvId(invIdList);
+				inList = getValidInListByInvId(invIdList);
 			}
 			// 设置价格比例,入库价格保留四位小数
 			inList.forEach(e->{
@@ -1342,7 +1342,7 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 			// 获取委外订单出库物料入库详情
 			List<String> invIdList = new ArrayList<>();
 			outList.forEach(e->invIdList.add(e.getInvOutId()));
-			List<FabricCommonIn> inList = fabricLossMapper.getInListByInvId(invIdList);
+			List<FabricCommonIn> inList = getValidInListByInvId(invIdList);
 			// 设置价格比例,入库价格保留四位小数
 			inList.forEach(e-> {
 				if (e.getIQuantityInvoice() != 0 && e.getIQuantitySettle() != 0){
@@ -1841,8 +1841,12 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 		if (oConvertUtils.listIsNotEmpty(outList1)){
 			otherOutList.addAll(outList1);
 		}
-		// 把成衣材料出库和销售出库cBusType设置成否,只用于扣减入库。不作为转入成本
-		otherOutList.forEach(e->e.setCBusType("否"));
+		// 把0299和0399 的 成衣材料出库和销售出库cBusType设置成否,只用于扣减入库。不作为转入成本
+		otherOutList.forEach(e->{
+			if ("0299".equalsIgnoreCase(e.getCInvCCodeOut()) || "0399".equalsIgnoreCase(e.getCInvCCodeOut())) {
+				e.setCBusType("否");
+			}
+		});
 
 		allOutList.addAll(otherOutList);
 		allOutList.forEach(e->{
@@ -1855,7 +1859,7 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 		if (otherOutList.size()>0) {
 			List<String> invIdList = new ArrayList<>();
 			otherOutList.forEach(e -> invIdList.add(e.getInvOutId()));
-			List<FabricCommonIn> inList = fabricLossMapper.getInListByInvId(invIdList);
+			List<FabricCommonIn> inList = getValidInListByInvId(invIdList);
 			inList.forEach(e -> {
 				if (e.getIQuantityInvoice() != 0 && e.getIQuantitySettle() != 0){
 					e.setIPrice(DoubleOperation.getScale(e.getIPrice()*e.getIQuantityInvoice()/e.getIQuantitySettle(),4));
@@ -2034,4 +2038,34 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 		return commonInList;
 
 	}
+
+	/**
+	 * 根据物料id获取入库记录,同一个委外子表id或者采购子表id,同物料,正负抵扣
+	 * @param invIdList
+	 * @return
+	 */
+	private List<FabricCommonIn> getValidInListByInvId(List<String> invIdList){
+		List<FabricCommonIn> inList = fabricLossMapper.getInListByInvId(invIdList);
+		// 采购入库或者委外入库负数
+		List<FabricCommonIn> nInList = inList.stream().filter(e->(e.getMODetailsID()!=0 || e.getPoDetailsID()!=0) && e.getIQuantity()<0 ).collect(Collectors.toList());
+		List<FabricCommonIn> pInList = inList.stream().filter(e->(e.getMODetailsID()==0 && e.getPoDetailsID()==0) || e.getIQuantity()>0 ).collect(Collectors.toList());
+		for (FabricCommonIn nItem : nInList){
+			Double dNQuantity = nItem.getIQuantity();
+			// 找到 同一个委外子表id或者采购子表id,同物料
+			List<FabricCommonIn> findList = pInList.stream().filter(e->
+					(e.getMODetailsID()!=0 && e.getMODetailsID().equals(nItem.getMODetailsID()) ||
+							e.getPoDetailsID()!=0 && e.getPoDetailsID().equals(nItem.getPoDetailsID())) && e.getInvId().equalsIgnoreCase(nItem.getInvId())).collect(Collectors.toList());
+			for (FabricCommonIn pItem : findList){
+				Double dSum = Math.min(-dNQuantity, pItem.getIQuantity());
+				if (dSum>0){
+					pItem.setIQuantity(DoubleOperation.sub(pItem.getIQuantity(), dSum));
+					dNQuantity = DoubleOperation.add(dNQuantity, dSum);
+				}
+				if (dNQuantity>=0){
+					break;
+				}
+			}
+		}
+		return pInList.stream().filter(e->(e.getMODetailsID()==0 && e.getPoDetailsID()==0) || e.getIQuantity()>0 ).collect(Collectors.toList());
+	}
 }