Skip to content

Fix loan auto-match (SQLite float-binding bug) + searchable matching modal#56

Merged
tschaefermedia merged 1 commit into
mainfrom
fix/loan-payment-matching
Jul 3, 2026
Merged

Fix loan auto-match (SQLite float-binding bug) + searchable matching modal#56
tschaefermedia merged 1 commit into
mainfrom
fix/loan-payment-matching

Conversation

@tschaefermedia

Copy link
Copy Markdown
Owner

Root cause

Auto-match silently found nothing on every loan. The amount filter used whereBetween(DB::raw('ABS(amount)'), [$low, $high]) with float bounds. SQLite binds PHP floats as text, so ABS(amount) BETWEEN '285.0' AND '315.0' compares a numeric column against text — where numerics always sort before text — and matches nothing. Verified:

300.0 BETWEEN 285.0 AND 315.0  (float bindings) -> 0  (false!)
300.0 BETWEEN 285   AND 315    (int bindings)   -> 1

Fixed with CAST(? AS REAL). This is why your loan payments were all matched manually and auto-match reported 'Keine passenden Buchungen gefunden'.

Also fixed

  • Amount source: auto-match now uses the configured monthly_rate (the actual debit) for the band, not just the computed annuity — everywhere else already uses monthly_rate.
  • Payment-day window wraps months: a debit due on the 30th that posts on the 1st (weekend/holiday shift) now matches instead of being counted ~29 days off.
  • Searchable matching modal: the 'Buchung zuordnen' dialog gets a search box (description / counterparty / reference / amount) and the cap goes 50 → 100, so an older payment is reachable instead of stuck behind 5 pages.

Tests

LoanPaymentMatchingTest: monthly_rate matching, month-boundary wrap, text search, amount search. All pass; frontend builds.

Root cause: the amount band used whereBetween with float bounds. SQLite binds
PHP floats as text, so 'ABS(amount) BETWEEN 285.0 AND 315.0' compared a numeric
column against text bounds and never matched — auto-match silently found nothing
on every loan. Fixed with CAST(? AS REAL).

Also:
- Auto-match now uses the configured monthly_rate (the real debit) for the
  amount band instead of only the computed annuity payment.
- The payment-day proximity check now wraps month boundaries, so a debit that
  shifts into the next month (e.g. a 30th due date posting on the 1st) matches.
- The 'Buchung zuordnen' modal gains a search box (description/counterparty/
  reference/amount) and raises the cap from 50 to 100, so older payments are
  reachable instead of being stuck behind 5 pages.
@tschaefermedia
tschaefermedia merged commit cad50d3 into main Jul 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant