feat(manager): expenses, the supplier book and tabs on v2 (platform-v2 step 6.13a)

- Finance -> Expenses: still owed, late, filters, new/edit (supplier picked or added there), pay in parts, details with payments, delete
- CRM -> Contacts: the supplier book with what each one is owed
- Finance -> Tabs: open (who owes most first) / settled, charges and payments, pay (cash/card/other), close, forgive
- backend: expenses.manage / tabs.manage (the list also reports.view, a customer's tabs also crm.manage, put-on-tab needs tabs.manage);
  payment <= due (expense.over_due), total >= paid (expense.below_paid), categories/kinds/methods checked, null clears a field;
  live events expenses.changed / tabs.changed; GET /api/expenses ?from=&to= venue dates (the report uses it); tab_status=settled
- fix: an expense with a due date failed to save (naive date refused by D-11)
- @xenia/i18n/number subpath; tests: test_finance.py (6), finance.test.mjs (5), e2e manager.mjs finance flow

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 12:54:21 +02:00
co-authored by Claude Opus 5.5
parent 6bdf0bdd79
commit 93c0dd7d9c
32 changed files with 1667 additions and 1153 deletions
@@ -1,6 +1,7 @@
// Reports → Expenses (plan step 6.12c; replaces the v1 expenses report): what the venue spent in
// a period (by the day each expense was entered), paid and still due; split by category or by
// supplier; every expense, a tap shows its payments. Entering expenses is Finance → Expenses.
// The period is filtered by the server (venue dates, 6.13a); categories / statuses are `finance.*` texts.
import { useState } from 'react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, Dialog, Select } from '@xenia/ui'
@@ -11,9 +12,8 @@ import { BarList } from '../kit/charts'
import { Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
import { PeriodPicker } from '../kit/Period'
import { defaultPeriod } from '../kit/reportLogic'
import { CATEGORIES, STATUS_TONE } from '../../finance/financeLogic'
const STATUS_TONE = { paid: 'success', partial: 'warning', due: 'danger' }
const CATEGORIES = ['supplier', 'utilities', 'rent', 'maintenance', 'staff', 'equipment', 'other'] // as Finance → Expenses saves them (models/expenses.py)
export default function ExpensesReport() {
const { t } = useTranslation('manager')
@@ -28,11 +28,10 @@ function Expenses() {
const [category, setCategory] = useState('')
const [split, setSplit] = useState('category')
const [open, setOpen] = useState(null)
const params = { ...(status ? { status } : {}), ...(category ? { category } : {}) }
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-expenses', params], queryFn: () => client.get('/api/expenses/', { params }).then(r => r.data) })
const catName = c => t(`reports.exp.categories.${c}`, { defaultValue: c })
const inPeriod = e => { const d = fmt.venueDateKey(e.created_at); return (!period.from || d >= period.from) && (!period.to || d <= period.to) }
const rows = (data ?? []).filter(inPeriod)
const params = { ...(period.from ? { from: period.from } : {}), ...(period.to ? { to: period.to } : {}), ...(status ? { status } : {}), ...(category ? { category } : {}) }
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-expenses', params], queryFn: () => client.get('/api/expenses/', { params }).then(r => r.data), events: ['expenses.changed'] })
const catName = c => t(`finance.categories.${c}`, { defaultValue: c })
const rows = data ?? []
const sum = k => rows.reduce((s, e) => s + (e[k] ?? 0), 0)
const groups = Object.values(rows.reduce((m, e) => {
const k = split === 'category' ? e.category : (e.contact_name || t('reports.exp.noSupplier'))
@@ -48,13 +47,13 @@ function Expenses() {
{ key: 'contact_name', label: t('reports.exp.supplier'), render: e => e.contact_name || '' },
{ key: 'total_amount', label: t('reports.exp.total'), align: 'right', render: e => fmt.formatMoney(e.total_amount) },
{ key: 'due_amount', label: t('reports.exp.due'), align: 'right', render: e => (e.due_amount ? <span className="text-danger-ink">{fmt.formatMoney(e.due_amount)}</span> : '') },
{ key: 'status', label: t('reports.status'), render: e => <Pill tone={STATUS_TONE[e.status] ?? 'neutral'}>{t(`reports.exp.status.${e.status}`, { defaultValue: e.status })}</Pill> },
{ key: 'status', label: t('reports.status'), render: e => <Pill tone={STATUS_TONE[e.status] ?? 'neutral'}>{t(`finance.status.${e.status}`, { defaultValue: e.status })}</Pill> },
]
return (
<div className="grid gap-4">
<PeriodPicker value={period} onChange={setPeriod} allowDay={false} right={<span className="flex gap-2 items-end">
<Select size="sm" value={status} onChange={e => setStatus(e.target.value)} aria-label={t('reports.status')}
options={[{ value: '', label: t('reports.store.anyStatus') }, ...['due', 'partial', 'paid'].map(s => ({ value: s, label: t(`reports.exp.status.${s}`) }))]} />
options={[{ value: '', label: t('reports.store.anyStatus') }, ...['due', 'partial', 'paid'].map(s => ({ value: s, label: t(`finance.status.${s}`) }))]} />
<Select size="sm" value={category} onChange={e => setCategory(e.target.value)} aria-label={t('reports.prod.category')}
options={[{ value: '', label: t('reports.prod.allCategories') }, ...CATEGORIES.map(c => ({ value: c, label: catName(c) }))]} />
</span>} />