|
|
|
@@ -89,6 +89,22 @@ const QcStockInModal: React.FC<Props> = ({ |
|
|
|
// const [viewOnly, setViewOnly] = useState(false); |
|
|
|
|
|
|
|
// Select Printer |
|
|
|
const getDefaultPrinter = useMemo(() => { |
|
|
|
if (typeof window === 'undefined' || printerCombo.length === 0) { |
|
|
|
return printerCombo[0]; |
|
|
|
} |
|
|
|
|
|
|
|
const savedPrinterId = localStorage.getItem('qcStockInModal_selectedPrinterId'); |
|
|
|
if (savedPrinterId) { |
|
|
|
const savedId = Number(savedPrinterId); |
|
|
|
const foundPrinter = printerCombo.find(p => p.id === savedId); |
|
|
|
if (foundPrinter) { |
|
|
|
return foundPrinter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return printerCombo[0]; |
|
|
|
}, [printerCombo]); |
|
|
|
const [selectedPrinter, setSelectedPrinter] = useState(printerCombo[0]); |
|
|
|
const [printQty, setPrintQty] = useState(1); |
|
|
|
const [tabIndex, setTabIndex] = useState(0); |
|
|
|
@@ -457,6 +473,24 @@ const QcStockInModal: React.FC<Props> = ({ |
|
|
|
[closeHandler], |
|
|
|
); |
|
|
|
// Print handler |
|
|
|
useEffect(() => { |
|
|
|
if (printerCombo.length > 0) { |
|
|
|
const savedPrinterId = typeof window !== 'undefined' |
|
|
|
? localStorage.getItem('qcStockInModal_selectedPrinterId') |
|
|
|
: null; |
|
|
|
|
|
|
|
if (savedPrinterId) { |
|
|
|
const savedId = Number(savedPrinterId); |
|
|
|
const foundPrinter = printerCombo.find(p => p.id === savedId); |
|
|
|
if (foundPrinter) { |
|
|
|
setSelectedPrinter(foundPrinter); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
setSelectedPrinter(printerCombo[0]); |
|
|
|
} |
|
|
|
}, [printerCombo]); |
|
|
|
const [isPrinting, setIsPrinting] = useState(false) |
|
|
|
const handlePrint = useCallback(async () => { |
|
|
|
// console.log("Print putaway documents"); |
|
|
|
@@ -487,6 +521,9 @@ const QcStockInModal: React.FC<Props> = ({ |
|
|
|
if (response) { |
|
|
|
console.log(response) |
|
|
|
} |
|
|
|
if (typeof window !== 'undefined' && selectedPrinter) { |
|
|
|
localStorage.setItem('qcStockInModal_selectedPrinterId', String(selectedPrinter.id)); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
setIsPrinting(() => false) |
|
|
|
} |
|
|
|
|