Added support for discounts in the POS checkout process, allowing operators to apply either a fixed amount or a percentage off the gross total. Updated the state management to include discount details and modified the receipt and cart rendering to display pre- and post-discount values. Enhanced the checkout API to handle discount inputs and ensure proper calculations. Updated relevant tests to cover new discount logic.
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { Printer } from "lucide-react";
|
|
|
|
/**
|
|
* The "Print this page" button on the SOP print routes.
|
|
*
|
|
* - On mount, if `auto` is true, calls `window.print()` after a short
|
|
* delay so the page has a chance to render fonts/layout.
|
|
* - Always renders a visible button the user can click to re-trigger
|
|
* the print dialog (useful if they closed it accidentally).
|
|
*
|
|
* The button is hidden in the printed output via the
|
|
* `.sop-print-actions { display: none }` rule inside @media print
|
|
* in globals.css.
|
|
*/
|
|
export function SopPrintTrigger({
|
|
label = "Print this page",
|
|
auto = false,
|
|
}: {
|
|
label?: string;
|
|
auto?: boolean;
|
|
}) {
|
|
useEffect(() => {
|
|
if (!auto) return;
|
|
// Wait for fonts / images to settle before opening the dialog.
|
|
const t = setTimeout(() => {
|
|
try {
|
|
window.print();
|
|
} catch {
|
|
// Ignore — the user can still click the button.
|
|
}
|
|
}, 400);
|
|
return () => clearTimeout(t);
|
|
}, [auto]);
|
|
|
|
return (
|
|
<div className="sop-print-actions">
|
|
<Printer className="h-4 w-4" aria-hidden />
|
|
<span>
|
|
Use your browser’s <strong>Print → Save as PDF</strong> to
|
|
save this SOP as a PDF file.
|
|
</span>
|
|
<button type="button" onClick={() => window.print()}>
|
|
{label}
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|