User Tools

Site Tools


wiki:manara:bugs:151

#151 — A contact-originated Sale invoice can never be voided or refunded through any reachable path (Resolved)

← Back to Manara Bugs · View issue #151 in MantisBT


Reported by: Khaled Tarabay on 2026-07-30T14:27:53+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-01T07:26:09+01:00
Severity: major
Priority: immediate
Reproducibility: always
Category: General

Description: The task's premise — that a Sale against a Client “creates a normal Draft sale invoice through the existing Billing engine” and should therefore be voidable and refundable like any ordinary customer invoice — does not hold. The exact same “manage it from the contact's page” guard that blocks editing a Purchase Bill (documented in BUG-PB04) also blocks the dedicated /void route and the Refunds & Credits flow for a Sale-kind contact invoice, even after it has been fully Issued, Collected, and a real Payments-module row exists for it. Recorded a real $300.00 Sale on Client-only contact 71 (DH Void 760899), producing Sale invoice LG-INV-169 (id 251). Issued it and collected the full $300.00 through the real contact-ledger “Collect” form — the invoice correctly reached Status: Paid, PAID $300.00, BALANCE DUE $0.00, and (unlike a Purchase Bill) a real row for it appeared in the global /payments list, confirming this is genuinely, unambiguously collected money, not a mirrored display figure. Tried every path a staff member or an attacker could reach to correct or reverse this invoice:

GET /billing/251/edit — 302s straight to /contacts/71, identical to the Purchase Bill behavior already documented in BUG-PB04. No invoice_status_id select is ever rendered for this invoice. The invoice detail page itself never renders a “Void Invoice” button for this invoice at all (diffed the full button/link list against a control invoice, which does have one) — the control isn't merely disabled, it's absent. The ledger row's own “Settle” cell only ever offers “Issue” (pre-collection) or “Collect” (post-issue) — never a cancel/void action. Raw-POST bypass straight to the invoice's own dedicated void route, POST /billing/251/void — the real route a normal invoice's “Void Invoice” button submits to — returned 302 to /contacts/71 and left the invoice completely unchanged (Status: Paid throughout). A control probe against the identical route on a genuine non-contact Issued invoice (id 239) succeeded outright and flipped it to Status: Void, confirming the route itself works and the block is specific to contact-originated invoices. /credit-notes/create?invoice_id=251 reproduces BUG-PB01's misleading banner, but now against a Sale invoice with real collected cash rather than a Purchase Bill's mirrored figure: it displays “Linked to invoice LG-INV-169 - DH Void 760899 - Internet Service.” at the top, while the invoice_id <select> underneath has no option for invoice 251 among its 87 entries and resolves to an empty value. A raw-POST bypass straight to POST /credit-notes with invoice_id=251&type=refund&amount=100.00 returned HTTP 200 (no redirect, i.e. rejected) with zero new row in /credit-notes and the invoice untouched. The net effect: $300.00 in real, collected, customer money sitting on a contact-originated Sale invoice has no in-product path to reverse, refund, or void, whereas the identical action on an ordinary Customer invoice works via one click. This is a materially larger business-capability gap than BUG-PB01/PB04 (which only concerned Purchase Bills, where the pattern is arguably intentional since no real money ever flows through Payments for that kind) — here it blocks a genuinely urgent operational need (undoing an erroneous or disputed real charge) with no documented alternative and no on-page indication that the limitation exists until the control is found to be silently missing or the raw route is tried. The fix should either extend the existing Billing void/refund engine to recognize and correctly process contact-originated Sale invoices (updating both the invoice and the contact ledger atomically), or, if this is intentionally out of scope for the initial release, the invoice detail page should say so explicitly rather than simply omitting the control, and the Refunds & Credits banner should stop claiming a link that doesn't exist (same root-cause fix as BUG-PB01, now proven to also apply to Sale-kind contact invoices).

