PaymentSuggestion
- Status
- Implemented
- Family
- 10 of 13
- Registry
- @lopifi/payment-suggestion
npx shadcn@latest add @lopifi/theme @lopifi/payment-suggestionThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Given a lump sum, proposes the set of open invoices that sums to it exactly. Multiple valid combinations are ranked oldest-first. Shows the basis, not a bare confidence score.
Lifted verbatim from Receivables (AR). 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/payment-suggestion.tsx
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/payment-suggestion.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
"use client";
import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { Button } from "@/components/ledger/button";
import { SparklesIcon } from "@/components/ledger/icons";
import { Money } from "@/components/ledger/money";
export type InvoiceCandidate = { id: string; number: string; balance: number; age: number };
export interface PaymentSuggestionProps {
candidates: InvoiceCandidate[];
className?: string;
lumpSum: MoneyValue;
onAccept?: (ids: string[]) => void;
}
/**
* Given a lump sum, propose the sets of open invoices that sum to it
* exactly. Multiple valid combinations are ranked oldest-first, and the
* basis is shown — not a bare confidence score.
*/
export function PaymentSuggestion({ lumpSum, candidates, onAccept, className }: PaymentSuggestionProps) {
const target = Number(lumpSum.amount);
const combos = React.useMemo(() => exactSubsets(candidates, target).slice(0, 3), [candidates, target]);
if (combos.length === 0) {
return (
<p className={cn("text-body text-text-secondary", className)}>
No combination of open invoices sums to <Money size="sm" tone="inherit" value={lumpSum} /> exactly.
</p>
);
}
return (
<div className={cn("space-y-2", className)}>
<h3 className="flex items-center gap-2 text-label font-medium text-text-secondary">
<SparklesIcon aria-hidden="true" className="size-3.5 text-accent" />
Combinations summing to <Money size="xs" tone="inherit" value={lumpSum} /> exactly
</h3>
<ul className="space-y-2">
{combos.map((combo, i) => (
<li
className="flex flex-wrap items-center gap-3 rounded-md border border-border bg-surface p-3"
key={i}
>
<span className="flex-1">
<span className="reference-numeric block text-body">
{combo.map((c) => c.number).join(" + ")}
</span>
<span className="block text-caption text-text-secondary">
{combo.length} invoices · oldest {Math.max(...combo.map((c) => c.age))} days
</span>
</span>
<Button onClick={() => onAccept?.(combo.map((c) => c.id))} size="sm" variant="primary">
Apply this set
</Button>
</li>
))}
</ul>
</div>
);
}
/** Small-n exact subset search, ranked oldest-first. */
function exactSubsets(candidates: InvoiceCandidate[], target: number): InvoiceCandidate[][] {
const results: InvoiceCandidate[][] = [];
const sorted = [...candidates].sort((a, b) => b.age - a.age);
const limit = Math.min(sorted.length, 16);
const walk = (index: number, running: number, picked: InvoiceCandidate[]) => {
if (results.length >= 8) return;
if (running === target && picked.length > 0) {
results.push([...picked]);
return;
}
if (running > target || index >= limit) return;
picked.push(sorted[index]);
walk(index + 1, running + sorted[index].balance, picked);
picked.pop();
walk(index + 1, running, picked);
};
walk(0, 0, []);
return results;
}
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 Receivables (AR)
- InvoiceFormWith the revenue-recognition preview per line.
- InvoiceDetailBalance due as the hero, not total.Spec
- InvoiceRegisterGapless-numbering check surfaced.Spec
- CashApplicationThe highest-value screen in AR. Every case, not just the happy one.
- UnappliedCashPanelNever revenue; net credit balances flagged as liabilities.Spec
- CreditNoteFormDistinct from a refund and from a write-off.Spec
- CollectionsWorklistPromise-to-pay as a first-class object.Spec
- DunningTimelinePer customer, not per invoice.Spec
- CustomerStatementPrintable. Print styles are first-class.Spec
- CustomerCreditPanelLimit and exposure together, with hierarchy roll-up.Spec
- SalesOrderTableBacklog, visually separated from ledger-derived numbers.Spec
- ArMetricsPanelDSO with its method stated.Spec
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Receivables (AR) — the family specThe four-layer specification this component was built against, before it was written.Doc
- Receivables — order to cashThe family running, with real figures in it, in both themes and at every density.Live
- CatalogAll 179 components, specified before they are written.Doc
- InvoiceA claim on a customerTerm
Elsewhere in the system
Where PaymentSuggestion 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.
- PaymentSuggestion, runningThe ar showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Which invoices make this deposit?A deposit against forty open items. Exact subset-sum over minor units — no floating point.Tool
- Payments and allocationHow is a payment tied to the documents it settles?API
- Receivables (AR)Receivables (AR) — specs for 13 React components: InvoiceForm, InvoiceDetail, InvoiceRegister, CashApplication and 9 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 Receivables (AR) 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.