Skip to content

ProfitAndLoss

P&L with period comparison and variance.
Implemented
Status
Implemented
Family
6 of 13
Registry
@lopifi/profit-and-loss
npx shadcn@latest add @lopifi/theme @lopifi/profit-and-loss

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

Revenue → COGS → Gross profit → Operating expenses → Operating income → Other → Net income.

  • Margin rows (gross %, operating %, net %) rendered as a Percent level, with their period-over-period change in points, visually distinguished from the money rows — a percentage in a column of dollars needs to not look like dollars.
  • Comparison modes: prior period, prior year, budget, forecast. Each with its own variance column.
  • Expense rows are polarity="inverted". An increase in COGS is not good news, and defaulting it to green is the bug this whole system exists to prevent.
  • Optional per-line WaterfallChart drill-in showing what drove the change.

Lifted verbatim from Statements. 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/profit-and-loss.tsx

Lopifi dependencies · 14
cncolumn-managerfiscal-periodformat-moneyiconsmoneymoney.typespercentperiod-changerulestatement-tabletooltipuse-scroll-edgesvariance-cell
npm packages
@base-ui-components/reactclass-variance-authorityclsxtailwind-merge
Registry entry
/r/profit-and-loss.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/profit-and-loss.tsx
"use client";

import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import {
  type DrilldownTarget,
  type StatementHeader,
  type StatementLine,
  StatementTable,
} from "@/components/ledger/statement-table";

export interface ProfitAndLossProps {
  className?: string;
  /** Offer the period columns to hide. See `StatementTable`. */
  columnManager?: boolean;
  header: Omit<StatementHeader, "statement">;
  /** Margin rows are Percent, not Money, and visually distinguished. */
  margins?: StatementLine[];
  materiality?: { absolute: number; relative: number };
  /** Caps the scroller so the column headers freeze. See `StatementTable`. */
  maxHeight?: number;
  /** EBITDA is not a P&L line. If shown, it appears below, separated. */
  nonGaap?: React.ReactNode;
  onDrilldown?: (line: StatementLine, target: DrilldownTarget) => void;
  periods: string[];
  /** Revenue → COGS → Gross profit → Opex → Operating income → Other → Net income. */
  sections: StatementLine[];
  showVariance?: boolean;
}

/**
 * Expense rows are `polarity="inverted"` — an increase in COGS is not good
 * news, and defaulting it to green is the bug this whole system exists to
 * prevent. The polarity is read from the account type, not chosen per call.
 */
export function ProfitAndLoss({
  header,
  periods,
  sections,
  margins = [],
  showVariance = true,
  materiality,
  onDrilldown,
  nonGaap,
  maxHeight,
  columnManager,
  className,
}: ProfitAndLossProps) {
  const lines = React.useMemo(
    () => [...sections, ...(margins.length ? [MARGIN_SECTION, ...margins] : [])],
    [sections, margins],
  );

  return (
    <div className={cn("w-full", className)}>
      <StatementTable
        columnManager={columnManager}
        header={{ ...header, statement: "Profit and loss" }}
        lines={lines}
        materiality={materiality}
        maxHeight={maxHeight}
        onDrilldown={onDrilldown}
        periods={periods}
        roundingNote="Figures are rounded once, at the display boundary. Parts may not sum."
        showVariance={showVariance}
      />
      {nonGaap ? (
        // Non-GAAP measures appear below net income, in a separated block,
        // never inside the P&L.
        <section className="mt-6 rounded-xl border border-dashed border-border bg-surface-sunken p-6">
          <h3 className="text-title-sm font-medium">Non-GAAP measures</h3>
          <p className="mb-4 text-caption text-text-secondary">
            Not defined by the framework. Every adjustment is named below.
          </p>
          {nonGaap}
        </section>
      ) : null}
    </div>
  );
}

const MARGIN_SECTION: StatementLine = {
  id: "margins",
  label: "Margins",
  level: 1,
  values: [],
  variant: "section",
};

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 Statements

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where ProfitAndLoss 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.

Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.

Told when Statements 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.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.