Paid totals derived from the payment rows

What an invoice has been paid is recomputed from the live payment rows rather than patched, so a wrong total can heal itself.

What it is

Both the correction path and the online-payment path rebuild paid_amount as the sum of non-reversed payment rows, then derive balance and status from it. Nothing increments or subtracts a stored figure.

Also called: invoice total doesn't match the payments · balance is wrong · self-healing totals

See it
Paid totals derived from the payment rows
Prepared for
Gideon Alt
1140 Ridge Line Rd · Fair Play
Shell package$33,034
Concrete & site$9,590
Doors & windows$6,394
Trim & finish$4,262
Total
$53,280
Signature
Best shown as a before/after of the totals block: paid $20,410.12 on a $10,205.06 invoice, then the corrected $10,205.06 after a reversal. src/components/invoices/InvoiceViewer.tsx. Sample data — no customer information appears here.
How it works
  1. 1recomputeInvoiceTotals sums live payments, computes balance = total − paid, and sets status.
  2. 2Status can fall as well as rise: an invoice whose only payment was reversed stops saying paid but drops to 'sent', not 'draft'.
  3. 3recordStripePayment recomputes the same way, so concurrent payments on different sessions cannot lose an update.
  4. 4Re-lining an invoice preserves paid_amount instead of resetting it to zero.
Why we built it

A stored paid total drifts. Subtract a reversal once and it is right, but if the figure was already wrong, or two corrections land together, it stays wrong forever and the invoice permanently disagrees with the payments listed on it. The amount paid is rebuilt from the payment rows that still count every time it is needed, which makes it self-correcting; a separate fault that reset the paid figure to zero when an invoice was edited in place — resurrecting a balance the customer had already settled — was closed with it.

The problem
  • Stored totals permanently disagreeing with the payment list.
  • In-place edits resurrecting a balance that had been paid.
  • Concurrent payment writes overwriting each other.
Sound familiar?
What you get
The invoice always agrees with the payments printed on it.
A historically wrong total corrects itself on the next write.

See it on your own jobs

Twenty minutes, your numbers, no slide deck. We’ll build one of your real buildings in front of you and send you the estimate link at the end — yours to keep either way.

or keep browsing features →