feat(terminal): quick sale at the counter: cash/card/split, change, cash drawer, fiscal (platform-v2 3.3b)
- POST /api/pos/sales: all checks first (shift, lines, payment split, cash given, discount → ordering.prices.modify or manager approval, fiscal VAT groups), then the existing open_order / add_items / pay_items functions, so tickets, KDS, price events, shift totals and the fiscal receipt work as for any order. - Cash drawer: printer_service.open_cash_drawer (ESC @ + ESC p 0 25 250) to the screen's receipt printer on cash, logged and audited (DRAWER_OPENED / DRAWER_FAILED). - orders._can_access_order: the people assigned to an order may act on it (a cashier's own takeaway order); pos_cart prices a batch with the lines before it, as add_items does. - Terminal: Charge → payment dialog (exact cash pre-selected, quick amounts, change, card, split by line), per-line discounts, sale summary and "Same again". - Tests: backend +6 (socket printer receives the drawer kick, fiscal file in the bridge folder), terminal unit +1, terminal.mjs +9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -187,3 +187,37 @@ export const UNITS = {
|
||||
}
|
||||
|
||||
export const unitOf = product => UNITS[product.unit_type] ?? null
|
||||
|
||||
// ── paying (3.3b) ───────────────────────────────────────────────────────────
|
||||
|
||||
/** Amounts a customer typically hands over for `total`: the exact amount, then the next
|
||||
* round amounts above it (notes of 5, 10, 20, 50, 100), at most five. */
|
||||
export function quickAmounts(total) {
|
||||
const out = [round2(total)]
|
||||
for (const step of [5, 10, 20, 50, 100]) {
|
||||
const v = Math.ceil((total + 0.0001) / step) * step
|
||||
if (v > total + 0.004 && !out.includes(v)) out.push(v)
|
||||
}
|
||||
return out.slice(0, 5)
|
||||
}
|
||||
|
||||
/** Change to give back (null when not enough was given). */
|
||||
export function changeFor(given, due) {
|
||||
if (given == null || Number.isNaN(given)) return null
|
||||
const c = round2(given - due)
|
||||
return c < 0 ? null : c
|
||||
}
|
||||
|
||||
/** Cash and card parts of a split: methods[i] is 'cash' | 'card' for line i, totals from the
|
||||
* quote. → { cash, card, payments } (payments as POST /api/pos/sales takes them). */
|
||||
export function splitPayments(methods, totals) {
|
||||
const lines = { cash: [], card: [] }
|
||||
methods.forEach((m, i) => lines[m].push(i))
|
||||
const sum = idx => round2(idx.reduce((s, i) => s + (totals[i] ?? 0), 0))
|
||||
const payments = ['card', 'cash'].filter(m => lines[m].length).map(m => ({ method: m, lines: lines[m] }))
|
||||
return { cash: sum(lines.cash), card: sum(lines.card), payments }
|
||||
}
|
||||
|
||||
export const DISCOUNTS = [0, 5, 10, 15, 20, 25, 50, 100]
|
||||
|
||||
const round2 = n => Math.round(n * 100) / 100
|
||||
|
||||
Reference in New Issue
Block a user