|
|
|
@@ -34,7 +34,11 @@ import PickerBatchSaveFab from "./PickerBatchSaveFab"; |
|
|
|
import { useSession } from "next-auth/react"; |
|
|
|
import { SessionWithTokens } from "@/config/authConfig"; |
|
|
|
import dayjs from "dayjs"; |
|
|
|
import { OUTPUT_DATE_FORMAT } from "@/app/utils/formatUtil"; |
|
|
|
import { |
|
|
|
OUTPUT_DATE_FORMAT, |
|
|
|
sanitizeStockTakeQtyInput, |
|
|
|
validateStockTakeQtyString, |
|
|
|
} from "@/app/utils/formatUtil"; |
|
|
|
|
|
|
|
interface PickerReStockTakeProps { |
|
|
|
selectedSession: AllPickedStockTakeListReponse; |
|
|
|
@@ -81,11 +85,6 @@ const PickerReStockTake: React.FC<PickerReStockTakeProps> = ({ |
|
|
|
e.preventDefault(); |
|
|
|
} |
|
|
|
}; |
|
|
|
const sanitizeIntegerInput = (value: string) => { |
|
|
|
// 只保留数字 |
|
|
|
return value.replace(/[^\d]/g, ""); |
|
|
|
}; |
|
|
|
const isIntegerString = (value: string) => /^\d+$/.test(value); |
|
|
|
const handleChangeRowsPerPage = useCallback((event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { |
|
|
|
const newSize = parseInt(event.target.value, 10); |
|
|
|
if (newSize === -1) { |
|
|
|
@@ -209,28 +208,36 @@ const PickerReStockTake: React.FC<PickerReStockTakeProps> = ({ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const totalQty = parseFloat(totalQtyStr); |
|
|
|
const badQty = parseFloat(badQtyStr || "0") || 0; |
|
|
|
|
|
|
|
if (Number.isNaN(totalQty)) { |
|
|
|
onSnackbar(t("Invalid QTY"), "error"); |
|
|
|
const totalValidated = validateStockTakeQtyString(totalQtyStr); |
|
|
|
if (!totalValidated.ok) { |
|
|
|
onSnackbar(t(totalValidated.errorKey), "error"); |
|
|
|
return; |
|
|
|
} |
|
|
|
const badValidated = validateStockTakeQtyString(badQtyStr, { allowEmpty: true }); |
|
|
|
if (!badValidated.ok) { |
|
|
|
onSnackbar(t(badValidated.errorKey), "error"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const availableQty = totalQty - badQty; |
|
|
|
const availableQty = totalValidated.qty - badValidated.qty; |
|
|
|
|
|
|
|
if (availableQty < 0) { |
|
|
|
onSnackbar(t("Available QTY cannot be negative"), "error"); |
|
|
|
return; |
|
|
|
} |
|
|
|
const availableValidated = validateStockTakeQtyString(String(availableQty)); |
|
|
|
if (!availableValidated.ok) { |
|
|
|
onSnackbar(t(availableValidated.errorKey), "error"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
setSaving(true); |
|
|
|
try { |
|
|
|
const request: SaveStockTakeRecordRequest = { |
|
|
|
stockTakeRecordId: detail.stockTakeRecordId || null, |
|
|
|
inventoryLotLineId: detail.id, |
|
|
|
qty: availableQty, |
|
|
|
badQty: badQty, |
|
|
|
qty: availableValidated.qty, |
|
|
|
badQty: badValidated.qty, |
|
|
|
remark: isSecondSubmit ? (recordInputs[detail.id]?.remark || null) : null, |
|
|
|
}; |
|
|
|
const result = await saveStockTakeRecord( |
|
|
|
@@ -536,7 +543,7 @@ const PickerReStockTake: React.FC<PickerReStockTakeProps> = ({ |
|
|
|
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} |
|
|
|
onKeyDown={blockNonIntegerKeys} |
|
|
|
onChange={(e) => { |
|
|
|
const clean = sanitizeIntegerInput(e.target.value); |
|
|
|
const clean = sanitizeStockTakeQtyInput(e.target.value); |
|
|
|
const val = clean; |
|
|
|
if (val.includes("-")) return; |
|
|
|
setRecordInputs(prev => ({ |
|
|
|
@@ -562,7 +569,7 @@ const PickerReStockTake: React.FC<PickerReStockTakeProps> = ({ |
|
|
|
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} |
|
|
|
onKeyDown={blockNonIntegerKeys} |
|
|
|
onChange={(e) => { |
|
|
|
const clean = sanitizeIntegerInput(e.target.value); |
|
|
|
const clean = sanitizeStockTakeQtyInput(e.target.value); |
|
|
|
const val = clean; |
|
|
|
if (val.includes("-")) return; |
|
|
|
setRecordInputs(prev => ({ |
|
|
|
@@ -606,7 +613,7 @@ const PickerReStockTake: React.FC<PickerReStockTakeProps> = ({ |
|
|
|
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} |
|
|
|
onKeyDown={blockNonIntegerKeys} |
|
|
|
onChange={(e) => { |
|
|
|
const clean = sanitizeIntegerInput(e.target.value); |
|
|
|
const clean = sanitizeStockTakeQtyInput(e.target.value); |
|
|
|
const val = clean; |
|
|
|
if (val.includes("-")) return; |
|
|
|
setRecordInputs(prev => ({ |
|
|
|
@@ -632,7 +639,7 @@ const PickerReStockTake: React.FC<PickerReStockTakeProps> = ({ |
|
|
|
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} |
|
|
|
onKeyDown={blockNonIntegerKeys} |
|
|
|
onChange={(e) => { |
|
|
|
const clean = sanitizeIntegerInput(e.target.value); |
|
|
|
const clean = sanitizeStockTakeQtyInput(e.target.value); |
|
|
|
const val = clean; |
|
|
|
if (val.includes("-")) return; |
|
|
|
setRecordInputs(prev => ({ |
|
|
|
|