diff --git a/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx b/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx index b65f45a..828bfa3 100644 --- a/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx +++ b/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx @@ -798,8 +798,22 @@ const [isConfirmingLot, setIsConfirmingLot] = useState(false); return; } - // 2) Check if scanned lot is exactly in expected lots - const exactLotMatch = sameItemLotsInExpected.find(l => + // ✅ FIXED: Find the ACTIVE suggested lot (not rejected lots) + const activeSuggestedLots = sameItemLotsInExpected.filter(lot => + lot.lotAvailability !== 'rejected' && + lot.stockOutLineStatus !== 'rejected' && + lot.processingStatus !== 'rejected' + ); + + if (activeSuggestedLots.length === 0) { + console.error("No active suggested lots found for this item"); + setQrScanError(true); + setQrScanSuccess(false); + return; + } + + // 2) Check if scanned lot is exactly in active suggested lots + const exactLotMatch = activeSuggestedLots.find(l => (scanned?.inventoryLotLineId && l.lotId === scanned.inventoryLotLineId) || (scanned?.lotNo && l.lotNo === scanned.lotNo) ); @@ -812,7 +826,8 @@ const [isConfirmingLot, setIsConfirmingLot] = useState(false); } // Case 2: Item matches but lot number differs -> open confirmation modal - const expectedLot = sameItemLotsInExpected[0]; + // ✅ FIXED: Use the first ACTIVE suggested lot, not just any lot + const expectedLot = activeSuggestedLots[0]; if (!expectedLot) { console.error("Could not determine expected lot for confirmation"); setQrScanError(true); @@ -827,6 +842,7 @@ const [isConfirmingLot, setIsConfirmingLot] = useState(false); return; } + console.log(`🔍 Lot mismatch: Expected ${expectedLot.lotNo}, Scanned ${scanned?.lotNo}`); setSelectedLotForQr(expectedLot); handleLotMismatch( { @@ -1134,7 +1150,14 @@ useEffect(() => { setPickExecutionFormOpen(false); setSelectedLotForExecutionForm(null); - + setQrScanError(false); + setQrScanSuccess(false); + setQrScanInput(''); + setIsManualScanning(false); + stopScan(); + resetScan(); + setProcessedQrCodes(new Set()); + setLastProcessedQr(''); await fetchAllCombinedLotData(); } catch (error) { console.error("Error submitting pick execution form:", error); diff --git a/src/i18n/zh/do.json b/src/i18n/zh/do.json index 9c0d2dc..dd77532 100644 --- a/src/i18n/zh/do.json +++ b/src/i18n/zh/do.json @@ -43,5 +43,6 @@ "Back": "返回", "Batch Release": "批量放單", "Batch release completed successfully.": "已完成批量放單", - "Edit Delivery Order Detail": "編輯交貨單詳情" + "Edit Delivery Order Detail": "編輯交貨單詳情", + "DO released successfully! Pick orders created.": "交貨單放單成功!提料單已建立。" } \ No newline at end of file