Table of Contents

#176 — Tax is enabled and a rate is saved, but no invoice ever adds or backs out tax — while the printed invoice still carries the tax (Resolved)

← Back to bug list · View issue #176 in MantisBT


Reported by: Nour aboulhosn on 2026-08-06T12:01:30+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-06T14:56:42+01:00
Severity: major
Priority: high
Reproducibility: have not tried
Category: General

Description: With tax on at 20%, label VAT, registration number GB123456789, and “prices already include tax” off, an invoice of `1 × $200.00` totals $200.00. It should be $240.00 (net $200 + VAT $40). The detail page and the printable page contain no subtotal row, no tax row and no rate anywhere — the only amounts printed are `$200.00`, `$200.00`, `$200.00`.Inclusive mode fails in the other direction: at 15% inclusive, `$115.00` prints as `Total $115.00` with no breakdown, where it must show net $100.00 and VAT $15.00. The feature is not dormant, though — the print header does render `VAT GB123456789`, so the app knows tax is on and presents the document as a tax invoice while charging no tax. In exclusive mode the business under-charges every customer by the full tax amount and owes tax it never collected.

The fix is to apply the saved rate at invoice creation: compute tax per taxable line and show Subtotal (net), a tax row labelled with the configured label and rate, and a gross Total, on both the detail and printable pages. In inclusive mode the entered price is the gross, so net = gross ÷ (1 + rate) and tax = gross − net must be derived and shown. Tax figures must be stored on the invoice at issue time, not recomputed from current settings. Until tax is calculated, the registration number should not be printed, because it presents an inaccurate tax invoice.

Steps to Reproduce: 1. Settings → Tax: tick “Charge tax on invoices”, label `VAT`, rate `20`, leave “Prices already include tax” unticked, registration number `GB123456789`. Save. 2. Invoices → New invoice: pick a customer, add one line — quantity `1`, unit price `200.00`. Save. 3. The invoice totals $200.00, with no subtotal and no VAT line. It should be $240.00. 4. Click “open the printable page”: the header prints `VAT GB123456789`, but the document shows only `$200.00` with no tax row. 5. Now tick “Prices already include tax”, set the rate to `15`, and issue an invoice for `115.00` — it prints `Total $115.00` with no net/tax breakdown.

Resolution: Fixed.

WHAT Tax switched on with a rate saved, and no invoice ever added or backed out tax. An invoice of 1 x $200.00 at 20% totalled $200.00 instead of $240.00, with no subtotal row, no tax row and no rate anywhere — while the printed header still rendered the tax registration number, presenting the document as a tax invoice while charging no tax.

WHERE app/classes/Billing/InvoiceLineItem.php — fromForm(), plus the matching argument in app/controllers/InvoiceController.php.

