User Tools

Site Tools


wiki:project-x:bugs:180

#180 — The "you cannot pay out more than the account holds" rule is enforced on transfers but not on expenses, so an expense drives a (Resolved)

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


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

Description: There are two ways to take money out of a cash account, and they disagree about whether it may go negative.

Cash → “Move money between accounts” enforces the rule properly: moving `$60.00` out of an account holding `$47.49` is refused with “That's more than the $47.49 in that account.”

Expenses do not enforce it at all. An expense of `$32.49` against a Cash account holding `$22.49` is accepted with “Expense saved.”, leaving the balance at -$10.00. The same route drove the Bank account to -$202.45. For a *Cash* account this is not a nicety — it represents physical money in a drawer and cannot hold minus ten dollars; a negative balance means a payment was recorded against the wrong account or a receipt was never entered, exactly the mistake the transfer screen already catches.

The inconsistency then produces a self-contradictory message: once an account is negative, a transfer out of it is refused with *“That's more than the -$10.00 in that account.”* — a correct guard quoting a balance its sibling feature should never have allowed.

The fix is one consistent rule for every outflow: run the same balance check on expenses that transfers already perform, when a `cash_account_id` is chosen (the field is optional, so the check must only apply when an account is selected). If overdrafts are genuinely wanted for Bank or Card terminal accounts, drive the rule from the account's `kind` — block it for `cash` and `wallet`, allow or warn for `bank` and `card` — rather than leaving it unenforced everywhere.

Steps to Reproduce: 1. Cash & accounts: note the Cash account balance (e.g. `$22.49`). 2. Confirm the rule exists — in “Move money between accounts”, try to move more than the balance (e.g. `$60.00` from an account holding `$47.49`). Refused: “That's more than the $47.49 in that account.” 3. Expenses → Add an expense: enter an amount larger than the Cash balance (e.g. `32.49` against `22.49`), pick any category and bill, set cash account = Cash. Save. 4. Accepted with “Expense saved.” 5. Return to Cash & accounts — the Cash account now reads -$10.00. 6. Try to move money out of it — refused with “That's more than the -$10.00 in that account.”

Resolution: Fixed.

WHAT “Move money between accounts” refused an outflow larger than the balance; expenses did not, so an expense drove a Cash account to -$10.00. Once negative, a transfer out was refused with “That's more than the -$10.00 in that account” — a correct guard quoting a balance its sibling feature should never have allowed.

WHERE app/controllers/ExpenseController.php — validated(), a new check next to the bill ceiling.

WHY The rule existed in exactly one of the two places money can leave an account. Nothing shared it, so nothing kept them in step.

FIX The same balance check now runs on an expense whenever a cash account is actually named (the field is optional, and an expense with no account is invisible to the cash screen by design). It reuses CashPosition::balanceOf() and the same `cash.transfer_too_big` message, so the two paths cannot drift apart again.

ONE DELIBERATE DEPARTURE FROM THE TICKET It suggests driving the rule from the account kind — block `cash` and `wallet`, allow an overdraft on `bank` and `card`. That is defensible in the world, but it would make expenses and transfers disagree again one kind later, which is the whole complaint here. One rule for both paths is what was asked for. If overdrafts are genuinely wanted later they belong on CashAccount as a property BOTH paths read, changed once.

An edit adds this expense's own current amount back before judging, or re-saving the row that emptied an account would be refused against a balance it is itself the reason for.

VERIFIED (real HTTP)

account funded to 100.00
spend 40.00 (under) -> accepted, balance 100.00 -> 60.00, "Expense saved."
spend 90.00 (over)  -> refused,  balance unchanged at 60.00
final balance 60.00 — never negative

Full suite 364 tests green; lint clean; 88-request sweep, 0 problems.

Activity / Notes

  • 2026-08-06T14:29:15+01:00 - Claude: Fixed.

WHAT “Move money between accounts” refused an outflow larger than the balance; expenses did not, so an expense drove a Cash account to -$10.00. Once negative, a transfer out was refused with “That's more than the -$10.00 in that account” — a correct guard quoting a balance its sibling feature should never have allowed.

WHERE app/controllers/ExpenseController.php — validated(), a new check next to the bill ceiling.

WHY The rule existed in exactly one of the two places money can leave an account. Nothing shared it, so nothing kept them in step.

FIX The same balance check now runs on an expense whenever a cash account is actually named (the field is optional, and an expense with no account is invisible to the cash screen by design). It reuses CashPosition::balanceOf() and the same `cash.transfer_too_big` message, so the two paths cannot drift apart again.

ONE DELIBERATE DEPARTURE FROM THE TICKET It suggests driving the rule from the account kind — block `cash` and `wallet`, allow an overdraft on `bank` and `card`. That is defensible in the world, but it would make expenses and transfers disagree again one kind later, which is the whole complaint here. One rule for both paths is what was asked for. If overdrafts are genuinely wanted later they belong on CashAccount as a property BOTH paths read, changed once.

An edit adds this expense's own current amount back before judging, or re-saving the row that emptied an account would be refused against a balance it is itself the reason for.

VERIFIED (real HTTP)

account funded to 100.00
spend 40.00 (under) -> accepted, balance 100.00 -> 60.00, "Expense saved."
spend 90.00 (over)  -> refused,  balance unchanged at 60.00
final balance 60.00 — never negative

Full suite 364 tests green; lint clean; 88-request sweep, 0 problems.

Full History

Date User Field Change
2026-08-06T12:05:34+01:00 Nour aboulhosn issue-new New Issue
2026-08-06T14:29:15+01:00 Claude note-added Note Added: 0000135
2026-08-06T14:29:17+01:00 Claude tag-added Tag Attached: done-by-claude
2026-08-06T14:29:17+01:00 Claude Assigned To ⇒ Claudine
2026-08-06T14:29:17+01:00 Claude Status new ⇒ resolved
2026-08-06T14:29:17+01:00 Claude Resolution open ⇒ fixed

Synced automatically from MantisBT issue #180.

wiki/project-x/bugs/180.txt · Last modified: by mantisbot