| @@ -94,9 +94,9 @@ const PickExecutionForm: React.FC<PickExecutionFormProps> = ({ | |||||
| const missSet = formData.missQty != null; | const missSet = formData.missQty != null; | ||||
| const badItemSet = formData.badItemQty != null; | const badItemSet = formData.badItemQty != null; | ||||
| const badPackageSet = (formData as any).badPackageQty != null; | const badPackageSet = (formData as any).badPackageQty != null; | ||||
| const calculateRemainingAvailableQty = useCallback((lot: LotPickData) => { | |||||
| return lot.availableQty || 0; | |||||
| }, []); | |||||
| const calculateRemainingAvailableQty = useCallback((lot: LotPickData) => { | |||||
| return (lot.availableQty + lot.requiredQty ) || 0; | |||||
| }, []); | |||||
| const calculateRequiredQty = useCallback((lot: LotPickData) => { | const calculateRequiredQty = useCallback((lot: LotPickData) => { | ||||
| // Use the original required quantity, not subtracting actualPickQty | // Use the original required quantity, not subtracting actualPickQty | ||||
| // The actualPickQty in the form should be independent of the database value | // The actualPickQty in the form should be independent of the database value | ||||
| @@ -203,14 +203,14 @@ useEffect(() => { | |||||
| const totalBadQty = badItem + badPackage; | const totalBadQty = badItem + badPackage; | ||||
| const total = ap + miss + totalBadQty; | const total = ap + miss + totalBadQty; | ||||
| const availableQty = selectedLot?.availableQty || 0; | const availableQty = selectedLot?.availableQty || 0; | ||||
| const maxActual = requiredQty + availableQty; | |||||
| // 1. Check actualPickQty cannot be negative | // 1. Check actualPickQty cannot be negative | ||||
| if (ap < 0) { | if (ap < 0) { | ||||
| newErrors.actualPickQty = t("Qty cannot be negative"); | newErrors.actualPickQty = t("Qty cannot be negative"); | ||||
| } | } | ||||
| // 2. Check actualPickQty cannot exceed available quantity | // 2. Check actualPickQty cannot exceed available quantity | ||||
| if (ap > availableQty) { | |||||
| if (ap > maxActual) { | |||||
| newErrors.actualPickQty = t("Actual pick qty cannot exceed available qty"); | newErrors.actualPickQty = t("Actual pick qty cannot exceed available qty"); | ||||
| } | } | ||||
| @@ -223,10 +223,10 @@ useEffect(() => { | |||||
| } | } | ||||
| // 4. Total (actualPickQty + missQty + badItemQty + badPackageQty) cannot exceed lot available qty | // 4. Total (actualPickQty + missQty + badItemQty + badPackageQty) cannot exceed lot available qty | ||||
| if (total > availableQty) { | |||||
| if (total > maxActual) { | |||||
| const errorMsg = t( | const errorMsg = t( | ||||
| "Total qty (actual pick + miss + bad) cannot exceed available qty: {available}", | "Total qty (actual pick + miss + bad) cannot exceed available qty: {available}", | ||||
| { available: availableQty } | |||||
| { available: maxActual } | |||||
| ); | ); | ||||
| newErrors.actualPickQty = errorMsg; | newErrors.actualPickQty = errorMsg; | ||||
| newErrors.missQty = errorMsg; | newErrors.missQty = errorMsg; | ||||
| @@ -322,6 +322,8 @@ useEffect(() => { | |||||
| const remainingAvailableQty = calculateRemainingAvailableQty(selectedLot); | const remainingAvailableQty = calculateRemainingAvailableQty(selectedLot); | ||||
| const requiredQty = calculateRequiredQty(selectedLot); | const requiredQty = calculateRequiredQty(selectedLot); | ||||
| const availableQty = selectedLot?.availableQty || 0; | |||||
| const maxActual = requiredQty + availableQty; | |||||
| return ( | return ( | ||||
| <Dialog open={open} onClose={handleClose} maxWidth="sm" fullWidth> | <Dialog open={open} onClose={handleClose} maxWidth="sm" fullWidth> | ||||
| <DialogTitle> | <DialogTitle> | ||||