Files
integreat/test/clj
Bryce 250bf0ea7f feat(ledger): make the Prime Cost Report readable against real ledger data
Rendering the report against a restored production database turned up
three things the tests could not have told me, and one they should have.

**Payroll posts on a pay run, not on a week.** A journal entry carries
the date it was posted, so a client paying every fortnight puts a
fortnight of labour on a single day. Against weekly columns the trend
read `—, 56.7%, —, 52.5%, -19.5%`, which is noise. Against fortnightly
columns the same client reads 18% to 27%. Hence the period control:
weekly, bi-weekly or four weeks, set to whatever the client's pay cycle
actually is.

**Zero is a claim, and it was the wrong one.** A period with no payroll
posted used to print 0.0% labour. No restaurant runs a week on no
labour; the pay run simply has not landed yet. That now reads as an em
dash, the trend line joins across the gap rather than diving to the
floor, and the footnote says what to do about it.

**A detail line printed larger than its own subtotal.** Averages
dropped empty periods from the denominator, so a band posting every
second period averaged over four periods while the total it rolled into
averaged over eight — $23,923 of "Payroll - General" inside $12,035 of
"Payroll". Money now averages across every period and ratios still
average only the periods they are known for, which is the distinction
that was missing.

The one the tests should have caught: the shared cell renderer calls
`dollars-0?` on a value before nil-punning it, so any nil cell was an
NPE at render time rather than a blank. Guarded, along with its
`:percent` branch, which also printed `%27.2` — sign on the wrong side.
Nothing else in the codebase reaches that branch.

Also here, in service of it being read rather than merely correct: a
summary strip with the latest labour percentage, what it usually runs
at, the change between them and a trend sparkline; a % of sales column
beside the average, as the workbook has; detail lines indented under
their subtotals; and an opt-in `height` on the shared table so a short
report stops reserving 70vh it does not use.

11 tests, 41 assertions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 23:50:00 -07:00
..