Table of Contents
#178 — Marking a Draft invoice paid records the payment and the cash but never changes the status, so a paid invoice reads as unpaid ev (Resolved)
← Back to bug list · View issue #178 in MantisBT
Reported by: Nour aboulhosn on 2026-08-06T12:03:34+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-06T14:29:12+01:00
Severity: major
Priority: high
Reproducibility: have not tried
Category: General
Description: Pressing “Mark as paid” on a Draft invoice does half of what it says. The money side works: a payment is recorded, the cash account rises by the invoice amount, “Total collected” rises by the same, and the app confirms “Invoice updated.” The status side never happens — the invoice stays Draft in the list, and pressing the button again reports success and still leaves it Draft.
Two things follow. A $200.00 invoice sits marked Draft while its `$200.00` payment is banked and counted, so anyone scanning the list for who still owes money will chase a customer who has already paid. And because the stored status is not `paid`, refunds are refused outright — *“Only a paid invoice can be refunded. Mark this one as paid first.”* — telling the user to do the exact thing they just did.
The defect is specific to the Draft → paid transition. Draft → Sent → Paid works correctly: the status becomes Paid, a refund is then accepted, and no second payment is created (cash delta `0.00`), so the payment side is properly idempotent. Only the status write is skipped when moving straight from Draft to paid.
The fix is to set the stored status to `paid` whenever “Mark as paid” succeeds, regardless of the prior state, writing status and payment in the same transaction so they cannot disagree. If a `sent` precondition is intended, it must reject the action visibly rather than reporting “Invoice updated.” and banking the money anyway.
Steps to Reproduce: 1. Invoices → New invoice: pick a customer, one line, quantity `1`, unit price `200.00`. Save — it is created as Draft. 2. Note the dashboard's Total collected and the Cash balance on Cash & accounts. 3. Open the invoice, press “Mark as paid” — the app confirms “Invoice updated.” 4. The money moved: a `$200.00` payment is listed, and both Total collected and the Cash balance rose by $200.00. 5. Go to Invoices — the invoice still shows the Draft badge. Press “Mark as paid” again: same confirmation, still Draft. 6. Try to refund it — refused with “Only a paid invoice can be refunded. Mark this one as paid first.” 7. Workaround: press “Mark as sent” (becomes Sent), then “Mark as paid” (becomes Paid). No extra payment is created and a refund is now accepted.
Resolution: Fixed.
WHAT “Mark as paid” on a Draft invoice recorded the payment and moved the cash but never changed the status, so a paid invoice kept reading Draft — and refunds were then refused with “Only a paid invoice can be refunded. Mark this one as paid first”, which is the thing the user had just done.
WHERE app/controllers/InvoiceController.php — updateStatus(), the `$to === 'paid'` branch.
WHY Two rules disagreed, silently. Invoice::TRANSITIONS allows draft → paid, so the action was accepted and the payment written. But Invoice::recomputeSettlement() — which is the only thing in the app that writes a settlement status — deliberately refuses to touch a draft or a void, because a bill nobody has agreed to must not become “paid” just because money was filed against it. So the money side ran and the status side was skipped, and nothing reported a problem.
FIX When the invoice is currently a draft, it is issued (status → sent) in the same action before the payment is recorded, so recomputeSettlement() then settles it normally. Nothing writes 'paid' by hand; the status still follows the payment rows. The audit row still records the whole move as `draft → paid`.
The ticket's alternative — refuse draft → paid visibly — was considered and rejected: writing an invoice and being paid on the spot without ever “sending” anything is the commonest shape in this product, and making that a two-step chore buys nothing. Issuing it is also the honest reading, since money cannot arrive for something never issued.
VERIFIED (real HTTP against the running app, not a unit test)
created: status=draft paid_at=NULL payments=0.00 after Mark as paid: status=paid paid_at=2026-08-06 payments=200.00 pressed again: status=paid payments=200.00 (idempotent, no second payment) refund form: now offered
Full suite 364 tests / 13,037 assertions green; lint clean; 88-request authenticated sweep in both languages with 0 problems.
Activity / Notes
- 2026-08-06T14:29:10+01:00 - Claude: Fixed.
WHAT “Mark as paid” on a Draft invoice recorded the payment and moved the cash but never changed the status, so a paid invoice kept reading Draft — and refunds were then refused with “Only a paid invoice can be refunded. Mark this one as paid first”, which is the thing the user had just done.
WHERE app/controllers/InvoiceController.php — updateStatus(), the `$to === 'paid'` branch.
WHY Two rules disagreed, silently. Invoice::TRANSITIONS allows draft → paid, so the action was accepted and the payment written. But Invoice::recomputeSettlement() — which is the only thing in the app that writes a settlement status — deliberately refuses to touch a draft or a void, because a bill nobody has agreed to must not become “paid” just because money was filed against it. So the money side ran and the status side was skipped, and nothing reported a problem.
FIX When the invoice is currently a draft, it is issued (status → sent) in the same action before the payment is recorded, so recomputeSettlement() then settles it normally. Nothing writes 'paid' by hand; the status still follows the payment rows. The audit row still records the whole move as `draft → paid`.
The ticket's alternative — refuse draft → paid visibly — was considered and rejected: writing an invoice and being paid on the spot without ever “sending” anything is the commonest shape in this product, and making that a two-step chore buys nothing. Issuing it is also the honest reading, since money cannot arrive for something never issued.
VERIFIED (real HTTP against the running app, not a unit test)
created: status=draft paid_at=NULL payments=0.00 after Mark as paid: status=paid paid_at=2026-08-06 payments=200.00 pressed again: status=paid payments=200.00 (idempotent, no second payment) refund form: now offered
Full suite 364 tests / 13,037 assertions green; lint clean; 88-request authenticated sweep in both languages with 0 problems.
Full History
| Date | User | Field | Change |
|---|---|---|---|
| 2026-08-06T12:03:34+01:00 | Nour aboulhosn | issue-new | New Issue |
| 2026-08-06T14:29:10+01:00 | Claude | note-added | Note Added: 0000134 |
| 2026-08-06T14:29:12+01:00 | Claude | tag-added | Tag Attached: done-by-claude |
| 2026-08-06T14:29:12+01:00 | Claude | Assigned To | ⇒ Claudine |
| 2026-08-06T14:29:12+01:00 | Claude | Status | new ⇒ resolved |
| 2026-08-06T14:29:12+01:00 | Claude | Resolution | open ⇒ fixed |
Synced automatically from MantisBT issue #178.
