Skip to content

Show wallet balance at end of selected time period #387

Description

@emavgl

Description

A user requested the ability to see a wallet's balance at the end of any selected month (e.g., balance on May 31st), not just the all-time/today balance. This is needed to compare Oinkoin data with monthly bank statements.

Current behavior:

  • The "Accounts" row on the homescreen shows the all-time balance of selected wallets (SQL: SUM(r.value) across ALL records + initial_amount + transfers).
  • This balance does not change when the user navigates to a past month — it always reflects today's total.
  • The Income/Expenses row below IS correctly scoped to the selected time period, but the Accounts row is not.

Requested behavior:

  • When viewing a past month (e.g., May 2026), the Accounts row should show the balance at the end of that month (May 31st), not the current balance.
  • The user wants this per-wallet (not just combined), so they can cross-check individual accounts against bank statements.

Proposed Solution

  1. Scope the Accounts row balance to the selected time period: Instead of showing the all-time wallet balance, calculate the balance as of the end of the selected time interval (e.g., endOfMonth for monthly view, endOfYear for yearly, etc.).
  2. Tapping the Accounts row opens a per-wallet breakdown: Currently tapping the row opens the WalletPickerPage (multi-select filter). Change this to show a per-wallet split at the selected time period, so the user can see each wallet's individual end-of-period balance.
  3. Current month behavior: Keep showing the current balance when the current month is selected (end-of-current-month balance, which matches today).

Technical Context

  • Wallet balance is computed in lib/services/database/sqlite-database.dart:648-662 via _walletBalanceQuery(), which has no date filter.
  • A new SQL query or in-memory filtering is needed to add WHERE r.datetime <= :endDate to both the main JOIN and the transfer subquery.
  • The balance is exposed via _controller.selectedWalletsBalance / selectedWalletsBalanceString in lib/records/controllers/tab_records_controller.dart:774-784.
  • The Accounts row UI is in lib/records/components/days-summary-box-card.dart:104-130.

Files Likely Affected

  • lib/services/database/sqlite-database.dart — Add a point-in-time balance query
  • lib/records/controllers/tab_records_controller.dart — Use period-scoped balance instead of all-time
  • lib/records/components/days-summary-box-card.dart — UI adjustments (optional)
  • lib/wallets/wallet-picker-page.dart or new page — Per-wallet breakdown view

Notes

  • The balance must account for: outgoing records (r.value where r.wallet_id = w.id), incoming transfers (ABS(t.value) where t.transfer_wallet_id = w.id), and w.initial_amount.
  • Future/planned records (from recurring patterns) should be excluded when calculating past end-of-period balances.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions