Browse Source

面料损耗更新

fenghaifu 2 years ago
parent
commit
871f9ceda0

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

@@ -121,4 +121,7 @@ public interface FabricLossMapper extends BaseMapper<FabricLoss> {
 	// 获取委外订单出库物料的入库物料信息:包含采购入库、委外入库、其他入库
 	@DS("multi-three")
 	List<Map<String,Object>> getOmRowInList(@Param("code")String code);
+	// 根据形态转换物料获取采购入库信息
+	@DS("multi-three")
+	List<Map<String,Object>> getOmRowInListWithAV(@Param("code")String code);
 }

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

@@ -602,13 +602,14 @@
 		WHERE
 		c.cInvCCode NOT LIKE '19%'
 		AND a.cCode LIKE CONCAT(#{code},'%')
+		and exists (select * from  rdrecords01 x where x.iOMoDID=b.MODetailsID)
 	</select>
 	<!-- 获取委外订单行id,出库物料信息,出库数量 -->
 	<select id="getOmRowOutList" resultType="org.jeecg.modules.report.entity.FabricMoOrderCK">
 		select b.MODetailsID,
 			 d.cInvCode as cInvCodeOut,z.cInvName as cInvNameOut,isnull(d.cFree1,'') as cColorOut,
 			 isnull(d.cBatch,'') as cBatchOut,
-			 d.iQuantity as iQuantityOut
+			 isnull(sum(d.iQuantity),0) as iQuantityOut
 		FROM
 		om_momain a
 		INNER JOIN OM_MODetails b ON a.moid = b.moid
@@ -618,6 +619,8 @@
 		WHERE
 		c.cInvCCode NOT LIKE '19%'
 		AND a.cCode LIKE CONCAT(#{code},'%')
+		group by b.MODetailsID,
+			 d.cInvCode,z.cInvName,d.cFree1,d.cBatch
 	</select>
 	<!-- 获取委外订单出库物料的入库物料信息:包含采购入库、委外入库、其他入库 -->
 	<select id="getOmRowInList" resultType="map">
@@ -650,7 +653,7 @@
 			select f.cBusType,f.cCode,'' as cVenName,'' as cVenAbbName,
 			e.cInvCode,isnull(e.cFree1,'') as cColor,isnull(e.cBatch,'') as cBatch,
 			e.iQuantity,
-			isnull(iPrice,0) as iPurchuseMoney,
+			isnull(e.iPrice,0) as iPurchuseMoney,
 			null as MODetailsID
 			from rdrecords08 e
 				inner join rdrecord08 f on e.id=f.id
@@ -673,4 +676,87 @@
 		)
 
 	</select>
+	<!-- 根据形态转换物料获取采购入库、其他入库信息 -->
+	<select id="getOmRowInListWithAV" resultType="map">
+	(
+	select f.cBusType,f.cCode,g.cVenName,g.cVenAbbName,
+		e.cInvCode,isnull(e.cFree1,'') as cColor,isnull(e.cBatch,'') as cBatch,
+		e.iQuantity,
+		isnull((select sum(iSum) from PurBillVouchs  x where x.RdsId =e.autoid and f.cbustype='普通采购'),0) as iPurchuseMoney,
+		e.iOMoDID as MODetailsID,
+		(select top 1  x.cInvCode2+isnull(x.cColor2,'')+isnull(x.cAVBatch2,'') from
+				VIEW_FabricLoss_AssemVouchs x where
+				x.cInvCode+isnull(x.cColor,'')+isnull(x.cAVBatch,'')=e.cInvCode+isnull(e.cfree1,'')+isnull(e.cBatch,'')) as cInvIdOut
+	from rdrecords01 e
+		inner join rdrecord01 f on e.id=f.id
+		inner join Vendor g on g.cVenCode=f.cVenCode
+	where
+		e.cinvcode+isnull(e.cfree1,'')+isnull(cbatch,'') in (
+			select x.cInvCode+isnull(x.cColor,'')+isnull(x.cAVBatch,'') from
+				VIEW_FabricLoss_AssemVouchs x
+				where x.cInvCode2+isnull(x.cColor2,'')+isnull(x.cAVBatch2,'') in (
+					select
+						e.cInvCode+isnull(e.cFree1,'')+isnull(e.cBatch,'')
+						from rdrecords08 e
+							inner join rdrecord08 f on e.id=f.id
+							where e.cinvcode+isnull(e.cfree1,'')+isnull(cbatch,'') in (
+
+								select
+									 d.cInvCode+isnull(d.cFree1,'')+isnull(d.cBatch,'')
+								FROM
+								om_momain a
+								INNER JOIN OM_MODetails b ON a.moid = b.moid
+								INNER JOIN Inventory c ON b.cinvcode = c.cinvcode
+								inner join rdrecords11 d on d.iOMoDID=b.MODetailsID
+								WHERE
+								f.cbustype='转换入库'
+								and c.cInvCCode NOT LIKE '19%'
+								AND a.cCode like CONCAT(#{code},'%')
+
+
+							)  and e.iQuantity>0
+				)
+
+		)
+		and e.iQuantity>0
+	) union all(
+		select f.cBusType,f.cCode,'' as cVenName,'' as cVenAbbName,
+		e.cInvCode,isnull(e.cFree1,'') as cColor,isnull(e.cBatch,'') as cBatch,
+		e.iQuantity,
+		isnull(e.iPrice,0) as iPurchuseMoney,
+		null as MODetailsID,
+		(select top 1  x.cInvCode2+isnull(x.cColor2,'')+isnull(x.cAVBatch2,'') from
+				VIEW_FabricLoss_AssemVouchs x where
+				x.cInvCode+isnull(x.cColor,'')+isnull(x.cAVBatch,'')=e.cInvCode+isnull(e.cfree1,'')+isnull(e.cBatch,'')) as cInvIdOut
+	from rdrecords08 e
+		inner join rdrecord08 f on e.id=f.id
+	where
+		e.cinvcode+isnull(e.cfree1,'')+isnull(cbatch,'') in (
+			select x.cInvCode+isnull(x.cColor,'')+isnull(x.cAVBatch,'') from
+				VIEW_FabricLoss_AssemVouchs x
+				where x.cInvCode2+isnull(x.cColor2,'')+isnull(x.cAVBatch2,'') in (
+					select
+						e.cInvCode+isnull(e.cFree1,'')+isnull(e.cBatch,'')
+						from rdrecords08 e
+							inner join rdrecord08 f on e.id=f.id
+							where e.cinvcode+isnull(e.cfree1,'')+isnull(cbatch,'') in (
+
+								select
+									 d.cInvCode+isnull(d.cFree1,'')+isnull(d.cBatch,'')
+								FROM
+								om_momain a
+								INNER JOIN OM_MODetails b ON a.moid = b.moid
+								INNER JOIN Inventory c ON b.cinvcode = c.cinvcode
+								inner join rdrecords11 d on d.iOMoDID=b.MODetailsID
+								WHERE
+								f.cbustype='转换入库'
+								and c.cInvCCode NOT LIKE '19%'
+								AND a.cCode like CONCAT(#{code},'%')
+							)  and e.iQuantity>0
+				)
+
+		)
+		and e.iQuantity>0 and f.cbustype='其他入库'
+	)
+	</select>
 </mapper>

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

@@ -510,8 +510,10 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 		List<FabricMoOrderCK> rowOutList = fabricLossMapper.getOmRowOutList(code);
 		// 获取委外订单出库物料的入库物料信息:包含采购入库、委外入库、其他入库
 		List<Map<String,Object>> rowInList = fabricLossMapper.getOmRowInList(code);
+		// 获取委外订单出库物料的形态转换前入库物料信息:包含采购入库
+		List<Map<String,Object>> rowInListWithAV = fabricLossMapper.getOmRowInListWithAV(code);
 
-		List<FabricMoOrderCK> fabricMoOrderCKList = getFabricMoOrderCKList(rowInfoList, rowOutList, rowInList);
+		List<FabricMoOrderCK> fabricMoOrderCKList = getFabricMoOrderCKList(rowInfoList, rowOutList, rowInList, rowInListWithAV);
 
 		for (FabricOMOrder fabricOMOrder : fabricOMOrderList){
 			// 根据入库物料过滤
@@ -673,11 +675,13 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 	 * @param rowInfoList - 委外订单行信息
 	 * @param rowOutList - 材料出库信息
 	 * @param rowInList - 材料入库信息
+	 * @param rowInListWithAV - 形态转换前的材料入库信息
 	 * @return
 	 */
 	List<FabricMoOrderCK> getFabricMoOrderCKList(List<Map<String,Object>> rowInfoList,
 	                                             List<FabricMoOrderCK> rowOutList,
-	                                             List<Map<String,Object>> rowInList){
+	                                             List<Map<String,Object>> rowInList,
+	                                             List<Map<String,Object>> rowInListWithAV){
 		// 从最底层的物料向上逐级设置材料入库成本
 		do {
 			// 可设置金额材料出库委外订单行id
@@ -689,10 +693,16 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 							in.get("cBatch").toString().equals(out.getCBatchOut())).count()>0;
 			}).collect(Collectors.toList());
 			// 可设置金额的入库单
-			List<Map<String,Object>> findInCanSetList = rowInList.stream().filter(in->{
-				return oConvertUtils.getDouble(in.get("iPurchuseMoney").toString(),0) == 0 &&
-						findOutCanSetList.stream().filter(out->
-							oConvertUtils.getInt(in.get("MODetailsID")).equals(out.getMODetailsID())).count()>0;
+			List<Map<String,Object>> findInCanSetList = rowInList.stream().filter(in->
+					oConvertUtils.getDouble(in.get("iPurchuseMoney").toString(),0) == 0 &&
+							oConvertUtils.getInt(in.get("MODetailsID"),0)>0
+					).collect(Collectors.toList());
+			if (findInCanSetList.size() == 0){
+				break;
+			}
+			findInCanSetList = findInCanSetList.stream().filter(in->{
+				return findOutCanSetList.stream().filter(out->
+								oConvertUtils.getInt(in.get("MODetailsID")).equals(out.getMODetailsID())).count()>0;
 			}).collect(Collectors.toList());
 			if (findInCanSetList.size() == 0){
 				break;
@@ -788,6 +798,42 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL
 					break;
 				}
 			}
+			// 形态转换前的入库
+			if (outSum>0){
+				List<Map<String,Object>> findInWithAVByOutList = rowInListWithAV.stream().filter(in->
+						in.get("cInvIdOut").toString().equals(itemOut.getCInvCodeOut()+itemOut.getCColorOut()+itemOut.getCBatchOut())).collect(Collectors.toList());
+				for (Map<String,Object> itemIn :findInWithAVByOutList){
+					Double inSum = oConvertUtils.getDouble(itemIn.get("iQuantity").toString(),0);
+					Double iPurchuseMoney = oConvertUtils.getDouble(itemIn.get("iPurchuseMoney").toString(),0);
+					Double curSum = outSum>inSum?inSum:outSum;
+					outSum -= curSum;
+
+					FabricMoOrderCK retItem = new FabricMoOrderCK();
+					ret.add(retItem);
+					retItem.setCBusType(itemIn.get("cBusType").toString());
+					retItem.setCCode(itemIn.get("cCode").toString());
+					retItem.setCVenName(itemIn.get("cVenName").toString());
+					retItem.setCVenAbbName(itemIn.get("cVenAbbName").toString());
+					retItem.setCInvCodeColorIn(findRowInfoOpt.get().get("cInvCodeColorIn").toString());
+					retItem.setCInvCodeOut(itemOut.getCInvCodeOut());
+					retItem.setCInvNameOut(itemOut.getCInvNameOut());
+					retItem.setCColorOut(itemOut.getCColorOut());
+					retItem.setCBatchOut(itemOut.getCBatchOut());
+					retItem.setMODetailsID(itemOut.getMODetailsID());
+					BigDecimal bdVal = new BigDecimal(curSum);
+					retItem.setIQuantity(bdVal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+					retItem.setIQuantityOut(itemOut.getIQuantityOut());
+					retItem.setIQuantityIn(inSum);
+					bdVal = new BigDecimal(iPurchuseMoney/inSum*curSum);
+					retItem.setIMoney(bdVal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+					bdVal = new BigDecimal(iPurchuseMoney/inSum);
+					retItem.setIPrice(bdVal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
+
+					if (outSum<=0){
+						break;
+					}
+				}
+			}
 		}
 
 		return ret;