Getting paid / Payment history table
A payment history that shows what was paid against what
A list of payments received, each matched to the invoices it settled, printed so a customer can reconcile their own records against yours.
Why this block is harder than it looks
One payment can settle several invoices and one invoice can be settled by several payments, so the data is a many-to-many relationship being printed as a flat table. Flattening it either repeats the payment on every invoice row, which makes the payment column sum to more than was received, or repeats the invoice on every payment row with the same problem in reverse. Whichever you pick, a reader adding a column gets a wrong total, and they will add the column.
The decisions that make it work
Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.
- Choose one direction and state it in the heading. Payments received, with what each settled, is different from invoices raised, with what settled them, and mixing the two is the failure.
- Group rather than flatten: one row per payment with its allocations indented beneath it, so the payment appears once and its total is correct.
- Only total the grouping level, never the allocation level, and label the total with what it is a total of.
- Keep each payment and all its allocations in one break-inside: avoid group, so an allocation never appears on a page without the payment it belongs to.
- Show the unallocated remainder explicitly where a payment does not fully allocate. A payment that appears to vanish generates a call.
- Print the payment reference exactly as it arrived, in the monospace face, since that is the string the customer will search for in their own system.
The fragment
Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.
<div class="pay-history">
<div class="payment">
<div class="head">
<span class="date">09 Mar 2026</span>
<span class="ref">FT-88104471</span>
<span class="amt">2,000.00</span>
</div>
<ul class="alloc">
<li><span>Invoice 2026-118</span><span class="amt">1,240.00</span></li>
<li><span>Invoice 2026-121</span><span class="amt">640.00</span></li>
<li class="rest"><span>Unallocated</span><span class="amt">120.00</span></li>
</ul>
</div>
</div>
<style>
.pay-history .payment {
break-inside: avoid; /* a payment and its allocations are one unit */
margin-bottom: 8pt;
padding-bottom: 6pt;
border-bottom: 0.4pt solid #ddd;
}
.pay-history .head {
display: grid;
grid-template-columns: 26mm 1fr auto;
gap: 6pt;
font-weight: 700;
font-size: 9.5pt;
}
.pay-history .ref {
font-family: "IBM Plex Mono", ui-monospace, monospace;
font-weight: 400;
}
.pay-history .alloc { list-style: none; margin: 3pt 0 0; padding-left: 8mm; }
.pay-history .alloc li {
display: flex;
justify-content: space-between;
font-size: 8.5pt;
color: #444;
padding: 1pt 0;
}
.pay-history .alloc .rest { font-style: italic; }
.pay-history .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
</style>What breaks when it is built the obvious way
Flattening the relationship into one row per allocation with the payment amount repeated. The amount column then sums to far more than was ever received, and a customer reconciling the statement concludes you have their money twice.
How to prove it survived pagination
Render a payment that settles three invoices and an invoice settled by two payments. Add the top-level amount column: it should equal the money actually received. Then confirm no allocation row appears on a page without its payment above it.
Where it sits in a finished document
This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The statement of account template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.
Frequently asked
Will this fragment work on its own?
Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.
Why does it look right in a browser and wrong in the PDF?
Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.
Do I need a special option on the render request for this?
No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.
Other parts of a document
The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.
An overdue band that is unmissable without shouting
A band across the top of a reminder saying how overdue the amount is, sitting above an otherwise ordinary invoice layout.
A credit block that cannot be mistaken for an amount owed
The amount being credited or refunded, on a credit note, laid out so nobody reads it as another bill.
A QR payment block that still scans off the printed page
A machine-readable payment code beside the amount and reference, so a payer can scan instead of typing an account number.
A governing law and jurisdiction clause that stays findable
The short clause naming the law that applies and the courts that will hear a dispute, usually near the end of an agreement.
Statement of account, as a complete file
The whole document with this block already in place, ready to copy and change.
break-inside in paged output
The property carrying the weight here, with its real support status.
Every part of a document
The full list, grouped by the kind of problem the block poses.
Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.