Skip to main content

Function: effectiveInvoiceStatus()

effectiveInvoiceStatus(status, dueDate, outstandingCents, todayIso): string

Defined in: src/lib/invoice/status.ts:24

The status to DISPLAY for an invoice.

The stored status is never flipped to 'overdue' as time passes (nothing in the system writes it — every consumer treats sent/partial/overdue as the same "outstanding" set and computes real overdue from due_date). So a sent/partial invoice that is past its due date and still owing is shown as 'overdue' here — the true outstanding state — while paid / void / draft pass through unchanged.

Pure and side-effect-free: it derives a display label only and never mutates or persists the stored status. All date comparisons are lexical on ISO date strings, so dueDate and todayIso must share the same format (e.g. 'YYYY-MM-DD') for the ordering to be correct.

Parameters

status

string

The stored invoice status (e.g. 'draft', 'sent', 'partial', 'paid', 'void'). Only 'sent' and 'partial' are eligible to be relabeled; any other value passes through unchanged.

dueDate

string | null

The invoice due date as an ISO date string, or null when no due date is set. A null due date can never be overdue.

outstandingCents

number

Amount still owing, in integer CENTS. Must be > 0 for the invoice to be considered outstanding; a fully-settled invoice (<= 0) is never relabeled.

todayIso

string

"Today" as an ISO date string, in the same format as dueDate. The invoice is past due only when dueDate < todayIso (strictly before today; due today is not yet overdue).

Returns

string

'overdue' when an eligible ('sent'/'partial'), still-owing invoice has a due date strictly before today; otherwise the original status unchanged.