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:
@@ -9,17 +9,25 @@ import { Field, Input, Select, Switch } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { configGroups, configValue, refOptions } from './devicesLogic'
|
||||
|
||||
// Where a `ref` field's choices come from (the device list is passed in)
|
||||
const REF_URLS = { prep_zones: '/api/prep-zones', categories: '/api/products/categories', printers: '/api/system/printers' }
|
||||
|
||||
export default function DeviceConfigFields({ appKey, fields = [], value, onChange, devices = [], selfId = null }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const needsZones = fields.some(f => f.choices_from === 'prep_zones')
|
||||
const [zones, setZones] = useState([])
|
||||
const sources = [...new Set(fields.map(f => f.choices_from).filter(s => s && REF_URLS[s]))].join(',')
|
||||
const [lists, setLists] = useState({})
|
||||
|
||||
useEffect(() => {
|
||||
if (!needsZones) return undefined
|
||||
if (!sources) return undefined
|
||||
let alive = true
|
||||
client.get('/api/prep-zones').then(r => { if (alive) setZones(r.data) }).catch(() => {})
|
||||
for (const s of sources.split(',')) {
|
||||
client.get(REF_URLS[s]).then(r => { if (alive) setLists(l => ({ ...l, [s]: r.data })) }).catch(() => {})
|
||||
}
|
||||
return () => { alive = false }
|
||||
}, [needsZones])
|
||||
}, [sources])
|
||||
const zones = lists.prep_zones ?? []
|
||||
const categories = lists.categories ?? []
|
||||
const printers = lists.printers ?? []
|
||||
|
||||
if (!fields.length) return null
|
||||
const base = key => `modules:${appKey}.config.${key}`
|
||||
@@ -45,7 +53,7 @@ export default function DeviceConfigFields({ appKey, fields = [], value, onChang
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
|
||||
options={[{ value: '', label: t(`${base(f.key)}.none`, { defaultValue: t('devices.form.none') }) },
|
||||
...refOptions(f, { zones, devices, selfId })]} />
|
||||
...refOptions(f, { zones, categories, printers, devices, selfId })]} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -85,9 +85,11 @@ export function configGroups(fields = []) {
|
||||
return out
|
||||
}
|
||||
|
||||
/** Options of a `ref` field: prep zones, or live devices of one app ("devices:<app>"). */
|
||||
export function refOptions(field, { zones = [], devices = [], selfId = null } = {}) {
|
||||
/** Options of a `ref` field: prep zones, categories, printers, or live devices of one app ("devices:<app>"). */
|
||||
export function refOptions(field, { zones = [], categories = [], printers = [], devices = [], selfId = null } = {}) {
|
||||
if (field.choices_from === 'prep_zones') return zones.map(z => ({ value: String(z.id), label: z.name }))
|
||||
if (field.choices_from === 'categories') return categories.map(c => ({ value: String(c.id), label: c.name }))
|
||||
if (field.choices_from === 'printers') return printers.filter(p => p.is_active !== false).map(p => ({ value: String(p.id), label: p.name }))
|
||||
if (field.choices_from?.startsWith('devices:')) {
|
||||
const app = field.choices_from.slice('devices:'.length)
|
||||
return devices.filter(d => !d.revoked_at && d.app_key === app && d.id !== selfId).map(d => ({ value: String(d.id), label: d.name }))
|
||||
|
||||
@@ -144,3 +144,9 @@ test('config fields in sections, in the order their groups first appear (3.2a)',
|
||||
[['zone', ['zone']], ['board', ['w', 's']], ['age', ['c']], [null, ['auto']]])
|
||||
assert.equal(configValue({ type: 'color' }, '#aabbcc'), '#aabbcc')
|
||||
})
|
||||
|
||||
test('refOptions: categories and active printers (3.3a)', () => {
|
||||
assert.deepEqual(refOptions({ choices_from: 'categories' }, { categories: [{ id: 3, name: 'Drinks' }] }), [{ value: '3', label: 'Drinks' }])
|
||||
assert.deepEqual(refOptions({ choices_from: 'printers' }, { printers: [{ id: 1, name: 'Bar', is_active: true }, { id: 2, name: 'Old', is_active: false }] }),
|
||||
[{ value: '1', label: 'Bar' }])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user