Files
xenia-pos-local/manager_dashboard/src/pages/reports/moves/MovesReport.jsx
T
bonaminandClaude Opus 5.5 0a353c5f97 feat(backend,waiter,manager): moves between tables and orders on the record
Owner 2026-11-23 (plan 6F.4). services/moves.py: every table transfer, lines moved and orders merged
is an order_moves row with its lines (order_move_items: line, quantity then); OrderItem.split_from_id
links a split part to its line, so a part carries the moves made before the split; combining moves
the removed lines' moves to the kept one. Alembic 0048: the tables, the column, and a backfill from
the audit notes written before (note='backfill'). A split part now also keeps the line's price change,
kitchen state, course, cost and names (it used to restart as pending at the menu price).
GET /api/orders/{id}/moves (the order's path, each line's); GET /api/reports/moves (+ export).
Waiter: a moved order's banner (T2 -> T5), moved lines marked, a line's Move history. Manager: the
order's Moves tab, each moved line's path, Reports -> Moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 08:03:11 +02:00

65 lines
4.2 KiB
React
Raw 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.
// Reports → Moves (plan 6F.4, owner 2026-11-23): every move between tables and orders in a period:
// a whole table moved, lines moved to another table, tables joined; from / to, who, the lines
// with their quantities and value; counts per kind and per person; export for Excel.
// GET /api/reports/moves (+ /export).
import { useState } from 'react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Dropdown, Toolbar } from '@xenia/ui'
import client from '../../../api/client'
import { useLiveQuery } from '../../../live/useLiveQuery'
import { BarList } from '../kit/charts'
import { ExportButton, Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
import { PeriodPicker } from '../kit/Period'
import { defaultPeriod, periodParams, periodSlug } from '../kit/reportLogic'
const KINDS = ['table_transfer', 'items_moved', 'orders_merged']
export default function MovesReport() {
const { t } = useTranslation('manager')
return <ReportPage title={t('reports.moves.title')} testId="report-moves"><MovesBody /></ReportPage>
}
function MovesBody() {
const { t } = useTranslation('manager')
const fmt = useFormat()
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
const [kinds, setKinds] = useState([])
const params = { ...periodParams(period), ...(kinds.length === 1 ? { kind: kinds[0] } : {}) }
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-moves', params], queryFn: () => client.get('/api/reports/moves', { params }).then(r => r.data) })
const rows = (data?.moves ?? []).filter(m => !kinds.length || kinds.includes(m.kind))
const columns = [
{ key: 'at', label: t('reports.misc.when'), render: m => fmt.formatDateTime(m.at, 'datetimeShort') },
{ key: 'kind', label: t('reports.moves.kind'), render: m => t(`reports.moves.kinds.${m.kind}`) },
{ key: 'from_table', label: t('reports.moves.from'), render: m => <span className="font-semibold text-ink">{m.from_table || t('reports.noTable')}</span> },
{ key: 'to_table', label: t('reports.moves.to'), render: m => <span className="font-semibold text-ink">{m.to_table || t('reports.noTable')}</span> },
{ key: 'items', label: t('reports.moves.lines'), sortable: false,
render: m => <span className="text-label text-ink-2">{m.items.map(i => `${i.name ?? `#${i.item_id}`}${i.quantity != null ? ` ×${fmt.formatNumber(i.quantity, { maxDecimals: 3 })}` : ''}`).join(', ')}</span> },
{ key: 'value', label: t('reports.misc.value'), align: 'right', render: m => fmt.formatMoney(m.value) },
{ key: 'by', label: t('reports.moves.by'), render: m => m.by || '' },
{ key: 'orders', label: '#', sortable: false, render: m => <span className="tabular-nums text-ink-3">#{m.from_order_id}{m.to_order_id !== m.from_order_id ? ` → #${m.to_order_id}` : ''}</span> },
]
return (
<div className="grid gap-4">
<PeriodPicker value={period} onChange={setPeriod} right={<ExportButton endpoint="/api/reports/moves/export" params={params} filename={`moves-${periodSlug(period)}.csv`} />} />
<Toolbar>
<Dropdown multiple value={kinds} onChange={setKinds} allLabel={t('reports.moves.allKinds')} aria-label={t('reports.moves.kind')}
options={KINDS.map(k => ({ value: k, label: t(`reports.moves.kinds.${k}`) }))} data-testid="moves-kind" />
</Toolbar>
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(12rem,1fr))]">
<Stat label={t('reports.moves.count')} value={rows.length} testId="moves-count" />
{KINDS.map(k => <Stat key={k} label={t(`reports.moves.kinds.${k}`)} value={data.by_kind[k] ?? 0} />)}
</div>
{data.by_person.length > 1 && (
<Panel title={t('reports.misc.byWhom')}>
<BarList format={v => fmt.formatNumber(v)} rows={data.by_person.map(p => ({ key: p.user_id ?? '—', label: p.name ?? '—', value: p.count }))} />
</Panel>
)}
<Panel padded={false} title={t('reports.moves.list')} tip={t('reports.moves.listTip')}>
<Table columns={columns} rows={rows} rowTestId="report-move" initialSort={{ key: 'at', dir: 'desc' }} limit={500} />
</Panel>
</>)}
</div>
)
}