site-panzai/utils/ticket.ts
2026-11-13 13:57:04 +01:00

17 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { Order } from '~/server/utils/store'
export function printTicket(o: Order) {
const w = window.open('', '_blank', 'width=380,height=640')
if (!w) return
const lines = o.items.map(i => `<tr><td>${i.qty}×</td><td><b>${i.name} ${i.size}</b><br>${[i.meat, i.sauce, ...(i.extras || [])].filter(Boolean).join(' · ')}${i.note ? `<br><i>« ${i.note} »</i>` : ''}</td><td style="text-align:right">${eur(i.unit * i.qty)}</td></tr>`).join('')
w.document.write(`<!doctype html><html><head><meta charset="utf-8"><title>Ticket ${o.num}</title><style>body{font:14px/1.4 monospace;margin:16px;color:#000}h1{font-size:20px;margin:0 0 4px}table{width:100%;border-collapse:collapse}td{padding:4px 2px;vertical-align:top}hr{border:0;border-top:1px dashed #000}</style></head><body>
<h1>PANZAÏ · #${o.num}</h1><div>${new Date(o.createdAt).toLocaleString('fr-FR')}</div><hr>
<div><b>${o.mode === 'livraison' ? 'LIVRAISON' : 'RETRAIT'}</b> — ${o.client.name} · ${o.client.phone}</div>
${o.address ? `<div>${o.address}</div>` : ''}${o.slot ? `<div>Créneau : ${o.slot}</div>` : ''}<hr>
<table>${lines}</table><hr>
<div>Total : <b>${eur(o.total)}</b> — ${o.paid ? 'PAYÉ' : 'À ENCAISSER'}</div>
</body></html>`)
w.document.close()
w.focus()
setTimeout(() => w.print(), 250)
}