feat: tabs in the books (platform-v2 step 6.13c, KI-018; owner 2026-11-19: every movement recorded)

- a line on a customer's tab is sold, not paid: services/sales.py counts tabbed lines as sold (on_tab apart)
- TabEntry / TabPayment record the business day and the shift of whoever did it (Alembic 0037, rows backfilled with their day);
  services/tab_books.py: per shift and per day, on tabs and tab money received (cash / card / other, who, in a shift or not)
- shift: tab cash goes in the drawer (net_to_deliver, the counted difference, total_collected), tab card in the card total;
  items paid other ways (transfer, on the house) are recorded apart and no longer counted as drawer cash;
  'activity': orders, items made / paid / put on a tab with values
- day summary: per person put on tabs and tab money received, every tab payment with who took it, the part taken outside shifts (in no drawer);
  the day's money: paid, on tabs, sold, paid on tabs, money taken (it used to subtract tabs from paid sales)
- Today: on tabs, paid on tabs; Staff -> Cash handover: paid on tabs; the shift dialog: made / paid / on a tab / paid on tabs
- fix: a line put on a tab was charged without its price change (a discount)
- tests: test_tab_books.py (the done-when), overview unit, e2e manager.mjs (the day records the tab payments; Today shows them)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 16:32:25 +02:00
co-authored by Claude Opus 5.5
parent 93c0dd7d9c
commit 07c9a0aecf
20 changed files with 510 additions and 64 deletions
@@ -31,7 +31,7 @@ export default function ShiftDialog({ shift, mode, onClose, onConfirm, busy }) {
const { data: summary, isPending } = useLiveQuery({
queryKey: ['shift-summary', shift.id],
queryFn: () => client.get(`/api/shifts/${shift.id}/summary`).then(r => r.data),
events: ['order_paid', 'order_updated'],
events: ['order_paid', 'order_updated', 'tabs.changed'],
})
const data = summary || shift
const money = shiftMoney(data)
@@ -88,6 +88,8 @@ export default function ShiftDialog({ shift, mode, onClose, onConfirm, busy }) {
<div className="text-label text-right">
{t('overview.shift.startCash')} <Money value={money.start} className="font-semibold text-ink" /><br />
+ {t('overview.shift.cashSales')} <Money value={money.cash} className="font-semibold text-ink" />
{money.tabCash > 0 && <><br />+ {t('overview.shift.tabCash')} <Money value={money.tabCash} className="font-semibold text-ink" /></>}
{money.refunded > 0 && <><br />− {t('overview.shift.refunded')} <Money value={money.refunded} className="font-semibold text-ink" /></>}
</div>
</div>
<div className="grid grid-cols-3 gap-3">
@@ -98,7 +100,10 @@ export default function ShiftDialog({ shift, mode, onClose, onConfirm, busy }) {
{money.total > 0 && <SplitBar parts={[
{ key: 'cash', tone: 'success', label: t('overview.pay.cash'), value: money.cash },
{ key: 'card', tone: 'info', label: t('overview.pay.card'), value: money.card },
]} />}
{ key: 'other', tone: 'neutral', label: t('overview.pay.other'), value: money.other },
{ key: 'tab', tone: 'accent', label: t('overview.shift.tabPayments'), value: money.tab },
].filter(p => p.value > 0)} />}
{data.activity && <ShiftActivity a={data.activity} money={money} />}
{summary && shiftPairs(summary).length > 0 && (
<div className="grid gap-2">
<span className="text-caption font-semibold uppercase tracking-wide text-ink-3">{t('overview.shift.perHour')}</span>
@@ -204,3 +209,24 @@ function OrderLines({ order, waiterId, kind, payment }) {
</div>
)
}
/** What happened in the shift (6.13c): made, paid, put on a tab, and the tab money received. */
function ShiftActivity({ a, money }) {
const { t } = useTranslation('manager')
const { formatMoney } = useFormat()
const cell = (label, items, value, testId, tone) => (
<Figure label={label} sub={value != null ? formatMoney(value) : null}>
<span className={tone} data-testid={testId}>{items}</span>
</Figure>
)
return (
<div className="grid grid-cols-2 sm:grid-cols-4 gap-3 rounded-card border border-line p-3" data-testid="shift-activity">
{cell(t('overview.shift.made', { count: a.orders }), a.made_items, a.made_value, 'shift-made')}
{cell(t('overview.shift.paidItems'), a.paid_items, a.paid_value, 'shift-paid', 'text-success-ink')}
{cell(t('overview.shift.onTab'), a.tab_items, a.tab_value, 'shift-on-tab', a.tab_items ? 'text-warning-ink' : undefined)}
<Figure label={t('overview.shift.tabPayments')} sub={money.tab ? t('overview.shift.tabPaymentsSub', { cash: formatMoney(money.tabCash), card: formatMoney(money.tabCard + money.tabOther) }) : null}>
<Money value={money.tab} data-testid="shift-tab-received" />
</Figure>
</div>
)
}