|
|
|
@ -822,7 +822,8 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
* 保证未拆分前 P_Qty 始终记录订单最初数量用于追溯;其余数量列(检验/发货)原行减量、新行承接,合计不变。 |
|
|
|
* 执行步骤: |
|
|
|
* 1) 校验入参,行锁读取原行数量快照,防止并发重复拆分; |
|
|
|
* 2) 拆分数量上界校验(订单数量按原行 A_Qty),四个过程数量按拆出 A_Qty / 原 A_Qty 比例拆; |
|
|
|
* 2) 拆分数量上界校验(订单数量按原行 A_Qty);检验申请数量取前端手工值, |
|
|
|
* 检验/通过/发货等过程数量按 拆分检验申请数量 / 原检验申请数量 比例拆(申请为0则过程数量全部留在原行); |
|
|
|
* 3) 验货申请子表口径校验并逐条拆分(最多1位小数,尾差调整保和,支持多条); |
|
|
|
* 4) 生成新 order_no(TransNoControl),复制原 POHeader 建新单头(po_no 沿用原值); |
|
|
|
* 5) 复制原行生成新单新行(order_no=新号、item_no=1、先套用可编辑字段覆盖再统一赋拆分数量/金额、order_ref2 重新分配保证唯一), |
|
|
|
@ -853,7 +854,8 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
throw new RuntimeException("未找到订单明细,请刷新后重试"); |
|
|
|
} |
|
|
|
String currentStatus = asText(snapshot.get("status")); |
|
|
|
if ("草稿".equals(currentStatus) || "已关闭".equals(currentStatus) || "已取消".equals(currentStatus)) { |
|
|
|
if ("草稿".equals(currentStatus) || "已关闭".equals(currentStatus) || "已取消".equals(currentStatus) |
|
|
|
|| "已发货".equals(currentStatus) || "完全发货".equals(currentStatus)) { |
|
|
|
throw new RuntimeException("当前状态不允许拆分:" + currentStatus); |
|
|
|
} |
|
|
|
BigDecimal origAQty = requireSnapshotAQty(snapshot); |
|
|
|
@ -863,14 +865,43 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
BigDecimal origToInspect = asDecimal(snapshot.get("toInspectQty")); |
|
|
|
requireOneDecimal(origAQty, "原行A_Qty"); |
|
|
|
|
|
|
|
// 2) 四个过程数量均按拆出 A_Qty / 原 A_Qty 分摊,新行保留一位小数,原行用原值相减。 |
|
|
|
// 2) 检验申请数量按前端手工值拆分;检验/通过/发货等过程数量跟随 |
|
|
|
// 「拆分检验申请数量 ÷ 原检验申请数量」比例迁移(申请数量为0时过程数量全部留在原行), |
|
|
|
// 避免按 A_Qty 比例带走的通过量无处挂载导致子明细配平失败。 |
|
|
|
if (splitQty.compareTo(origAQty) >= 0) { |
|
|
|
throw new RuntimeException("拆分订单数量必须小于原行A_Qty(" + formatQtyText(origAQty) + "),原行需保留数量"); |
|
|
|
} |
|
|
|
BigDecimal splitToInspect = splitProportionally(origToInspect, splitQty, origAQty, "检验申请数量"); |
|
|
|
BigDecimal newInspect = splitProportionally(origInspect, splitQty, origAQty, "检验数量"); |
|
|
|
BigDecimal newApprove = splitProportionally(origApprove, splitQty, origAQty, "检验完成数量"); |
|
|
|
BigDecimal splitShip = splitProportionally(origShip, splitQty, origAQty, "发货数量"); |
|
|
|
// 拆分检验申请数量由前端手工填写(可与拆分订单数量不同、可为0),不再按 A_Qty 等比例计算 |
|
|
|
BigDecimal splitToInspect = normalizeSplitNumber( |
|
|
|
model.getSplitToInspectQty() == null ? BigDecimal.ZERO : model.getSplitToInspectQty(), |
|
|
|
"拆分检验申请数量"); |
|
|
|
requireOneDecimal(splitToInspect, "拆分检验申请数量"); |
|
|
|
if (splitToInspect.compareTo(origToInspect) > 0) { |
|
|
|
throw new RuntimeException("拆分检验申请数量不能大于原行检验申请数量(" + formatQtyText(origToInspect) + ")"); |
|
|
|
} |
|
|
|
if (splitToInspect.compareTo(splitQty) > 0) { |
|
|
|
throw new RuntimeException("拆分检验申请数量不能大于拆分订单数量(" + formatQtyText(splitQty) + ")"); |
|
|
|
} |
|
|
|
// 下限:拆出订单量超出原行未申请检验部分时,超出量必须随订单拆出对应申请量, |
|
|
|
// 否则原行剩余 A_Qty 将不足以覆盖剩余有效验货占用(先拆未申请部分,再带申请量)。 |
|
|
|
BigDecimal minToInspect = splitQty.subtract(origAQty.subtract(origToInspect)).max(BigDecimal.ZERO); |
|
|
|
if (splitToInspect.compareTo(minToInspect) < 0) { |
|
|
|
throw new RuntimeException("拆分检验申请数量不能小于" + formatQtyText(minToInspect) |
|
|
|
+ "(拆分订单数量超出未申请检验的数量,需随订单拆出至少 " + formatQtyText(minToInspect) + " 申请量)"); |
|
|
|
} |
|
|
|
BigDecimal newInspect; |
|
|
|
BigDecimal newApprove; |
|
|
|
BigDecimal splitShip; |
|
|
|
if (origToInspect.signum() > 0) { |
|
|
|
newInspect = splitProportionally(origInspect, splitToInspect, origToInspect, "检验数量"); |
|
|
|
newApprove = splitProportionally(origApprove, splitToInspect, origToInspect, "检验完成数量"); |
|
|
|
splitShip = splitProportionally(origShip, splitToInspect, origToInspect, "发货数量"); |
|
|
|
} else { |
|
|
|
// 原行无检验申请(拆分检验申请数量只能为0):检验/通过/发货数量全部留在原行 |
|
|
|
newInspect = BigDecimal.ZERO; |
|
|
|
newApprove = BigDecimal.ZERO; |
|
|
|
splitShip = BigDecimal.ZERO; |
|
|
|
} |
|
|
|
BigDecimal remainAQty = origAQty.subtract(splitQty); |
|
|
|
BigDecimal remainToInspect = origToInspect.subtract(splitToInspect); |
|
|
|
BigDecimal remainInspect = origInspect.subtract(newInspect); |
|
|
|
@ -895,7 +926,7 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
POHeader newHeader = new POHeader(); |
|
|
|
BeanUtils.copyProperties(origHeader, newHeader); |
|
|
|
newHeader.setOrderNo(newOrderNo); |
|
|
|
newHeader.setStatus(currentStatus); |
|
|
|
newHeader.setStatus("已下达"); |
|
|
|
newHeader.setId(null); |
|
|
|
poHeaderMapper.insert(newHeader); |
|
|
|
Integer newHeaderId = resolveInsertedHeaderId(newHeader, site); |
|
|
|
@ -926,7 +957,7 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
splitDetail.setInspectApproveQty(newApprove); |
|
|
|
splitDetail.setValue(calculatePoValue(price, 0.0)); |
|
|
|
splitDetail.setSumPrice(calculateSumPrice(price, splitQty.doubleValue())); |
|
|
|
splitDetail.setStatus(currentStatus); |
|
|
|
splitDetail.setStatus("已下达"); |
|
|
|
splitDetail.setSourceOrderNo(orderNo); |
|
|
|
splitDetail.setSourceItemNo(itemNo); |
|
|
|
// po_no 复制原值 → order_ref1 沿用,order_ref2 需在新单下重新分配以保证外部订单行号唯一 |
|
|
|
@ -955,14 +986,21 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
if (updateCount == 0) { |
|
|
|
throw new RuntimeException("拆分提交失败,请刷新后重试"); |
|
|
|
} |
|
|
|
// 7) 子表按同一比例逐条拆分,原行用原值相减以消除尾差。 |
|
|
|
moveSplitInspectionSubs(subs, splitQty, origAQty, splitToInspect, newApprove, |
|
|
|
// 7) 子表按拆分检验申请数量比例逐条拆分,原行用原值相减以消除尾差; |
|
|
|
// 分母改用原检验申请数量,与上方过程数量口径保持一致(原申请为0时退回 A_Qty 口径,此时子明细均为零数量)。 |
|
|
|
moveSplitInspectionSubs(subs, |
|
|
|
origToInspect.signum() > 0 ? splitToInspect : splitQty, |
|
|
|
origToInspect.signum() > 0 ? origToInspect : origAQty, |
|
|
|
splitToInspect, newApprove, |
|
|
|
newOrderNo, splitDetail.getOrderRef1(), newRef2); |
|
|
|
|
|
|
|
// 子明细分配完成后,按两行各自仍在进行的验货申请和过程数量计算状态。 |
|
|
|
String splitStatus = PoDetailStatusSupport.resolveStatusAfterSplit(splitQty, |
|
|
|
splitToInspect, newInspect, newApprove, splitShip, |
|
|
|
hasInspectingRequest(site, newOrderNo, 1)); |
|
|
|
// 拆分生成的新订单:带出检验申请数量>0 时按新行数量重算(验货中/待验货等), |
|
|
|
// 未带申请(拆出纯未验货量)时保持「已下达」,便于直接重新发起验货申请;原行始终按过程数量重算。 |
|
|
|
String splitStatus = splitToInspect.signum() > 0 |
|
|
|
? PoDetailStatusSupport.resolveStatusAfterSplit(splitQty, splitToInspect, newInspect, |
|
|
|
newApprove, splitShip, hasInspectingRequest(site, newOrderNo, splitDetail.getItemNo())) |
|
|
|
: "已下达"; |
|
|
|
String remainStatus = PoDetailStatusSupport.resolveStatusAfterSplit(remainAQty, |
|
|
|
remainToInspect, remainInspect, remainApprove, remainShip, |
|
|
|
hasInspectingRequest(site, orderNo, itemNo)); |
|
|
|
@ -1008,7 +1046,8 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
throw new RuntimeException("未找到订单明细,请刷新后重试"); |
|
|
|
} |
|
|
|
String currentStatus = asText(snapshot.get("status")); |
|
|
|
if ("草稿".equals(currentStatus) || "已关闭".equals(currentStatus) || "已取消".equals(currentStatus)) { |
|
|
|
if ("草稿".equals(currentStatus) || "已关闭".equals(currentStatus) || "已取消".equals(currentStatus) |
|
|
|
|| "已发货".equals(currentStatus) || "完全发货".equals(currentStatus)) { |
|
|
|
throw new RuntimeException("当前状态不允许拆单:" + currentStatus); |
|
|
|
} |
|
|
|
BigDecimal origAQty = requireSnapshotAQty(snapshot); |
|
|
|
@ -1064,7 +1103,7 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
BeanUtils.copyProperties(origHeader, newHeader); |
|
|
|
newHeader.setOrderNo(newOrderNo); |
|
|
|
newHeader.setPoNo(targetPoNo); |
|
|
|
newHeader.setStatus(currentStatus); |
|
|
|
newHeader.setStatus("已下达"); |
|
|
|
newHeader.setId(null); |
|
|
|
poHeaderMapper.insert(newHeader); |
|
|
|
Integer newHeaderId = resolveInsertedHeaderId(newHeader, site); |
|
|
|
@ -1082,7 +1121,7 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
newDetail.setPoHeaderId(newHeaderId); |
|
|
|
newDetail.setQty(splitQty.doubleValue()); |
|
|
|
newDetail.setAQty(splitQty.doubleValue()); |
|
|
|
newDetail.setStatus(currentStatus); |
|
|
|
newDetail.setStatus("已下达"); |
|
|
|
newDetail.setToInspectQty(newToInspect); |
|
|
|
newDetail.setInspectQty(newInspect.doubleValue()); |
|
|
|
newDetail.setInspectApproveQty(newApprove); |
|
|
|
@ -1121,9 +1160,12 @@ public class PODetailServiceImpl extends ServiceImpl<PODetailMapper, PODetail> i |
|
|
|
moveSplitInspectionSubs(subs, splitQty, origAQty, newToInspect, newApprove, |
|
|
|
newOrderNo, targetPoNo, newRef2); |
|
|
|
|
|
|
|
String newStatus = PoDetailStatusSupport.resolveStatusAfterSplit(splitQty, |
|
|
|
newToInspect, newInspect, newApprove, newShip, |
|
|
|
hasInspectingRequest(site, newOrderNo, 1)); |
|
|
|
// 拆分生成的新订单:带出检验申请数量>0 时按新行数量重算状态(验货中/待验货等), |
|
|
|
// 未带申请时保持「已下达」(原行仍按过程数量重算状态) |
|
|
|
String newStatus = newToInspect.signum() > 0 |
|
|
|
? PoDetailStatusSupport.resolveStatusAfterSplit(splitQty, newToInspect, newInspect, |
|
|
|
newApprove, newShip, hasInspectingRequest(site, newOrderNo, newDetail.getItemNo())) |
|
|
|
: "已下达"; |
|
|
|
String remainStatus = PoDetailStatusSupport.resolveStatusAfterSplit(remainAQty, |
|
|
|
remainToInspect, remainInspect, remainApprove, remainShip, |
|
|
|
hasInspectingRequest(site, orderNo, itemNo)); |
|
|
|
|