feat: printing problems shown and handled; printing set-up on v2 (platform-v2 step 6.10)
- a ticket that doesn't print is a problem for whoever sent it and the managers: GET /api/print-problems (the order, table, dishes, printer, since when, tries, last error, who sent it) and three ways out: print again, send to another printer, handled (services/print_problems.py; print_jobs.resolved_by / redirected_to, Alembic 0036); live event print.problems from the print paths - phone: the red printer button opens the problems sheet, the table page warns (usePrintProblems replaces the 8 s poll); counter POS: a red button under the modes with the shared panel (@xenia/ordering PrintProblemsPanel + pure rules); manager: a card on the overview (top), the Tables page and the order page - manager: Settings -> Printing (printers with reachability, test print, network scan; ticket layout + test ticket, beep, fonts with previews, dot leader, dividers) and Management -> Prep zones (cards + zone dialog with the ticket language, printers, copies, sorting, category order, kitchen screen) rebuilt in src/pages/printing; v1 PrintFontsTab, PrepZonesConfigPage, PendingPrints and /api/orders/pending-prints removed - access: printer add/edit/delete/scan need core.settings.manage, prep zone changes catalog.menu.manage (were any dashboard user) - tests: test_print_problems.py, @xenia/ordering printProblems, manager printing.test.mjs, e2e print_problems.mjs (done-when) + manager.mjs printing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// Printing problems (plan step 6.10), as plain data for every app: GET /api/print-problems
|
||||
// gives { problems, printers }; a problem is one ticket (an order's lines for one printer)
|
||||
// that didn't print. Node-tested (tests/printProblems.test.mjs).
|
||||
|
||||
export const PRINT_EVENT = 'print.problems'
|
||||
|
||||
/** The problems of one order (the order and table pages show only theirs). */
|
||||
export const problemsOf = (problems = [], orderId) => problems.filter(p => p.order_id === orderId)
|
||||
|
||||
/** The printers this ticket can be sent to instead (any but its own). */
|
||||
export const otherPrinters = (problem, printers = []) => printers.filter(p => p.id !== problem.printer.id)
|
||||
|
||||
/** "2× Burger, Freddo": what the ticket holds. */
|
||||
export function itemsText(problem) {
|
||||
return problem.items.map(i => (i.quantity !== 1 || i.unit_type !== 'piece' ? `${i.quantity}× ${i.name}` : i.name)).join(', ')
|
||||
}
|
||||
|
||||
/** Where the ticket belongs: the table's name, else the order number. */
|
||||
export const placeOf = problem => problem.table_name || `#${problem.order_id}`
|
||||
|
||||
/** Minutes since the first try (whole minutes, never negative). */
|
||||
export function minutesSince(problem, now = Date.now()) {
|
||||
const t = problem.since ? new Date(/[zZ]|[+-]\d\d:?\d\d$/.test(problem.since) ? problem.since : `${problem.since}Z`).getTime() : now
|
||||
return Math.max(0, Math.floor((now - t) / 60_000))
|
||||
}
|
||||
|
||||
/** One line per printer with how many tickets wait on it (the counter's and the phones' summary). */
|
||||
export function byPrinter(problems = []) {
|
||||
const out = new Map()
|
||||
for (const p of problems) {
|
||||
const e = out.get(p.printer.id) ?? { printer: p.printer, count: 0 }
|
||||
e.count += 1
|
||||
out.set(p.printer.id, e)
|
||||
}
|
||||
return [...out.values()]
|
||||
}
|
||||
|
||||
/** The request for an action: 'retry' | 'redirect' (with a printer) | 'handled'. → [url, body] */
|
||||
export function actionRequest(kind, problem, printerId) {
|
||||
const base = `/api/print-problems/${problem.job_id}`
|
||||
if (kind === 'redirect') return [`${base}/redirect`, { printer_id: printerId }]
|
||||
return [`${base}/${kind}`, {}]
|
||||
}
|
||||
Reference in New Issue
Block a user