|
|
|
@@ -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); |
|
|
|
|