| @@ -923,7 +923,9 @@ const fetchAllCombinedLotData = useCallback(async (userId?: number, pickOrderIdO | |||||
| pickOrderLinesForDisplay.forEach((line: any) => { | pickOrderLinesForDisplay.forEach((line: any) => { | ||||
| // 用来记录这一行已经通过 lots 出现过的 lotId | // 用来记录这一行已经通过 lots 出现过的 lotId | ||||
| const lotIdSet = new Set<number>(); | const lotIdSet = new Set<number>(); | ||||
| /** 已由有批次建議分配的量(加總後與 pick_order_line.requiredQty 的差額 = 無批次列應顯示的數) */ | |||||
| let lotsAllocatedSumForLine = 0; | |||||
| // ✅ lots:按 lotId 去重并合并 requiredQty | // ✅ lots:按 lotId 去重并合并 requiredQty | ||||
| if (line.lots && line.lots.length > 0) { | if (line.lots && line.lots.length > 0) { | ||||
| const lotMap = new Map<number, any>(); | const lotMap = new Map<number, any>(); | ||||
| @@ -940,6 +942,7 @@ const fetchAllCombinedLotData = useCallback(async (userId?: number, pickOrderIdO | |||||
| }); | }); | ||||
| lotMap.forEach((lot: any) => { | lotMap.forEach((lot: any) => { | ||||
| lotsAllocatedSumForLine += Number(lot.requiredQty) || 0; | |||||
| if (lot.id != null) { | if (lot.id != null) { | ||||
| lotIdSet.add(lot.id); | lotIdSet.add(lot.id); | ||||
| } | } | ||||
| @@ -1029,7 +1032,13 @@ const fetchAllCombinedLotData = useCallback(async (userId?: number, pickOrderIdO | |||||
| location: stockout.location || null, | location: stockout.location || null, | ||||
| stockUnit: line.item.uomDesc, | stockUnit: line.item.uomDesc, | ||||
| availableQty: stockout.availableQty || 0, | availableQty: stockout.availableQty || 0, | ||||
| requiredQty: line.requiredQty, | |||||
| // 無批次列對應 suggested_pick_lot 的缺口量(如 11),勿用整行 POL 需求(100)以免顯示成 89 / 100 | |||||
| requiredQty: stockout.noLot | |||||
| ? Math.max( | |||||
| 0, | |||||
| (Number(line.requiredQty) || 0) - lotsAllocatedSumForLine | |||||
| ) | |||||
| : Number(line.requiredQty) || 0, | |||||
| actualPickQty: stockout.qty || 0, | actualPickQty: stockout.qty || 0, | ||||
| inQty: 0, | inQty: 0, | ||||
| outQty: 0, | outQty: 0, | ||||