Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,12 @@ Router: `main/routes/expenses.ts`. Full path: `/api/expenses`. Reads need `expen
creation, voiding, and replacement need `expenses.manage` **and** `expenses.view`, while payment and
reversal mutations need `expenses.pay` and `expenses.reverse` (alongside `expenses.view`, plus
`cash.movements.manage` for cash methods) so an actor can always read back the row they touched.
Amounts are integer minor units in the expense's own `currency_code`; no endpoint converts currencies
or assumes a minor-unit factor.
Amounts are positive safe-integer minor units in the expense's own `currency_code`; no endpoint
converts currencies or assumes a minor-unit factor. Active incurred totals per currency (after
subtracting the replaced source on replacement) and returned aggregate totals must fit within
`Number.MAX_SAFE_INTEGER`, or the operation fails with `422 amount_range_exceeded`; legacy rows with
an out-of-range stored amount project `amount_minor` and `due_minor` as `null` so list, detail, and
recovery mutations stay usable without rounding.

| Method | Path | Authorization | Parameters | Response |
| --- | --- | --- | --- | --- |
Expand Down
240 changes: 188 additions & 52 deletions frontend/src/app/(dashboard)/expenses/page.tsx

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions frontend/src/components/expenses/ExpenseWorkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ export default function ExpenseWorkflow({
setAttemptState({ attempt: next, storageBlocked: false });
// The freshly loaded record wins over the list row once it is that same record.
const record = detail && detail.id === expense?.id ? detail : expense;
const fmtMinor = (amountMinor: number) =>
fmt(amountMinor / getCurrencyMinorUnitFactor(record?.currency_code ?? context.currency_code));
const fmtMinor = (amountMinor: number | null) =>
amountMinor === null
? tCommon('notAvailable')
: fmt(
amountMinor / getCurrencyMinorUnitFactor(record?.currency_code ?? context.currency_code),
);

/** Replacing copies the source values into the fresh form. */
const openReplace = () => {
Expand All @@ -154,7 +158,11 @@ export default function ExpenseWorkflow({
if (expense) {
setDescription(expense.description);
setCategoryId(expense.category_id);
setAmount(unitAdapter.toDisplay(expense.amount_minor / minorFactor));
setAmount(
expense.amount_minor === null
? ''
: unitAdapter.toDisplay(expense.amount_minor / minorFactor),
);
setIncurredOn(expense.incurred_on);
setPayee(expense.payee ?? '');
setNotes(expense.notes ?? '');
Expand Down Expand Up @@ -409,7 +417,7 @@ export default function ExpenseWorkflow({
focusAmount();
return;
}
if (cents > record.due_minor) {
if (record.due_minor === null || cents > record.due_minor) {
setErrors({ amount: t('exceedsDue', { amount: fmtMinor(record.due_minor) }) });
focusAmount();
return;
Expand Down Expand Up @@ -1038,9 +1046,7 @@ export default function ExpenseWorkflow({
<Button
type="button"
onClick={openPayment}
disabled={
busy || locked || record.status !== 'active' || record.due_minor === 0
}
disabled={busy || locked || record.status !== 'active' || !record.due_minor}
data-testid="expense-record-payment"
>
{t('paymentTitle')}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export interface ExpenseRecord {
description: string;
payee: string | null;
notes: string | null;
amount_minor: number;
amount_minor: number | null;
currency_code: string;
incurred_on: string;
created_by: string;
Expand All @@ -369,7 +369,7 @@ export interface ExpenseRecord {
void_reason: string | null;
status: ExpenseStatus;
paid_minor: number;
due_minor: number;
due_minor: number | null;
}

export interface ExpensePaymentRecord {
Expand Down
Loading
Loading