Steps to Reproduce: Create a Client contact, record a real Sale, Issue it, and Collect full payment through the contact ledger — confirm Status: Paid and a real row in /payments. Navigate to /billing/<id>/edit — confirm the redirect to /contacts/<id> and the absent status select. Raw-POST invoice_id=<csrf> to /billing/<id>/void — confirm 302 back to the contact page and the invoice's status unchanged, contrasted against the same route succeeding on a normal invoice. Navigate to /credit-notes/create?invoice_id=<id> — observe the “Linked to invoice …” banner while the invoice_id select has no matching option. Raw-POST to /credit-notes with that invoice_id — confirm no credit-note row is created and the invoice is unchanged.

Resolution: Fixed (the reachable, safe subset). A contact-originated Sale/Purchase invoice had NO void/refund path anywhere — Billing void/edit/refund are blocked for contact invoices, the detail page omits Void, and the ledger row only offered Issue/Collect.

FIX: - New POST /contacts/{id}/transactions/{txnId}/void → ContactController::voidTransaction() (gated contacts.manage, same as Issue/Collect) voids the linked invoice ONLY when amount_paid == 0. An unpaid contact invoice has no payments rows and no finance-ledger entries, so voiding is a clean status flip with nothing to reverse. A part/fully-paid one is refused with an honest message (reverse via a refund/finance adjustment). - ContactTransaction::balancesFor() now EXCLUDES rows whose linked invoice is void, so cancelling drops the owed figure from the tile; the ledger row stays for audit (Balance shows 0 for a void row). - A “Cancel” button appears on the contact page ledger row for an unpaid, non-void contact invoice. - billing/show.php now shows an EXPLICIT note for a contact invoice (instead of silently omitting the controls) saying where it is managed. The misleading banner is fixed by the #147 change (applies to Sale-kind contact invoices too).

Scope: a full refund/reverse of a COLLECTED contact sale (reversing real payments + the finance credit) is a larger feature deliberately left out — the unpaid-void path + honest note cover the reachable, safe operations, and the page no longer hides that limitation.

Files: app/controllers/ContactController.php, app/classes/Crm/ContactTransaction.php, app/routes/web.php, app/views/contacts/show.php, app/views/billing/show.php. No schema change.

Activity / Notes

  • 2026-08-01T07:26:06+01:00 - Claude: Fixed (the reachable, safe subset). A contact-originated Sale/Purchase invoice had NO void/refund path anywhere — Billing void/edit/refund are blocked for contact invoices, the detail page omits Void, and the ledger row only offered Issue/Collect.

FIX: - New POST /contacts/{id}/transactions/{txnId}/void → ContactController::voidTransaction() (gated contacts.manage, same as Issue/Collect) voids the linked invoice ONLY when amount_paid == 0. An unpaid contact invoice has no payments rows and no finance-ledger entries, so voiding is a clean status flip with nothing to reverse. A part/fully-paid one is refused with an honest message (reverse via a refund/finance adjustment). - ContactTransaction::balancesFor() now EXCLUDES rows whose linked invoice is void, so cancelling drops the owed figure from the tile; the ledger row stays for audit (Balance shows 0 for a void row). - A “Cancel” button appears on the contact page ledger row for an unpaid, non-void contact invoice. - billing/show.php now shows an EXPLICIT note for a contact invoice (instead of silently omitting the controls) saying where it is managed. The misleading banner is fixed by the #147 change (applies to Sale-kind contact invoices too).

Scope: a full refund/reverse of a COLLECTED contact sale (reversing real payments + the finance credit) is a larger feature deliberately left out — the unpaid-void path + honest note cover the reachable, safe operations, and the page no longer hides that limitation.

Files: app/controllers/ContactController.php, app/classes/Crm/ContactTransaction.php, app/routes/web.php, app/views/contacts/show.php, app/views/billing/show.php. No schema change.

Full History

Date User Field Change
2026-07-30T14:27:53+01:00 Khaled Tarabay issue-new New Issue
2026-08-01T07:26:00+01:00 Claude Assigned To ⇒ Claudine
2026-08-01T07:26:03+01:00 Claude tag-added Tag Attached: done-by-claude
2026-08-01T07:26:06+01:00 Claude note-added Note Added: 0000109
2026-08-01T07:26:09+01:00 Claude Status new ⇒ resolved

Synced automatically from MantisBT issue #151.

wiki/manara/bugs/151.txt · Last modified: by mantisbot