QR Code Fast Scan with Auto Quantity

This commit is contained in:
Srinath 2026-01-28 15:44:26 +05:30
parent 0fc07aaeac
commit 5c6e5fd9be
1 changed files with 29 additions and 1 deletions

View File

@ -127,6 +127,9 @@ export default function BSC1Search(props) {
const [QuickAdd, setQuickAdd] = useState(false); const [QuickAdd, setQuickAdd] = useState(false);
const inputRef = useRef(null); const inputRef = useRef(null);
const containerRef = useRef(null); const containerRef = useRef(null);
// QR code tracking
const [lastScannedQr, setLastScannedQr] = useState(null);
const [currentSessionQr, setCurrentSessionQr] = useState(null);
const focusStatusCustMouse = useSelector(GlobalfocusStatusCustMouse); const focusStatusCustMouse = useSelector(GlobalfocusStatusCustMouse);
const CompoPaymentIconStatus = useSelector(GlobalCompoPaymentIconStatus); const CompoPaymentIconStatus = useSelector(GlobalCompoPaymentIconStatus);
const CompoPreOrderDtlStatus = useSelector(GlobalCompoPreOrderDtlStatus); const CompoPreOrderDtlStatus = useSelector(GlobalCompoPreOrderDtlStatus);
@ -432,6 +435,14 @@ export default function BSC1Search(props) {
stopScannerFromParent(); stopScannerFromParent();
}; };
// Clear QR tracker function
const clearQrTracker = () => {
setLastScannedQr(null);
setCurrentSessionQr(null);
};
const ProductNameOnChange = (data) => { const ProductNameOnChange = (data) => {
if (isSelectingRef.current) { if (isSelectingRef.current) {
isSelectingRef.current = false; isSelectingRef.current = false;
@ -447,8 +458,22 @@ export default function BSC1Search(props) {
} }
await dispatch(changeSearchedData(data)); await dispatch(changeSearchedData(data));
// If same QR as current session, just add quantity
if (currentSessionQr === data) {
if (lastScannedQr) {
const updatedProduct = {
...lastScannedQr,
OrderQty: (lastScannedQr.OrderQty || 1) + 1,
Quantity: (lastScannedQr.Quantity || 1) + 1
};
ProductSelected(updatedProduct);
}
return;
}
try { try {
// 🚀 Dispatch API // 🚀 Call API for new session QR code
searchPromiseRef.current = dispatch( searchPromiseRef.current = dispatch(
getProductsearch({ getProductsearch({
CompId, CompId,
@ -467,6 +492,9 @@ export default function BSC1Search(props) {
ApiSearchData?.QrBasedSearch === 'Y' || ApiSearchData?.QrBasedSearch === 'Y' ||
ApiSearchData?.OnePcQRBased === 'Y' ApiSearchData?.OnePcQRBased === 'Y'
) { ) {
setCurrentSessionQr(data);
setLastScannedQr(ApiSearchData);
ProductSelected(ApiSearchData); ProductSelected(ApiSearchData);
setQuickAdd(false); setQuickAdd(false);
} else if (!ApiSearchData.ProdId && ApiSearchData?.AppId == 0) { } else if (!ApiSearchData.ProdId && ApiSearchData?.AppId == 0) {