← Back to bug list · View issue #203 in MantisBT
Reported by: Nour aboulhosn on 2026-08-11T10:02:29+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-11T10:39:21+01:00
Severity: major
Priority: high
Reproducibility: have not tried
Category: General
Description: A `$100.00` credit on an unpaid `$500.00` invoice is handled correctly everywhere except the ledger. The invoice drops to `Still owed $400.00`, “Waiting to be paid” falls by `$100.00`, and the cash screen does not move — all right. The trial balance instead moves “Cash and bank” by −$100.00 and “Money owed to us” by $0.00, the exact opposite of both.
The correct entry credits receivables and touches no cash. The app posts a credit through the refund path — `Dr Refunds given / Cr Cash` — so the ledger reports money leaving a bank account that never paid anything out, while still claiming the customer owes the full amount.
Nothing on the statement reveals it, because `Dr Refunds given / Cr Cash` is internally balanced — the totals still agree, so the ledger looks sound while both figures are wrong. Crediting should credit receivables and leave cash alone.
Steps to Reproduce: 1. Note Reports → Trial balance: “Cash and bank” and “Money owed to us”. 2. Raise a sales invoice for `1 × $500.00` and use Mark as sent. Both the screen receivable and the trial balance receivable rise by `$500.00`, correctly. 3. In Refunds, choose Credit, amount `100.00`, and save. “Credit recorded.” appears. 4. The invoice reads `Still owed $400.00`, “Waiting to be paid” has fallen `$100.00`, and Cash & accounts is unchanged — all correct. 5. Reopen the trial balance. “Cash and bank” has fallen by `$100.00` and “Money owed to us” has not moved at all. 6. “Refunds given” has risen by the credit, confirming a credit is being booked down the refund path.
Resolution: Fixed.
WHAT WAS WRONG A credit was being posted down the refund path — Dr Refunds given / Cr Cash — so the statement reported money leaving a bank account that had paid nothing out, while still claiming the customer owed the full amount. Exactly as reported: cash −$100, receivables unmoved.
WHY IT WAS INVISIBLE That entry is internally balanced, so the debit and credit totals still agreed while both figures were wrong. Nothing on the page could reveal it.
WHERE app/classes/Billing/TrialBalance.php. `refundTotal()` and `refundTaxTotal()` summed the `refunds` table with NO filter on `kind`, even though Refund::KINDS already documents the rule out loud — “Only 'refund' appears in a cash figure”. The two kinds were read by one query.
THE FIX Both queries now take a `kind` (whitelisted against Refund::isValidKind(), so it can never become a way into the SQL), and the statement composes four figures instead of two. The entries are now:
refund on a sale Dr Refunds given + Dr Tax payable / Cr Cash credit on a sale Dr Credits given + Dr Tax payable / Cr Money owed to us
A credit on a purchase is the mirror and comes off payables. Credits get their own two rows rather than being folded into the refund rows: both reduce income, but only one of them involved money, and reading them as one figure is how the wrong entry stayed hidden. Zero rows are dropped, so a company that never issues a credit never sees them.
VERIFIED On real books, measuring the delta rather than the absolute (these books already hold $12,797 of cash and $5,400 of receivables). Raised a $500 sales invoice, marked it sent, credited $100:
cash moved 0.00 (was −100.00) receivable moved −100.00 (was 0.00) Refunds given unchanged Credits given +83.33 — the net; the other $16.67 is tax handed back statement still balances
Full suite green: 373 tests, 13,266 assertions.
WHAT WAS WRONG A credit was being posted down the refund path — Dr Refunds given / Cr Cash — so the statement reported money leaving a bank account that had paid nothing out, while still claiming the customer owed the full amount. Exactly as reported: cash −$100, receivables unmoved.
WHY IT WAS INVISIBLE That entry is internally balanced, so the debit and credit totals still agreed while both figures were wrong. Nothing on the page could reveal it.
WHERE app/classes/Billing/TrialBalance.php. `refundTotal()` and `refundTaxTotal()` summed the `refunds` table with NO filter on `kind`, even though Refund::KINDS already documents the rule out loud — “Only 'refund' appears in a cash figure”. The two kinds were read by one query.
THE FIX Both queries now take a `kind` (whitelisted against Refund::isValidKind(), so it can never become a way into the SQL), and the statement composes four figures instead of two. The entries are now:
refund on a sale Dr Refunds given + Dr Tax payable / Cr Cash credit on a sale Dr Credits given + Dr Tax payable / Cr Money owed to us
A credit on a purchase is the mirror and comes off payables. Credits get their own two rows rather than being folded into the refund rows: both reduce income, but only one of them involved money, and reading them as one figure is how the wrong entry stayed hidden. Zero rows are dropped, so a company that never issues a credit never sees them.
VERIFIED On real books, measuring the delta rather than the absolute (these books already hold $12,797 of cash and $5,400 of receivables). Raised a $500 sales invoice, marked it sent, credited $100:
cash moved 0.00 (was −100.00) receivable moved −100.00 (was 0.00) Refunds given unchanged Credits given +83.33 — the net; the other $16.67 is tax handed back statement still balances
Full suite green: 373 tests, 13,266 assertions.
| Date | User | Field | Change |
|---|---|---|---|
| 2026-08-11T10:02:29+01:00 | Nour aboulhosn | issue-new | New Issue |
| 2026-08-11T10:39:11+01:00 | Claude | Assigned To | ⇒ Claudine |
| 2026-08-11T10:39:17+01:00 | Claude | tag-added | Tag Attached: done-by-claude |
| 2026-08-11T10:39:19+01:00 | Claude | note-added | Note Added: 0000161 |
| 2026-08-11T10:39:21+01:00 | Claude | Status | new ⇒ resolved |
Synced automatically from MantisBT issue #203.