feat: residues accounting
This commit is contained in:
31
src/pages/ResiduesPage/hooks/useResiduesPdf.tsx
Normal file
31
src/pages/ResiduesPage/hooks/useResiduesPdf.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useResiduesContext } from "../contexts/ResiduesContext.tsx";
|
||||
import { notifications } from "../../../shared/lib/notifications.ts";
|
||||
|
||||
const useResiduesPdf = () => {
|
||||
const { palletIdsToPrint, boxIdsToPrint } = useResiduesContext();
|
||||
|
||||
const basePdfUrl = `${import.meta.env.VITE_API_URL}/residues/pdf`;
|
||||
|
||||
const getPdf = (url: string) => {
|
||||
const pdfWindow = window.open(url);
|
||||
if (!pdfWindow) return;
|
||||
pdfWindow.print();
|
||||
};
|
||||
|
||||
const onGetPalletsPdfClick = () => {
|
||||
if (palletIdsToPrint.size === 0 && boxIdsToPrint.size === 0) {
|
||||
notifications.show({ message: "Не выбран ни один элемент для печати "});
|
||||
return;
|
||||
}
|
||||
|
||||
const palletIdsStr = palletIdsToPrint.values().toArray().join(",")
|
||||
const boxIdsStr = boxIdsToPrint.values().toArray().join(",")
|
||||
getPdf(`${basePdfUrl}/?pallet_ids=${palletIdsStr}&box_ids=${boxIdsStr}`);
|
||||
};
|
||||
|
||||
return {
|
||||
onGetPalletsPdfClick,
|
||||
};
|
||||
};
|
||||
|
||||
export default useResiduesPdf;
|
||||
Reference in New Issue
Block a user