← Back to bug list · View issue #181 in MantisBT
Reported by: Nour aboulhosn on 2026-08-06T12:06:22+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-06T14:29:21+01:00
Severity: major
Priority: high
Reproducibility: have not tried
Category: General
Description: Project X makes the expense-to-bill link mandatory — the form requires a bill, and the link is validated properly (a sales invoice, a non-existent id, a voided bill or another owner's invoice are all refused). Having enforced that every expense must belong to a bill, the app then places no limit on what may be filed against one and gives no way to see what has been.
Against a single purchase invoice #P-9001 for $60.00, four expenses of `$59.01`, `$58.02`, `$57.03` and `$56.04` — $230.10, nearly four times the bill — were each accepted with “Expense saved.” and no warning. The dashboard's Total expenses rose by the full amount.
The bill shows no trace of it. Its page still reads *“Payments — Nothing recorded against this invoice yet.”* So the bill shows nothing settled and nothing outstanding, while the expenses exist only in the expenses list, each pointing at a bill that does not acknowledge them. The mandatory link — the control that ought to prevent paying a bill twice — currently prevents nothing and reveals nothing.
The practical risk is double payment: a user paying a supplier in instalments, or two people recording the same bill on different days, will file several expenses against one invoice and the overpayment stays invisible until someone reconciles by hand. The fix is to use the link — list the expenses filed against a bill with a total applied and a remaining balance, warn (or refuse) when the total would exceed the bill's face value, and reflect a fully covered bill as settled.
Steps to Reproduce: 1. Create a purchase invoice (Invoices → New invoice → “Record a bill you received”) for a supplier, one line, unit price `60.00`. 2. Expenses → Add an expense: amount `59.01`, any category, select the `$60.00` bill under “Which bill?”. Save — “Expense saved.” 3. Repeat three times against the same bill with `58.02`, `57.03` and `56.04` (different amounts avoid the same-day duplicate warning). All accepted, no warning. 4. The dashboard's Total expenses has risen by $230.10 — against a $60.00 bill. 5. Open the bill: it still reads “Payments — Nothing recorded against this invoice yet.” None of the four expenses is shown.
Resolution: Fixed, both halves.
WHAT No limit on what could be filed against a bill, and no way to see what had been: $230.10 across four expenses against a $60.00 bill, all accepted with no warning, while the bill's own page still read “Payments — Nothing recorded against this invoice yet.” Reported independently by the product owner in the same breath: “i can pay 120$ to a 10$ invoice.”
WHERE
app/controllers/ExpenseController.php — validated(), the new bill ceiling app/classes/Expenses/Expense.php — totalForInvoice($id, $exceptId), listForInvoice($id) app/controllers/InvoiceController.php — show() passes billExpenses app/views/invoices/show.php — the list, the applied total and the remaining
WHY The link was enforced and then never used. Nothing summed what had been applied, and the bill page only knew about `invoice_payments` rows — which a purchase bill with expenses against it can never have, because the expense IS the cash event and counting both would double the money.
FIX 1. CEILING. An expense against a bill is refused when it would take the total past what is left on that bill. The ceiling is Payment::remainingOn() (the one place that knows how a gross is built — lines, the frozen tax rate, inclusive vs exclusive, less credits) minus the expenses already filed. A refusal, not a warning: this is arithmetic, and the reader can always resolve it by correcting the amount or by filing it against no bill, which is one tap away since the link became optional. An edit excludes its own row from the sum, or re-saving a $60 expense on a $60 bill would be told $60 exceeds $0.
2. VISIBILITY. The bill now lists the expenses filed against it, with “Applied” and “Still to pay”. Amounts and dates only, never who spent it — expenses.view_all is the product's privacy guarantee and this screen is gated on invoices.view, which is a different question; but the total has to be complete, because a bill half paid by a colleague is still half paid.
3. While here: the payment form is now hidden on a bill settled by expenses. The comment above that condition has always listed this as one of three cases it hides for, and only two were implemented — so such a bill drew a full “Record a payment” form that the controller then refused at the door.
NOTE ON THE TICKET'S FIRST LINE It states the expense-to-bill link is mandatory. It no longer is — that was reversed the day before this, because requiring a bill broke the commonest case in the product (buying supplies from a different shop each time). The rest of the ticket stands unchanged and is what was fixed.
VERIFIED (real HTTP, the ticket's own figures)
$60.00 bill: 59.01 accepted -> 58.02, 57.03, 56.04 all REFUSED
applied 59.01 of 60.00, bill status 'part_paid'
bill page: lists "Expenses against this bill", Applied $45.00 / Still to pay $15.00,
"Nothing recorded" gone
Full suite 364 tests green; lint clean; 88-request sweep, 0 problems.
WHAT No limit on what could be filed against a bill, and no way to see what had been: $230.10 across four expenses against a $60.00 bill, all accepted with no warning, while the bill's own page still read “Payments — Nothing recorded against this invoice yet.” Reported independently by the product owner in the same breath: “i can pay 120$ to a 10$ invoice.”
WHERE
app/controllers/ExpenseController.php — validated(), the new bill ceiling app/classes/Expenses/Expense.php — totalForInvoice($id, $exceptId), listForInvoice($id) app/controllers/InvoiceController.php — show() passes billExpenses app/views/invoices/show.php — the list, the applied total and the remaining
WHY The link was enforced and then never used. Nothing summed what had been applied, and the bill page only knew about `invoice_payments` rows — which a purchase bill with expenses against it can never have, because the expense IS the cash event and counting both would double the money.
FIX 1. CEILING. An expense against a bill is refused when it would take the total past what is left on that bill. The ceiling is Payment::remainingOn() (the one place that knows how a gross is built — lines, the frozen tax rate, inclusive vs exclusive, less credits) minus the expenses already filed. A refusal, not a warning: this is arithmetic, and the reader can always resolve it by correcting the amount or by filing it against no bill, which is one tap away since the link became optional. An edit excludes its own row from the sum, or re-saving a $60 expense on a $60 bill would be told $60 exceeds $0.
2. VISIBILITY. The bill now lists the expenses filed against it, with “Applied” and “Still to pay”. Amounts and dates only, never who spent it — expenses.view_all is the product's privacy guarantee and this screen is gated on invoices.view, which is a different question; but the total has to be complete, because a bill half paid by a colleague is still half paid.
3. While here: the payment form is now hidden on a bill settled by expenses. The comment above that condition has always listed this as one of three cases it hides for, and only two were implemented — so such a bill drew a full “Record a payment” form that the controller then refused at the door.
NOTE ON THE TICKET'S FIRST LINE It states the expense-to-bill link is mandatory. It no longer is — that was reversed the day before this, because requiring a bill broke the commonest case in the product (buying supplies from a different shop each time). The rest of the ticket stands unchanged and is what was fixed.
VERIFIED (real HTTP, the ticket's own figures)
$60.00 bill: 59.01 accepted -> 58.02, 57.03, 56.04 all REFUSED
applied 59.01 of 60.00, bill status 'part_paid'
bill page: lists "Expenses against this bill", Applied $45.00 / Still to pay $15.00,
"Nothing recorded" gone
Full suite 364 tests green; lint clean; 88-request sweep, 0 problems.
| Date | User | Field | Change |
|---|---|---|---|
| 2026-08-06T12:06:22+01:00 | Nour aboulhosn | issue-new | New Issue |
| 2026-08-06T14:29:19+01:00 | Claude | note-added | Note Added: 0000136 |
| 2026-08-06T14:29:21+01:00 | Claude | tag-added | Tag Attached: done-by-claude |
| 2026-08-06T14:29:21+01:00 | Claude | Assigned To | ⇒ Claudine |
| 2026-08-06T14:29:21+01:00 | Claude | Status | new ⇒ resolved |
| 2026-08-06T14:29:21+01:00 | Claude | Resolution | open ⇒ fixed |
Synced automatically from MantisBT issue #181.