Showing
1 changed file
with
24 additions
and
8 deletions
| ... | ... | @@ -120,10 +120,6 @@ public class ProcurementWarehouseReceiveOrderServiceImpl |
| 120 | 120 | */ |
| 121 | 121 | private static final String BPM_FLAG = "RECEIVE_ORDER"; |
| 122 | 122 | /** |
| 123 | - * 结算类型-买断 | |
| 124 | - */ | |
| 125 | - private static final String SETTLE_TYPE_BUYOUT = "买断"; | |
| 126 | - /** | |
| 127 | 123 | * 两日网价均差提醒阈值 |
| 128 | 124 | */ |
| 129 | 125 | private static final BigDecimal PRICE_WARN_THRESHOLD = new BigDecimal("800"); |
| ... | ... | @@ -293,7 +289,16 @@ public class ProcurementWarehouseReceiveOrderServiceImpl |
| 293 | 289 | bo.setSettleType(settle.getSettleType()); |
| 294 | 290 | |
| 295 | 291 | // 明细自动计算:没有类别(category)的结算明细行不代入 |
| 296 | - boolean buyout = settle.getSettleType() != null && settle.getSettleType().contains(SETTLE_TYPE_BUYOUT); | |
| 292 | + List<ProcurementMaterialSettleLine> settleLines = settleLineService.getBySettleDetailId(settleDetailId); | |
| 293 | + // 明细行关联的采购计划(行计划ID -> 计划),是否买断按计划的数量/质量/通货买断判定,与结算详情单 settleType 无关 | |
| 294 | + List<String> planIds = settleLines.stream() | |
| 295 | + .filter(l -> l != null && StringUtil.isNotBlank(l.getProcurementPlanId())) | |
| 296 | + .map(ProcurementMaterialSettleLine::getProcurementPlanId) | |
| 297 | + .distinct() | |
| 298 | + .collect(Collectors.toList()); | |
| 299 | + Map<String, ProcurementPlan> planMap = planIds.isEmpty() ? Collections.emptyMap() | |
| 300 | + : procurementPlanService.listByIds(planIds).stream() | |
| 301 | + .collect(Collectors.toMap(ProcurementPlan::getId, p -> p, (a, b) -> a)); | |
| 297 | 302 | // 申请净重(品种关系ID -> 合计申请净重),买断采购数 = 申请净重 - 退料 - 折斤 |
| 298 | 303 | Map<String, BigDecimal> applyQuantityMap = settleApplyLineService.getBySettleDetailId(settleDetailId) |
| 299 | 304 | .stream() |
| ... | ... | @@ -301,7 +306,6 @@ public class ProcurementWarehouseReceiveOrderServiceImpl |
| 301 | 306 | .collect(Collectors.toMap(ProcurementMaterialSettleApplyLine::getBreedRelationshipId, |
| 302 | 307 | ProcurementMaterialSettleApplyLine::getQuantity, BigDecimal::add)); |
| 303 | 308 | |
| 304 | - List<ProcurementMaterialSettleLine> settleLines = settleLineService.getBySettleDetailId(settleDetailId); | |
| 305 | 309 | for (ProcurementMaterialSettleLine settleLine : settleLines) { |
| 306 | 310 | if (settleLine == null || StringUtil.isBlank(settleLine.getCategory())) { |
| 307 | 311 | // 没有类别的不代入 |
| ... | ... | @@ -315,7 +319,8 @@ public class ProcurementWarehouseReceiveOrderServiceImpl |
| 315 | 319 | lineVo.setName(settleLine.getName()); |
| 316 | 320 | lineVo.setUnit("kg"); |
| 317 | 321 | lineVo.setSettleType(settle.getSettleType()); |
| 318 | - lineVo.setPurchaseQuantity(calcPurchaseQuantity(buyout, settleLine, applyQuantityMap)); | |
| 322 | + lineVo.setPurchaseQuantity(calcPurchaseQuantity(isBuyoutPlan(planMap.get(settleLine.getProcurementPlanId())), | |
| 323 | + settleLine, applyQuantityMap)); | |
| 319 | 324 | lineVo.setActualQuantity(settleLine.getNetWeight()); |
| 320 | 325 | lineVo.setTaxPrice(resolveTaxPrice(settleLine)); |
| 321 | 326 | if (lineVo.getTaxPrice() != null && lineVo.getPurchaseQuantity() != null) { |
| ... | ... | @@ -744,7 +749,18 @@ public class ProcurementWarehouseReceiveOrderServiceImpl |
| 744 | 749 | } |
| 745 | 750 | |
| 746 | 751 | /** |
| 747 | - * 采购数:买断 = 申请净重 - 退料 - 折斤(对应关系缺失则为空);经销 = 入库净重 | |
| 752 | + * 计划是否买断:数量买断/质量买断/通货买断任一为真即买断;计划不存在视为经销 | |
| 753 | + */ | |
| 754 | + private boolean isBuyoutPlan(ProcurementPlan plan) { | |
| 755 | + if (plan == null) { | |
| 756 | + return false; | |
| 757 | + } | |
| 758 | + return Boolean.TRUE.equals(plan.getQuantityBuyout()) || Boolean.TRUE.equals(plan.getQualityBuyout()) | |
| 759 | + || Boolean.TRUE.equals(plan.getCommodityBuyout()); | |
| 760 | + } | |
| 761 | + | |
| 762 | + /** | |
| 763 | + * 采购数:买断(按行关联计划判定)= 申请净重 - 退料 - 折斤(对应关系缺失则为空);经销 = 入库净重 | |
| 748 | 764 | */ |
| 749 | 765 | private BigDecimal calcPurchaseQuantity(boolean buyout, ProcurementMaterialSettleLine settleLine, |
| 750 | 766 | Map<String, BigDecimal> applyQuantityMap) { | ... | ... |