Add credit card statement cycle support

Merged
DA
1mo ago
+1064-67

Summary

Adds a read-only statement cycle concept to credit cards so the Overview tab shows what the last closed statement came to and what is building toward the next one, plus when the payment is due.

Changes

  • New statement_close_day / due_day integer columns on credit_cards (1..31, clamped to last day of month) plus a DB migration.
  • CreditCard#statement_cycle_configured?, last_statement_close_date, previous_statement_close_date, next_statement_close_date, payment_due_date_for, next_payment_due_date, days_until_due, last_statement_balance_money, accrued_since_last_close_money, minimum_payment_shortfall?.
  • Plaid CreditProcessor ingests last_statement_issue_date / next_payment_due_date into the close/due days, filling blank fields only so manual corrections survive a sync.
  • New Overview tab at credit_cards/tabs/_overview.html.erb wired into UI::AccountPage (credit cards now get activity + overview + statements). Captioned cards:
    • Statement Balance (with due date + day count)
    • Since Last Statement (closes date; reads as a credit when negative so the two sum back to the header balance)
    • APR
    • Above-minimum alert comparing the payment against the closed statement
  • Form inputs for the two days, permitted on CreditCardsController; locale strings added.
  • Due-date anchoring fixed so a card closing the 10th and due the 26th reports Oct 26 on Oct 16 rather than skipping to the next statement. Minimum payment no longer appears as a standalone card (only as the derived comparison), and the countdown reports exact days (including overdue) rather than weeks/months.
  • Tests added for the cycle math, Plaid ingestion, controller permits, and the overview tab.

Why only this scope (deliberately deferred)

The natural next step is auto-generating a monthly "payment to card" recurring transfer so it appears on the Bills page / iCal feed. That is deliberately deferred because RecurringTransaction has no per-(family, destination_account) uniqueness: create_from_transfer stamps no dedup_scope (the unique indexes include name/amount), so a variable-amount card payment yields orphaned duplicate series, and the Cleaner never deletes manual rows. Fixing that dedup gap is a prerequisite and a separate PR.

Verification

  • Full unit suite: 11932 runs; the 3 failures / 3 errors are identical to the clean-tree baseline (Settings::HostingsControllerTest, SimplefinEntry::ProcessorTest, Eval::Langfuse::ExperimentRunnerTest). No new failures.
  • System suite: 244 runs; the 2 failures (ComboboxDarkThemeTest) are pre-existing.
  • rubocop, erb_lint, Biome, and Brakeman all clean.
image image

Summary by CodeRabbit

  • New Features
    • Credit cards now have an Overview tab showing statement balances, activity since the last close, payment due dates and countdowns, and APR when statement-cycle details are available.
    • Set or edit statement close and payment due days in card details; available dates may also be filled in during account sync.
    • The overview flags minimum-payment shortfalls, labels credits toward the next statement, and explains when amounts can’t be calculated, including when currency conversion rates are unavailable.
    • Cards without statement-cycle details show a setup prompt.
  • Bug Fixes
    • Credit-card overview calculations use a consistent date across account pages.