Invoice discounts and totals
Discount controls (none, percentage or fixed amount) for a line or the whole invoice, the early payment discount (amount and last day to pay at it), and the invoice editor's summary card: invoice discount, live subtotal, discount, tax, total and the early payment price, worked out as the server will. A controlled card that fetches nothing: values and onChange (the whole draft), errors and dirtyFields.
Component: A piece you place inside your own screens: a table, a form, a card or a dialog. You decide the layout around it. Pages vs components
Works with Dolfin’s SDK context, with appearance and behaviour you can customise. Requires DolfinProvider.
Installation
Needs the Dolfin registry token. The CLI copies the source into your app.
bunx --bun shadcn@4.23.0 add @dolfin/ar-invoice-discountAlso installs: card, field, input, select, base-theme, base-info-hint, base-money, ui-ar-invoice-discount.
Usage
import { InvoiceDiscountFields } from "@/components/dolfin/ar/invoice-discount";
// Place it anywhere inside your <DolfinProvider>.
<InvoiceDiscountFields type={type} value={value} onTypeChange={handleTypeChange} onValueChange={handleValueChange} currency={currency} label={label} />Renders inside DolfinProvider (set it up once). It renders the data you pass as props.
API reference
| Prop | Type | Description |
|---|---|---|
type required | "Fixed" | "None" | "Percentage" | |
value required | number | |
onTypeChange required | (type: DiscountType) => void | |
onValueChange required | (value: number) => void | |
currency required | string | The invoice currency, shown on a fixed amount. |
label required | string | |
error | string | Message for the value, from the draft's errors. |
compact | boolean | Smaller labels, for a line. |
dirtyClassName | string | false | Ring for a changed field. |
className | string |
Customisation
Without editing the source, you can change:
- Class names
dirtyClassNameclassName- Messages
ar.invoiceDraftbase.infoHint.moreAbout
Or edit the installed file directly: it is your code. See theming for colours and fonts.
Hooks
The SDK hooks this component uses. Use them directly from @dolfinai/react to build your own version.
useDolfinLocaleuseMessagesFiles
Written to your app by the install command:
components/dolfin/ar/invoice-discount.tsx132 linescomponents/dolfin/ar/invoice-draft-summary.tsx177 lines