Modules
Invoices
Receivables with aging, overdue reminders, partial payments, a quick view and a live invoice editor.
The stored state is draft, sent or paid. invoiceStatus() derives pending, partial and overdue from the due date and the payments. Only drafts can be edited; /billing/invoices/new creates one.
Files
File | Role |
|---|---|
pages/billing/invoices/index.vue | The list with the receivables card. |
pages/billing/invoices/[id].vue | The editor with a live preview. |
composables/useInvoices.ts | save, setState, remind, recordPayment, markPaid, duplicate, remove and the known clients. |
types/models/invoices.ts | Invoices, lines and payments. |
config/invoices.config.ts | Views, aging buckets, terms, tax and discount rates and payment methods. |
utils/invoices.ts | Pure rules, unit tested. |
components/pages/billing/ | InvoiceDocument, InvoiceQuickView, InvoiceReceivablesCard, InvoicePaymentDialog. |
Data
useInvoices() loads its data through a InvoicesProvider (types/models/invoices.ts); the demo uses createInvoicesMockProvider(). Write a provider that calls your API and make it the default: the pages do not change. See Connect your API.
Permissions
The list and the editor need invoices.view.
Configuration
INVOICE_VIEWS
The views of the list.
const INVOICE_VIEWS: InvoiceView[]
INVOICE_AGING_BUCKETS
The aging buckets of the receivables bar.
const INVOICE_AGING_BUCKETS: InvoiceAgingBucket[]
INVOICE_PAYMENT_TERMS
Payment terms in days.
const INVOICE_PAYMENT_TERMS: number[]
INVOICE_TAX_RATES
The tax rates of the editor.
const INVOICE_TAX_RATES: number[]
INVOICE_DISCOUNT_RATES
The discount rates of the editor.
const INVOICE_DISCOUNT_RATES: number[]
INVOICE_PAYMENT_METHODS
Payment methods for recording a payment.
const INVOICE_PAYMENT_METHODS: InvoicePaymentMethod[]
Rules
Pure functions in utils/, unit tested in tests/unit/. Statuses and segments are derived from the stored data, never stored themselves.
invoiceTotals()
Totals; the discount applies before VAT.
invoiceTotals(invoice: Pick<Invoice, 'lines' | 'taxRate' | 'discountRate'>): InvoiceTotals
subtotaldiscounttaxtotalinvoiceStatus()
The derived status.
invoiceStatus(invoice: Invoice, now: Date): InvoiceStatus
invoiceBalance()
The amount due.
invoiceBalance(invoice: Invoice): number
invoiceAging()
Outstanding by bucket.
invoiceAging(invoices: Invoice[], now: Date): { buckets: Record<InvoiceAgingBucket, number>; count: number; total: number; }bucketscounttotalaverageCollectionDays()
Average days to collect.
averageCollectionDays(invoices: Invoice[]): number | undefined
How it works
- A receivables card replaces KPI cards: outstanding total, collected this month, an aging bar and a
v-listlegend whose items filter the table. - An overdue
BaseAlertoffers “show” and “send reminders”. - A row click opens
InvoiceQuickView: amount due,InvoiceDocument, theBaseTimelinehistory, reminder, payment (aBaseFormPanel+BaseFormdialog), Download PDF (theprint()of BaseDocument, which opens the print dialog with only the invoice), duplicate and delete. - The editor is a BaseDocumentEditor: a plain
v-formwithBase*inputs next to a liveInvoiceDocumentpreview (which only maps the invoice onto BaseDocument), in four numbered sections (BaseSectionTitle): client, dates and terms (the due date is a sentence computed from the payment terms), items with unlimited lines and a totals block where discount and VAT are picked next to their amounts, and the note. The validation message disappears as soon as the form is valid.