WHY — and it was none of the three obvious places The rate WAS being copied onto each invoice correctly (InvoiceController stamps `tax_rate` and `tax_inclusive` from the company's settings on every save). App\Billing\Tax was computing correctly the whole time — tests/Billing/TaxTest.php has been proving it over 60 generated invoices. The settings screen saved correctly.

They were simply being handed a TAXABLE NET OF ZERO.

`fromForm()` decided a line's taxability with `array_key_exists($index, $taxable)` — “present means ticked”, which is how an unchecked HTML checkbox behaves. Its own comment read: “The form renders the boxes ticked by default, so the value here is the reader's actual choice.”

The form has never rendered that control. So `$taxable` was always the empty array, the test was always false, and every line of every invoice was stored `taxable = 0` — against a schema whose default for that column is TRUE. Tax on a taxable net of nothing is nothing.

A comment describing behaviour that was never implemented, on the one line where the failure is silent and arithmetic.

FIX `fromForm()` takes `$taxableChoiceOffered`. When the form did not offer the choice — which is every client today — the line takes the column's own default and is TAXABLE. When it does, the ticks are honoured exactly.

⭐ “NO CONTROL” MUST NOT LOOK LIKE “ALL UNTICKED”. An absent checkbox and an unticked one post identically, so presence alone can never be trusted; the caller has to say whether the choice was on screen at all. That is the same trap SettingsController::SECTIONS exists for, and getting it wrong here is what made this invisible for as long as it existed.

Per-line taxability is deliberately NOT added to the form. It is an advanced control nobody asked for, it would fight the `name=“description[]“` array syntax the line editor uses (an unchecked box posts nothing, so the indices would shift), and simplicity on this form is a stated product goal. The column and the machinery remain, and the new argument is the hook to switch it on later without re-introducing the ambiguity.

VERIFIED against the running app, with the ticket's own figures

EXCLUSIVE 20% on 1 x 200.00
  stored rate=20.000 inclusive=0, net=200.00, taxable_net=200.00
  -> subtotal 200.00, tax 40.00, GROSS 240.00
  invoice page renders a VAT row and shows 240.00
INCLUSIVE 15% on 115.00
  -> net 100.00, tax 15.00, gross 115.00

Full suite 364 tests / 13,042 assertions green; lint clean; 88-request authenticated sweep in both languages, 0 problems.

Activity / Notes

WHAT Tax switched on with a rate saved, and no invoice ever added or backed out tax. An invoice of 1 x $200.00 at 20% totalled $200.00 instead of $240.00, with no subtotal row, no tax row and no rate anywhere — while the printed header still rendered the tax registration number, presenting the document as a tax invoice while charging no tax.

WHERE app/classes/Billing/InvoiceLineItem.php — fromForm(), plus the matching argument in app/controllers/InvoiceController.php.

WHY — and it was none of the three obvious places The rate WAS being copied onto each invoice correctly (InvoiceController stamps `tax_rate` and `tax_inclusive` from the company's settings on every save). App\Billing\Tax was computing correctly the whole time — tests/Billing/TaxTest.php has been proving it over 60 generated invoices. The settings screen saved correctly.

They were simply being handed a TAXABLE NET OF ZERO.

`fromForm()` decided a line's taxability with `array_key_exists($index, $taxable)` — “present means ticked”, which is how an unchecked HTML checkbox behaves. Its own comment read: “The form renders the boxes ticked by default, so the value here is the reader's actual choice.”

The form has never rendered that control. So `$taxable` was always the empty array, the test was always false, and every line of every invoice was stored `taxable = 0` — against a schema whose default for that column is TRUE. Tax on a taxable net of nothing is nothing.

A comment describing behaviour that was never implemented, on the one line where the failure is silent and arithmetic.

FIX `fromForm()` takes `$taxableChoiceOffered`. When the form did not offer the choice — which is every client today — the line takes the column's own default and is TAXABLE. When it does, the ticks are honoured exactly.

⭐ “NO CONTROL” MUST NOT LOOK LIKE “ALL UNTICKED”. An absent checkbox and an unticked one post identically, so presence alone can never be trusted; the caller has to say whether the choice was on screen at all. That is the same trap SettingsController::SECTIONS exists for, and getting it wrong here is what made this invisible for as long as it existed.

Per-line taxability is deliberately NOT added to the form. It is an advanced control nobody asked for, it would fight the `name=“description[]“` array syntax the line editor uses (an unchecked box posts nothing, so the indices would shift), and simplicity on this form is a stated product goal. The column and the machinery remain, and the new argument is the hook to switch it on later without re-introducing the ambiguity.

VERIFIED against the running app, with the ticket's own figures

EXCLUSIVE 20% on 1 x 200.00
  stored rate=20.000 inclusive=0, net=200.00, taxable_net=200.00
  -> subtotal 200.00, tax 40.00, GROSS 240.00
  invoice page renders a VAT row and shows 240.00
INCLUSIVE 15% on 115.00
  -> net 100.00, tax 15.00, gross 115.00

Full suite 364 tests / 13,042 assertions green; lint clean; 88-request authenticated sweep in both languages, 0 problems.

Full History

Date User Field Change
2026-08-06T12:01:30+01:00 Nour aboulhosn issue-new New Issue
2026-08-06T14:56:36+01:00 Claude note-added Note Added: 0000138
2026-08-06T14:56:42+01:00 Claude tag-added Tag Attached: done-by-claude
2026-08-06T14:56:42+01:00 Claude Assigned To ⇒ Claudine
2026-08-06T14:56:42+01:00 Claude Status new ⇒ resolved
2026-08-06T14:56:42+01:00 Claude Resolution open ⇒ fixed

Synced automatically from MantisBT issue #176.