whisper-money/app
Víctor Falcón 7e958284e3
fix(loans): project monthly balances from actual entries instead of original params (#259)
## Summary

- **Bug**: The `loans:generate-balances` command called
`getBalanceAtDate()` which always recalculated the remaining balance
from the **original loan parameters** (`original_amount`,
`annual_interest_rate`, `loan_term_months`, `start_date`), completely
ignoring existing actual balance entries. When the real balance was
lower than the theoretical amortization schedule (e.g. user made extra
payments), the auto-generated balance would **jump up** instead of
continuing to decrease.
- **Example**: Account `019d0b33-d3c5-7110-9033-51155ac93219` had a real
balance of ~4,489,670 (March 2026), but the command generated 5,700,356
(April 2026) — a jump **up** of ~1.2M cents instead of the expected ~16K
decrease.
- **Fix**: `getBalanceAtDate()` now checks for the latest
`AccountBalance` entry on or before the target date and projects forward
from it, falling back to the theoretical formula only when no entries
exist. This matches the method's own documented behavior and aligns with
how `generateProjection()` already works.

## Testing

Added 4 new tests:
- Projects from existing balance entries instead of original loan params
- Returns existing balance when target date is in the same month
- Generates correct monthly balance when existing entries differ from
theoretical
- All 44 existing loan tests continue to pass
2026-04-04 15:57:29 +01:00
..
Actions chore: upgrade Laravel 12 to 13 (#242) 2026-03-25 12:56:33 +00:00
Console/Commands chore: Remove account-mapping feature flag (#252) 2026-04-01 12:09:22 +02:00
Contracts feat(banking): add banking:backfill-ibans command to populate missing IBANs (#221) 2026-03-12 10:58:55 +00:00
Enums fix(banking): retry failed sync connections and log every sync attempt (#251) 2026-03-31 11:34:35 +01:00
Events Add Budgeting Feature to Track and Manage Spending (#36) 2026-01-21 15:25:50 +01:00
Http feat(settings): centralize currency options and split profile/account support (#256) 2026-04-02 19:23:10 +02:00
Jobs chore: Remove account-mapping feature flag (#252) 2026-04-01 12:09:22 +02:00
Listeners feat(emails): co-founder language, welcome rewrite, and Spanish translations (#208) 2026-03-05 15:22:07 +01:00
Mail chore: upgrade Laravel 12 to 13 (#242) 2026-03-25 12:56:33 +00:00
Models fix(banking): retry failed sync connections and log every sync attempt (#251) 2026-03-31 11:34:35 +01:00
Notifications feat: Spanish localization (#74) 2026-02-08 11:58:08 +01:00
Policies feat(accounts): add real estate asset tracking (#241) 2026-03-24 10:21:32 +00:00
Providers chore: Remove account-mapping feature flag (#252) 2026-04-01 12:09:22 +02:00
Services fix(loans): project monthly balances from actual entries instead of original params (#259) 2026-04-04 15:57:29 +01:00