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:
@@ -58,11 +58,24 @@ export function MoneyTab({ data }) {
|
||||
|
||||
<div className="rounded-card border border-line overflow-hidden">
|
||||
<Section title={t('overview.day.sales')} shaded>
|
||||
<Row label={t('overview.day.salesTotal')} value={formatMoney(data.total_revenue)} />
|
||||
{data.tabbed_revenue > 0 && <Row indent label={t('overview.day.onTabs')} value={`− ${formatMoney(data.tabbed_revenue)}`} tone="text-warning-ink"
|
||||
{/* 6.13c: sold = paid + on tabs; money taken = paid items + tab payments received */}
|
||||
<Row label={t('overview.day.paidSales')} value={formatMoney(data.total_revenue)} />
|
||||
{data.tabbed_revenue > 0 && <Row label={t('overview.day.onTabs')} value={formatMoney(data.tabbed_revenue)} tone="text-warning-ink"
|
||||
info={<InfoTip>{t('overview.day.onTabsTip')}</InfoTip>} />}
|
||||
<Row label={t('overview.day.taken')} value={formatMoney(data.total_revenue - (data.tabbed_revenue || 0))} tone="text-success-ink" />
|
||||
<Row label={t('overview.day.salesTotal')} value={formatMoney(data.total_revenue + (data.tabbed_revenue || 0))} />
|
||||
{data.tabs?.received?.total > 0 && <Row label={t('overview.day.tabReceived')} value={`+ ${formatMoney(data.tabs.received.total)}`}
|
||||
sub={t('overview.day.tabReceivedSub', { cash: formatMoney(data.tabs.received.cash), card: formatMoney(data.tabs.received.card + data.tabs.received.other) })}
|
||||
info={<InfoTip>{t('overview.day.tabReceivedTip')}</InfoTip>} />}
|
||||
<Row label={t('overview.day.taken')} value={formatMoney(data.total_revenue + (data.tabs?.received?.total || 0))} tone="text-success-ink" />
|
||||
</Section>
|
||||
{data.tabs?.payments?.length > 0 && (
|
||||
<Section title={t('overview.day.tabPayments')}>
|
||||
{data.tabs.payments.map(p => (
|
||||
<Row key={p.id} label={t('overview.day.tabPayment', { customer: p.customer_name ?? '', name: p.received_by_name, method: t(`overview.pay.${p.method}`, { defaultValue: p.method }) })}
|
||||
sub={`${formatDateTime(p.at, 'time')}${p.shift_id ? '' : ` · ${t('overview.day.noShift')}`}`} value={formatMoney(p.amount)} tone="text-success-ink" />
|
||||
))}
|
||||
</Section>
|
||||
)}
|
||||
<Section title={t('overview.day.cogs')}>
|
||||
<Row label={t('overview.day.cogsKnown')} value={formatMoney(data.cogs_trackable)} info={<InfoTip>{t('overview.day.cogsTip')}</InfoTip>} />
|
||||
{data.cogs_has_gap && <Row indent warn label={t('overview.day.uncosted', { count: data.cogs_uncosted_count, revenue: formatMoney(data.cogs_uncosted_revenue) })} value="?" />}
|
||||
@@ -137,6 +150,8 @@ export function StaffTab({ data }) {
|
||||
<Figure label={t('overview.day.tablesServed')}>{w.tables_served ?? 0}</Figure>
|
||||
<Figure label={t('overview.day.itemsPaid')}>{w.items_paid}</Figure>
|
||||
<Figure label={t('overview.day.collected')}><Money value={w.total_collected} className="text-success-ink" /></Figure>
|
||||
{w.on_tab_value > 0 && <Figure label={t('overview.day.putOnTab')}><Money value={w.on_tab_value} className="text-warning-ink" /></Figure>}
|
||||
{w.tab_cash + w.tab_card + w.tab_other > 0 && <Figure label={t('overview.day.tabReceived')}><Money value={w.tab_cash + w.tab_card + w.tab_other} className="text-success-ink" /></Figure>}
|
||||
<ChevronDown size={16} className={cx('text-ink-3 transition-transform duration-base', shown && 'rotate-180')} aria-hidden="true" />
|
||||
</button>
|
||||
{shown && (
|
||||
@@ -235,6 +250,8 @@ export function CashTab({ data, counted, onCounted, value }) {
|
||||
<div className="rounded-card border border-line bg-surface-2 px-4 py-3">
|
||||
<div className="text-caption font-semibold uppercase tracking-wide text-ink-3 mb-1">{t('overview.day.takings')}</div>
|
||||
<Row label={t('overview.day.staffTook')} value={formatMoney(data.total_waiter_collected)} />
|
||||
{data.tabs?.received_outside_shifts?.total > 0 && <Row indent label={t('overview.day.tabOutsideShifts')} value={formatMoney(data.tabs.received_outside_shifts.total)}
|
||||
info={<InfoTip>{t('overview.day.tabOutsideShiftsTip')}</InfoTip>} />}
|
||||
{data.store_opening_cash != null && <Row label={t('overview.day.openingCash')} value={formatMoney(data.store_opening_cash)} />}
|
||||
<div className="border-t border-line mt-1 pt-1">
|
||||
<Row label={t('overview.day.drawerExpected')} value={formatMoney(expected)} info={<InfoTip>{t('overview.day.drawerExpectedTip')}</InfoTip>} />
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -91,14 +91,29 @@ export function shiftCounts(summary) {
|
||||
}
|
||||
}
|
||||
|
||||
/** The shift's money: what it started with, took in cash / card, and what should be in the drawer. */
|
||||
/**
|
||||
* The shift's money (6.13c: every movement apart): what it started with, took for items in cash /
|
||||
* by card / other ways (transfer, on the house: in no drawer), took on customers' tabs, gave
|
||||
* back, and what should be in the drawer (the backend's `net_to_deliver` when given).
|
||||
*/
|
||||
export function shiftMoney(data = {}) {
|
||||
const cash = data.cash_sales ?? data.total_collected ?? 0
|
||||
const card = data.card_sales ?? 0
|
||||
const other = data.other_sales ?? 0
|
||||
const tabCash = data.tab_cash ?? 0
|
||||
const tabCard = data.tab_card ?? 0
|
||||
const tabOther = data.tab_other ?? 0
|
||||
const refunded = data.cash_refunds ?? 0
|
||||
const start = data.starting_cash ?? 0
|
||||
const total = cash + card
|
||||
const cashPct = total > 0 ? Math.round((cash / total) * 100) : 0
|
||||
return { cash, card, start, total, expected: start + cash, cashPct, cardPct: total > 0 ? 100 - cashPct : 0 }
|
||||
const tab = tabCash + tabCard + tabOther
|
||||
const total = cash + card + other + tab
|
||||
const drawer = cash + tabCash
|
||||
const cashPct = total > 0 ? Math.round((drawer / total) * 100) : 0
|
||||
return {
|
||||
cash, card, other, tabCash, tabCard, tabOther, tab, refunded, start, total,
|
||||
expected: data.net_to_deliver ?? start + cash + tabCash - refunded,
|
||||
cashPct, cardPct: total > 0 ? 100 - cashPct : 0,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user