feat(terminal): counter POS screen with server-priced cart and shift gate (platform-v2 3.3a)

- Backend /api/pos (pos_counter): session (business day, the cashier's own shift,
  self-start, who can open the day), menu (sellable products with every kind of choice,
  no costs; price now from the pricing engine), quote (lines by id → the waiter's
  selected_options entries with DB prices → resolve_price as orders do; pos.line_invalid).
- POS device settings: default order type, start category, receipt printer (new ref
  sources categories / printers, also in the manager's Devices dialogs).
- Terminal apps/pos: shift gate (start shift with drawer cash), categories, search,
  product grid, price check, options dialog, cart priced by the backend.
- Tests: backend test_pos (13), terminal pos.test.mjs, manager refOptions,
  terminal.mjs +10 POS checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 21:55:30 +02:00
co-authored by Claude Opus 5.5
parent b1112b249e
commit 17bee66df1
25 changed files with 1556 additions and 21 deletions
+64
View File
@@ -0,0 +1,64 @@
// The counter POS's server data (plan step 3.3a): the cashier's session (shift gate), the
// menu, and the cart priced by the backend. Kept fresh by the live connection.
import { useCallback, useEffect, useRef, useState } from 'react'
import client from '../../api/client'
import { useLiveEvent, useLiveEvents } from '../../device/context'
const quiet = { xenia: { noOverride: true } }
const MENU_REFRESH_MS = 5 * 60_000 // prices can change with the time (happy hours)
const QUOTE_DELAY_MS = 120
/** GET /api/pos/session: { business_day, shift, self_start, day_openers } (null while loading). */
export function usePosSession() {
const [session, setSession] = useState(null)
const [error, setError] = useState(null)
const load = useCallback(async () => {
try {
setSession((await client.get('/api/pos/session', quiet)).data)
setError(null)
} catch (err) { setError(err) }
}, [])
useEffect(() => { load() }, [load])
useLiveEvent('ready', load)
useLiveEvents(['shift_changed', 'business_day_changed'], load)
return { session, error, reload: load }
}
/** GET /api/pos/menu: { settings, categories, products } (null while loading). */
export function useMenu() {
const [menu, setMenu] = useState(null)
const load = useCallback(async () => {
try { setMenu((await client.get('/api/pos/menu', quiet)).data) } catch { /* the shell shows offline */ }
}, [])
useEffect(() => { load() }, [load])
useEffect(() => {
const id = setInterval(load, MENU_REFRESH_MS)
return () => clearInterval(id)
}, [load])
useLiveEvent('ready', load)
useLiveEvents(['products_changed', 'device.updated'], load)
return { menu, reload: load }
}
/** The cart priced by POST /api/pos/quote whenever it changes (latest answer wins).
* → { quote, pending, error } */
export function useQuote(lines, orderType) {
const [state, setState] = useState({ quote: null, pending: false, error: null })
const seq = useRef(0)
const key = JSON.stringify([lines, orderType])
useEffect(() => {
const mine = ++seq.current
if (!lines.length) { setState({ quote: { lines: [], total: 0 }, pending: false, error: null }); return undefined }
setState(s => ({ ...s, pending: true }))
const id = setTimeout(async () => {
try {
const { data } = await client.post('/api/pos/quote', { order_type: orderType, lines }, quiet)
if (mine === seq.current) setState({ quote: data, pending: false, error: null })
} catch (err) {
if (mine === seq.current) setState(s => ({ ...s, pending: false, error: err }))
}
}, QUOTE_DELAY_MS)
return () => clearTimeout(id)
}, [key]) // eslint-disable-line react-hooks/exhaustive-deps -- `key` is lines + orderType
return state
}