What it is
A residential inter-school tournament takes registration fees, a refundable caution deposit, participation and accommodation charges and a per-head charge for identity cards, from dozens of schools over a single week. Before this, it was run from a spreadsheet and a register book.
The desk is staffed by three people during the event, working at the same time on the same records, and every document they produce is printed and handed to a school representative who is standing in front of them.
That last detail decided most of the design. A billing system whose output can be reprinted at leisure is a different problem from one whose output is already in somebody's hand.
The problem
The deposit is held per school, not per invoice
One school may be invoiced several times across a week, but the caution deposit is one deposit for the season. Grouping payments by invoice gets the balance wrong in both directions — it double-counts the deposit for a school billed twice, and loses it for a school billed late.
Schools leave in stages, so a refund covers a group
A contingent does not go home together. Three groups from the same school might leave on days two, four and five, and each one is owed for the accommodation nights it did not use. A refund is therefore attached to a departing group, not to a school and not to an invoice.
Local schools owe nothing for accommodation, but still owe for ID cards
Teams from the host city go home each night. The obvious implementation is a conditional — if the school is local, skip the accommodation charge — and that conditional then has to be remembered in the refund calculation, the balance calculation, the Excel export and every future report.
Two people can press Submit on the same refund in the same instant
At a busy desk this is not a theoretical race. Without a guard, the same departing group is refunded twice and the discrepancy surfaces weeks later during reconciliation, with no record of how it happened.
An invoice cannot be corrected, because the school is holding it
If a printed document is edited in place, the paper and the database now disagree and nothing on either of them says so. The register book no longer reconciles, and the person who finds the gap has no way to tell a correction from a mistake.
What we built
The special case lives in the data, not the code
A local school's invoice snapshots both accommodation rates as zero at the moment it is raised. Every later calculation — refunds, balances, exports — then comes out correct without knowing that local schools exist. There is no conditional to forget.
Every invoice stores the rates it was raised under
Changing a rate next season does not rewrite last season's documents. An invoice is a record of what was agreed on the day, so the rates travel with it rather than being looked up again at render time.
Concurrency is held at the database, not in the application
Refunds run inside a serializable transaction behind a partial unique index, so the second of two simultaneous submissions cannot succeed. The person who loses the race does not see an error page — they are told where that school actually stands now, which is the thing they were trying to find out.
Wrong invoices are cancelled and reissued, never edited
Moving an invoice to trash requires a typed reason, marks the document visibly cancelled, and offers to raise the correct one immediately with the school already selected. The cancelled number is retained and never reused, and the Excel export carries a separate Cancelled sheet so the physical register reconciles without anybody writing in the margin.
A refund of zero is still issued
A group that stayed the full week is owed nothing, but something has to record that those people have left — otherwise the school's remaining head count is wrong for the rest of the event. The document is raised for zero and carries the note.
A guided tour written for somebody's first morning
The desk is staffed by people who were handed the system the week of the event. The product tour walks the real screens in the order the day happens, and a step whose element is not on screen is skipped rather than shown pointing at nothing.
What the client has now
- Three people work the same records simultaneously without double-issuing a refund or a deposit.
- Every printed document can be traced: who raised it, under which rates, whether it was cancelled and why.
- The Excel export reconciles against the register book without manual annotation, including cancellations.
- The whole financial workflow — invoices, part-payments, partial refunds, deposits, cancellations, audit log, PDF documents and exports — is six data models.
What we took from it
Push the exception into the data and the code stays simple
The instinct when a rule has an exception is to write the exception as a branch. That branch then has to be remembered everywhere downstream, and it will not be. Setting the rate to zero at the moment the document is created makes every subsequent calculation correct by arithmetic rather than by vigilance — and the invoice, which is the thing the client actually argues about, states plainly what it charged.