RollForward
- Status
- Implemented
- Family
- 9 of 13
- Registry
- @lopifi/roll-forward
npx shadcn@latest add @lopifi/theme @lopifi/roll-forwardThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
The most reusable component in the accounting family. Every schedule is this shape.
Opening · + Additions · − Releases · ± Adjustments · = Closing
Closing vs. GL balance → Difference (must be zero or explained)
Asserts opening = prior closing. Asserts closing = GL. Difference always visible; non-zero is the primary state of the screen with a required explanation.
Lifted verbatim from Accounting core (GL). The doc and this page are the same paragraphs, so they cannot disagree.
What lands in your repository
One component is never one file. Everything below is copied into your project, where you own it.
- Files
components/ledger/roll-forward.tsx
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/roll-forward.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { CheckIcon, ExclamationTriangleIcon } from "@/components/ledger/icons";
import { Money } from "@/components/ledger/money";
import { Rule } from "@/components/ledger/rule";
export interface RollForwardProps extends React.ComponentPropsWithoutRef<"div"> {
additions: MoneyValue;
adjustments: MoneyValue;
closing: MoneyValue;
explanation?: string;
/** Asserted against the GL. */
glBalance: MoneyValue;
opening: MoneyValue;
periodLabel: string;
/** Asserted against the prior period's closing. */
priorClosing?: MoneyValue;
releases: MoneyValue;
title: string;
}
/**
* The most reusable component in the accounting family — every schedule is
* this shape.
*
* Opening · + Additions · − Releases · ± Adjustments · = Closing, then
* closing vs. GL. The difference is always visible, and non-zero is the
* primary state of the screen with a required explanation.
*/
export const RollForward = React.forwardRef<HTMLDivElement, RollForwardProps>(
(
{
className,
title,
periodLabel,
opening,
priorClosing,
additions,
releases,
adjustments,
closing,
glBalance,
explanation,
...props
},
ref,
) => {
const currency = closing.currency;
const continuity = priorClosing == null || Number(priorClosing.amount) === Number(opening.amount);
const glDifference = Number(closing.amount) - Number(glBalance.amount);
const ties = glDifference === 0;
const ok = continuity && ties;
return (
<div
className={cn("rounded-xl border bg-surface", ok ? "border-border" : "border-negative", className)}
ref={ref}
{...props}
>
<header className="border-b border-border-subtle px-6 py-4">
<h3 className="text-title-sm font-medium">{title}</h3>
<p className="text-caption text-text-secondary">{periodLabel}</p>
</header>
<table className="w-full">
<caption className="sr-only">
{title} roll-forward for {periodLabel}
</caption>
<tbody>
<Line amount={opening} label="Opening balance" />
<Line amount={additions} label="Additions" sign="+" />
<Line amount={releases} label="Releases" sign="−" />
<Line amount={adjustments} label="Adjustments" sign="±" />
<tr>
<td />
<td className="px-6">
<Rule variant="subtotal" />
</td>
</tr>
<Line amount={closing} emphasis label="Closing balance" />
<tr>
<td />
<td className="px-6">
<Rule variant="total" />
</td>
</tr>
<Line amount={glBalance} label="General ledger balance" muted />
<tr>
<th
className={cn(
"py-2 pl-6 pr-6 text-left text-label font-medium",
ties ? "text-positive" : "text-negative",
)}
scope="row"
>
Difference
</th>
<td className={cn("px-6 py-2 text-right", ties ? "text-positive" : "text-negative")}>
<Money accounting size="md" tone="inherit" value={{ amount: glDifference, currency }} />
</td>
</tr>
</tbody>
</table>
<div className="space-y-2 px-6 pb-6">
{!continuity && priorClosing ? (
<p
className="flex items-center gap-2 rounded-sm bg-negative-subtle px-3 py-2 text-body text-negative"
role="alert"
>
<ExclamationTriangleIcon aria-hidden="true" className="size-4 shrink-0" />
Opening does not equal the prior period’s closing of{" "}
<Money accounting tone="inherit" value={priorClosing} />.
</p>
) : null}
<p
className={cn(
"flex items-center gap-2 rounded-sm px-3 py-2 text-body",
ties ? "bg-positive-subtle text-positive" : "bg-negative-subtle text-negative",
)}
role={ties ? undefined : "alert"}
>
{ties ? (
<CheckIcon aria-hidden="true" className="size-4 shrink-0" />
) : (
<ExclamationTriangleIcon aria-hidden="true" className="size-4 shrink-0" />
)}
{ties
? "Closing balance ties to the general ledger."
: "Closing balance does not tie to the general ledger. This must be explained before the close can proceed."}
</p>
{!ties ? (
explanation ? (
<p className="rounded-sm bg-surface-sunken p-3 text-body">{explanation}</p>
) : (
<label className="block">
<span className="mb-1 block text-label font-medium text-text-secondary">
Explanation (required)
</span>
<textarea
className="w-full rounded-sm border border-border bg-surface p-2 text-body outline-none focus-visible:border-accent"
placeholder="What accounts for the difference?"
rows={2}
/>
</label>
)
) : null}
</div>
</div>
);
},
);
RollForward.displayName = "RollForward";
function Line({
label,
amount,
sign,
emphasis,
muted,
}: {
label: string;
amount: MoneyValue;
sign?: string;
emphasis?: boolean;
muted?: boolean;
}) {
return (
<tr>
<th
className={cn(
"py-2 pl-6 pr-6 text-left text-body font-normal",
emphasis && "font-medium",
muted && "text-text-secondary",
)}
scope="row"
>
{sign ? (
<span aria-hidden="true" className="mr-2 inline-block w-3 text-text-tertiary">
{sign}
</span>
) : (
<span aria-hidden="true" className="mr-2 inline-block w-3" />
)}
{label}
</th>
<td className="px-6 py-2 text-right">
<Money
accounting
size={emphasis ? "md" : "sm"}
tone={muted ? "secondary" : "primary"}
value={amount}
/>
</td>
</tr>
);
}
The accounting it encodes
Concepts this component renders. Each one is defined once, in the lexicon, and used identically in the code and the copy.
Also in Accounting core (GL)
- JournalEntryDebit and credit as two columns. No signed-column variant.
- JournalEntryFormLine grid with live balance check and dimension capture.
- JournalEntryTableAll entries, with the gapless-numbering check.
- AccountPickerShows the normal balance. Blocks non-postable accounts.
- ChartOfAccountsHierarchy, statement mapping, unsupported-account flags.
- AccountRegisterGL detail with a running balance.
- DimensionPickerEntity always required; renders what the account demands.
- AdjustingEntryFormTemplated by type. Auto-reverse defaults on for accruals.
- RecurringEntryTemplateTemplate editable; instances read-only.
- EntryReversalDialogHold-to-confirm. Never a delete.
- ScheduleTableOne shell, seven presets. Prepaids through debt.
- AccountTieOutEvery BS account, proven against its evidence.
- SchedulePreviewWhat the schedules will post, before they post.
- RevenueWaterfallDeferred balance recognizing by future period.
- DepreciationScheduleBook and tax in parallel. In-service date, not purchase date.
- LeaseScheduleROU asset and liability on diverging curves.
- AllowanceRollForwardWith the methodology shown, not just the number.
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Accounting core (GL) — the family specThe four-layer specification this component was built against, before it was written.Doc
- General ledger and accounting coreThe family running, with real figures in it, in both themes and at every density.Live
- CatalogAll 179 components, specified before they are written.Doc
- General ledgerThe complete set of accounts, holding every posted entryTerm
Elsewhere in the system
Where RollForward sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.
- RollForward, runningThe gl showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Depreciation scheduleStraight-line, declining balance or SYD, with the convention that decides the first period.Tool
- Lease — ASC 842 / IFRS 16PV of the payments at your IBR, the liability unwind and the ROU asset — straight-line for a finance lease, the plug to a level cost for an operating one.Tool
- Accounting core (GL)The general ledger layer. Specs for 18 React components: JournalEntry, JournalEntryForm, JournalEntryTable, AccountPicker and 14 more.Doc
Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.
Told when Accounting core (GL) changes
Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.