diff --git a/web/dashboard/src/components/pos2/pos2-screen.tsx b/web/dashboard/src/components/pos2/pos2-screen.tsx index 46bc291..06397dd 100644 --- a/web/dashboard/src/components/pos2/pos2-screen.tsx +++ b/web/dashboard/src/components/pos2/pos2-screen.tsx @@ -121,6 +121,8 @@ export function Pos2Screen() { const [busy, setBusy] = useState(false); const [payTarget, setPayTarget] = useState(null); const [payLoyalty, setPayLoyalty] = useState(0); + // Order just paid — kept after the cart is cleared so the receipt stays printable. + const [paidOrderId, setPaidOrderId] = useState(null); const [online, setOnline] = useState(true); useEffect(() => { @@ -287,13 +289,14 @@ export function Pos2Screen() { loyaltyPointsToRedeem: loyaltyRedeem > 0 ? loyaltyRedeem : undefined, }); const paid = payments.reduce((s, p) => s + p.amount, 0); - const paidOrderId = payTarget.id; - notify.success(`پرداخت ${fmt(paid)} تومان ثبت شد`, { - action: { label: "چاپ فاکتور", onClick: () => void printReceipt(cafeId as string, paidOrderId) }, - }); + const justPaidOrderId = payTarget.id; + notify.success(`پرداخت ${fmt(paid)} تومان ثبت شد`); queryClient.invalidateQueries({ queryKey: ["tables-board", cafeId] }); queryClient.invalidateQueries({ queryKey: ["orders-open", cafeId] }); backToBoard(); + // Keep the paid order id so the cashier can still print the receipt after + // the cart is cleared (the success sheet below uses it). + if (!isLocalOrder(justPaidOrderId)) setPaidOrderId(justPaidOrderId); } catch (e) { if (e instanceof ApiClientError && e.code.startsWith("POS_DEVICE")) { notify.error(posDeviceMsg(e)); @@ -307,14 +310,10 @@ export function Pos2Screen() { } }; - // Print (or reprint) the customer receipt for the active, already-saved order. - const printActiveReceipt = async () => { - if (!activeOrderId || isLocalOrder(activeOrderId)) { - notify.error("ابتدا سفارش را ثبت کنید"); - return; - } + // Print (or reprint) the customer receipt for a saved server order. + const printReceiptById = async (orderId: string) => { try { - await printReceipt(cafeId as string, activeOrderId); + await printReceipt(cafeId as string, orderId); notify.success("فاکتور برای چاپ ارسال شد"); } catch (e) { const code = e instanceof ApiClientError ? e.code : ""; @@ -328,6 +327,14 @@ export function Pos2Screen() { } }; + const printActiveReceipt = async () => { + if (!activeOrderId || isLocalOrder(activeOrderId)) { + notify.error("ابتدا سفارش را ثبت کنید"); + return; + } + await printReceiptById(activeOrderId); + }; + // ── guards ─────────────────────────────────────────────────────────────── if (!cafeId) { return ( @@ -613,6 +620,35 @@ export function Pos2Screen() { onConfirm={confirmPay} /> )} + + {paidOrderId && ( +
+
setPaidOrderId(null)} /> +
+
+ +
+

پرداخت با موفقیت ثبت شد

+

فاکتور مشتری را می‌توانید چاپ کنید

+
+ + +
+
+
+ )}
); }