| 
														
															@@ -547,20 +547,21 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			// 取材料出库成本+本次委外成本=成本 
														 | 
														
														 | 
														
															 			// 取材料出库成本+本次委外成本=成本 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			fabricOMOrder.setFabricMoOrderRKList(findList); 
														 | 
														
														 | 
														
															 			fabricOMOrder.setFabricMoOrderRKList(findList); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			List<FabricMoOrderCK> ckList = fabricOMOrder.getFabricMoOrderCKList(); 
														 | 
														
														 | 
														
															 			List<FabricMoOrderCK> ckList = fabricOMOrder.getFabricMoOrderCKList(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			FabricMoOrderCK ckItem = null; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			Double iMoneyCk = 0.0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			if (ckList != null && ckList.size() > 0){ 
														 | 
														
														 | 
														
															 			if (ckList != null && ckList.size() > 0){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				ckItem = ckList.get(0); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				for (FabricMoOrderCK item : ckList) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					iMoneyCk += item.getIMoney(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			} 
														 | 
														
														 | 
														
															 			} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			for (FabricMoOrderRK fabricMoOrderRK : findList){ 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				BigDecimal bdVal = new BigDecimal(fabricMoOrderRK.getIQuantityIn()-fabricMoOrderRK.getISumBillQuantity()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			for (FabricMoOrderRK fabricMoOrderRK : findList) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				BigDecimal bdVal = new BigDecimal(fabricMoOrderRK.getIQuantityIn() - fabricMoOrderRK.getISumBillQuantity()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				fabricMoOrderRK.setISumBillQuantityN(bdVal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); 
														 | 
														
														 | 
														
															 				fabricMoOrderRK.setISumBillQuantityN(bdVal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				bdVal = new BigDecimal(fabricMoOrderRK.getIQuantityIn()-fabricMoOrderRK.getISQuantity()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				bdVal = new BigDecimal(fabricMoOrderRK.getIQuantityIn() - fabricMoOrderRK.getISQuantity()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				fabricMoOrderRK.setISQuantityN(bdVal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); 
														 | 
														
														 | 
														
															 				fabricMoOrderRK.setISQuantityN(bdVal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				if (ckItem != null && ckItem.getIPrice() != null && ckItem.getIPrice()>0){ 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					bdVal = new BigDecimal(fabricMoOrderRK.getIProcessFee()+ckItem.getIPrice()*fabricMoOrderRK.getIQuantityOut()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					fabricMoOrderRK.setIPrice(bdVal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				Double curIMoneyCk = iMoneyCk * fabricMoOrderRK.getIQuantityIn() / fabricOMOrder.getIQuantityIn() ; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				bdVal = new BigDecimal((fabricMoOrderRK.getIProcessFee() + curIMoneyCk) / fabricMoOrderRK.getIQuantityIn()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				fabricMoOrderRK.setIPrice(bdVal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			} 
														 | 
														
														 | 
														
															 			} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		} 
														 | 
														
														 | 
														
															 		} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -682,6 +683,64 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	                                             List<FabricMoOrderCK> rowOutList, 
														 | 
														
														 | 
														
															 	                                             List<FabricMoOrderCK> rowOutList, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	                                             List<Map<String,Object>> rowInList, 
														 | 
														
														 | 
														
															 	                                             List<Map<String,Object>> rowInList, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	                                             List<Map<String,Object>> rowInListWithAV){ 
														 | 
														
														 | 
														
															 	                                             List<Map<String,Object>> rowInListWithAV){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		// 判断出库物料在形态转换里的,把入库物料从形态转换设置成本。只取一层 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		do{ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			// 出库物料不在入库单里的物料,在形态转换单里 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			List<FabricMoOrderCK> findOutCanSetList = rowOutList.stream().filter(out->{ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				return rowInList.stream().filter(in-> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								in.get("cInvCode").toString().equals(out.getCInvCodeOut()) && 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								in.get("cColor").toString().equals(out.getCColorOut()) && 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								in.get("cBatch").toString().equals(out.getCBatchOut())).count()==0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			}).collect(Collectors.toList()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			// 找到金额为0的入库物料 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			List<Map<String,Object>> findInCanSetList = rowInList.stream().filter(in-> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					oConvertUtils.getDouble(in.get("iPurchuseMoney").toString(),0) == 0 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			).collect(Collectors.toList()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			// 根据委外订单子表id,找到入库物料 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			findInCanSetList = findInCanSetList.stream().filter(in->{ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				return findOutCanSetList.stream().filter(out-> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						oConvertUtils.getInt(in.get("MODetailsID")).equals(out.getMODetailsID())).count()>0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			}).collect(Collectors.toList()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			// 设置入库单金额 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			for (Map<String,Object> item : findInCanSetList){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// 本次入库加工费 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				Optional<Map<String,Object>> findRowInfoOpt = rowInfoList.stream().filter(info-> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						oConvertUtils.getInt(info.get("MODetailsID")).equals(oConvertUtils.getInt(item.get("MODetailsID"))) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				).findFirst(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				if (!findRowInfoOpt.isPresent()){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					continue; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				Map<String,Object> findRowInfo = findRowInfoOpt.get(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// 本次加工费用 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				Double iProcessFee = oConvertUtils.getDouble(findRowInfo.get("iProcessFee").toString(),0); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// 本次入库总数量 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				Double iQuantityIn = oConvertUtils.getDouble(findRowInfo.get("iQuantityIn").toString(),0); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// 出库材料费 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				Double iOutFee = 0.0; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				List<FabricMoOrderCK> findOutList = rowOutList.stream().filter(out->out.getMODetailsID().equals(oConvertUtils.getInt(item.get("MODetailsID")))).collect(Collectors.toList()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				for (FabricMoOrderCK itemOut : findOutList){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					Double outSum = itemOut.getIQuantityOut(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					// 获取出库的入库 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					List<Map<String,Object>> findInByOutList = rowInListWithAV.stream().filter(in-> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							in.get("cInvIdOut").equals(itemOut.getCInvCodeOut()+itemOut.getCColorOut()+itemOut.getCBatchOut())).collect(Collectors.toList()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					for (Map<String,Object> itemIn :findInByOutList){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						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; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						iOutFee += curSum*iPurchuseMoney/inSum; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						if (outSum<=0){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							break; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// 单价 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				Double iPrice = (iOutFee+iProcessFee)/iQuantityIn; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// 设置采购金额 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				item.put("iPurchuseMoney", iPrice*oConvertUtils.getDouble(item.get("iQuantity").toString(),0)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		}while(false); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		// 从最底层的物料向上逐级设置材料入库成本 
														 | 
														
														 | 
														
															 		// 从最底层的物料向上逐级设置材料入库成本 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		do { 
														 | 
														
														 | 
														
															 		do { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			// 可设置金额材料出库委外订单行id 
														 | 
														
														 | 
														
															 			// 可设置金额材料出库委外订单行id 
														 |