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
@@ -19,6 +19,9 @@ import { ExportButton, Failed, Loading, Panel, ReportPage, Stat, Table } from '.
import { PeriodPicker } from '../kit/Period'
import { defaultPeriod, periodParams, periodSlug, ratio } from '../kit/reportLogic'
/** Money a shift received on customers' tabs (6.13c). */
const tabOf = s => (s.tab_cash ?? 0) + (s.tab_card ?? 0) + (s.tab_other ?? 0)
export default function StaffReport() {
const { t } = useTranslation('manager')
const tabs = [
@@ -118,6 +121,8 @@ function CashTab() {
{ key: 'starting_cash', label: t('reports.staff.starting'), align: 'right', render: s => fmt.formatMoney(s.starting_cash ?? 0) },
{ key: 'cash_sales', label: t('reports.staff.cash'), align: 'right', render: s => fmt.formatMoney(s.cash_sales ?? 0) },
{ key: 'card_sales', label: t('reports.staff.card'), align: 'right', render: s => fmt.formatMoney(s.card_sales ?? 0) },
{ key: 'tabs', label: t('reports.staff.tabMoney'), align: 'right', tip: t('reports.staff.tabMoneyTip'), sort: s => tabOf(s),
render: s => (tabOf(s) ? <span title={t('reports.staff.tabMoneySplit', { cash: fmt.formatMoney(s.tab_cash ?? 0), card: fmt.formatMoney((s.tab_card ?? 0) + (s.tab_other ?? 0)) })}>{fmt.formatMoney(tabOf(s))}</span> : '') },
{ key: 'refunds', label: t('reports.refunded'), align: 'right', sort: s => (s.cash_refunds ?? 0) + (s.card_refunds ?? 0),
render: s => { const r = (s.cash_refunds ?? 0) + (s.card_refunds ?? 0); return r ? <span className="text-danger-ink">{fmt.formatMoney(r)}</span> : '' } },
{ key: 'net_to_deliver', label: t('reports.staff.handOver'), align: 'right', render: s => <span className="font-semibold">{fmt.formatMoney(s.net_to_deliver)}</span> },
@@ -132,6 +137,7 @@ function CashTab() {
<Stat label={t('reports.staff.starting')} value={fmt.formatMoney(sum('starting_cash'))} sub={t('reports.staff.shiftsCount', { count: rows.length })} />
<Stat label={t('reports.staff.cash')} value={fmt.formatMoney(sum('cash_sales'))} />
<Stat label={t('reports.staff.card')} value={fmt.formatMoney(sum('card_sales'))} />
{rows.some(tabOf) && <Stat label={t('reports.staff.tabMoney')} tip={t('reports.staff.tabMoneyTip')} value={fmt.formatMoney(rows.reduce((n, r) => n + tabOf(r), 0))} />}
<Stat label={t('reports.staff.handOver')} tip={t('reports.staff.handOverTip')} tone="accent" value={fmt.formatMoney(sum('net_to_deliver'))} testId="staff-handover" />
</div>
<Panel padded={false} title={t('reports.staff.cashTitle')}>
@@ -69,6 +69,9 @@ function Today() {
<Stat big label={t('reports.revenue')} tip={t('reports.revenueTip')} testId="today-revenue"
value={<MoneyCell value={d.revenue} />}
sub={t('reports.today.finished', { count: finished, avg: fmt.formatMoney(finished ? d.revenue / finished : 0) })} />
{d.on_tab > 0 && <Stat label={t('reports.today.onTab')} tip={t('reports.today.onTabTip')} tone="warning" value={fmt.formatMoney(d.on_tab)} testId="today-on-tab" />}
{d.tab_received?.total > 0 && <Stat label={t('reports.today.tabReceived')} tip={t('reports.today.tabReceivedTip')} tone="success" value={fmt.formatMoney(d.tab_received.total)}
sub={t('reports.today.tabReceivedSub', { cash: fmt.formatMoney(d.tab_received.cash), card: fmt.formatMoney(d.tab_received.card + d.tab_received.other) })} testId="today-tab-received" />}
{d.fees > 0 && <Stat label={t('reports.fees')} tip={t('reports.feesTip')} value={fmt.formatMoney(d.fees)} testId="today-fees" />}
{d.refunded > 0 && <Stat label={t('reports.refunded')} tip={t('reports.refundedTip')} tone="danger" value={fmt.formatMoney(d.refunded)}
sub={t('reports.today.refunds', { count: d.refunds?.count ?? 0 })} testId="today-refunded" />}