Open-source personal finance manager. Self-hosted, privacy-first.
feat: add transaction sum calculation (#204)
Tássio Noronha4b4fdcb8e94b
diff --git a/backend/app/api/transactions.py b/backend/app/api/transactions.pyindex b6cb3e5b..2c76098a 100644--- a/backend/app/api/transactions.py+++ b/backend/app/api/transactions.py@@ -26,11 +26,23 @@ def _tag_fx_fallback(tx: TransactionRead, primary_currency: str) -> TransactionRreturn tx+class TransactionsSummary(BaseModel):+ """Income / expense / net totals across all rows matching the active+ filters (issue #185). Amounts are in the user's primary currency.+ Floats (not Decimal) so the JSON payload matches `amount_primary`+ and the frontend gets plain numbers."""+ income: float+ expense: float+ net: float+ currency: str++class PaginatedTransactions(BaseModel):items: list[TransactionRead]total: intpage: intlimit: int+ summary: Optional[TransactionsSummary] = Nonedef _merge_id_filters(@@ -71,7 +83,7 @@ async def list_transactions(user: User = Depends(current_active_user),):accounting_mode = await get_credit_card_accounting_mode(session)- transactions, total = await transaction_service.get_transactions(+ transactions, total, summary = await transaction_service.get_transactions(session, user.id,account_ids=_merge_id_filters(account_id, account_ids),category_ids=_merge_id_filters(category_id, category_ids),@@ -85,10 +97,16 @@ async def list_transactions(unbilled_only=unbilled_only,sort_by=sort_by,sort_dir=sort_dir,+ include_summary=True,)primary_currency = user.primary_currencyitems = [_tag_fx_fallback(TransactionRead.model_validate(tx, from_attributes=True), primary_currency) for tx in transactions]- return PaginatedTransactions(items=items, total=total, page=page, limit=limit)+ summary_out = (+ TransactionsSummary(**summary, currency=primary_currency)+ if summary is not None+ else None+ )+ return PaginatedTransactions(items=items, total=total, page=page, limit=limit, summary=summary_out)@router.get("/export")@@ -112,14 +130,14 @@ async def export_transactions(if transaction_ids:# Selection-only export: bypass user-facing filters but keep the# service-level user/visibility scoping intact.- transactions, _ = await transaction_service.get_transactions(+ transactions, _, _ = await transaction_service.get_transactions(session, user.id,skip_pagination=True,accounting_mode=accounting_mode,transaction_ids=transaction_ids,)else:- transactions, _ = await transaction_service.get_transactions(+ transactions, _, _ = await transaction_service.get_transactions(session, user.id,account_ids=_merge_id_filters(account_id, account_ids),category_ids=_merge_id_filters(category_id, category_ids),diff --git a/backend/app/services/transaction_service.py b/backend/app/services/transaction_service.pyindex 4269f24a..6fcd2331 100644--- a/backend/app/services/transaction_service.py+++ b/backend/app/services/transaction_service.py@@ -1,6 +1,7 @@import reimport uuidfrom datetime import date+from decimal import Decimalfrom typing import Optionalfrom sqlalchemy import select, func, or_, update@@ -78,7 +79,8 @@ async def get_transactions(min_amount: Optional[float] = None,max_amount: Optional[float] = None,account_types: Optional[list[str]] = None,-) -> tuple[list[Transaction], int]:+ include_summary: bool = False,+) -> tuple[list[Transaction], int, Optional[dict]]:# In "accrual" mode, bucket/order by effective_date so list filters# line up with the cash-flow view used by the dashboard and reports.# When the user has set a manual cycle override (effective_bill_date)@@ -333,6 +335,37 @@ async def get_transactions(count_query = select(func.count()).select_from(base_query.subquery())total = await session.scalar(count_query)+ # Filtered summary (issue #185): income / expense / net across ALL+ # rows matching the active filters — not just the current page — so+ # the UI can show an accurate total even when results span pages.+ # Cross-currency rows are normalized to their primary-currency amount+ # when stamped (coalesce → native amount as fallback for unstamped+ # rows). Computed before pagination so it covers the whole result set.+ summary: Optional[dict] = None+ if include_summary:+ summary_subq = base_query.subquery()+ amount_norm = func.coalesce(+ summary_subq.c.amount_primary, summary_subq.c.amount+ )+ summary_rows = await session.execute(+ select(+ summary_subq.c.type,+ func.coalesce(func.sum(func.abs(amount_norm)), 0),+ ).group_by(summary_subq.c.type)+ )+ income = Decimal("0")+ expense = Decimal("0")+ for row_type, row_total in summary_rows:+ if row_type == "credit":+ income = Decimal(str(row_total or 0))+ elif row_type == "debit":+ expense = Decimal(str(row_total or 0))+ summary = {+ "income": income,+ "expense": expense,+ "net": income - expense,+ }+# Apply ordering (and pagination unless skipped). Bill-view callers# order by purchase date so the in-cycle list matches the bank's own# statement ordering regardless of accounting mode.@@ -396,7 +429,7 @@ async def get_transactions(# and the frontend needs `is_shared` to lock them from edits.await _tag_shared_view(session, transactions, user_id)- return transactions, total or 0+ return transactions, total or 0, summaryasync def _tag_shared_view(diff --git a/backend/mcp_server/tools/transactions.py b/backend/mcp_server/tools/transactions.pyindex 04199986..8632b60d 100644--- a/backend/mcp_server/tools/transactions.py+++ b/backend/mcp_server/tools/transactions.py@@ -120,7 +120,7 @@ async def list_transactions(# Hard cap regardless of what the LLM asks — the schema says 50 but# not every provider enforces additionalProperties / maximum.limit = max(1, min(int(limit), 50))- txs, total = await transaction_service.get_transactions(+ txs, total, _ = await transaction_service.get_transactions(session,ctx.user_id,account_ids=parse_uuid_list(account_ids),diff --git a/backend/tests/test_credit_card_accounting_mode.py b/backend/tests/test_credit_card_accounting_mode.pyindex d1260fc0..677628c8 100644--- a/backend/tests/test_credit_card_accounting_mode.py+++ b/backend/tests/test_credit_card_accounting_mode.py@@ -736,7 +736,7 @@ class TestEffectiveBillDateFiltersList:await session.commit()# March window: should include the override'd tx.- march_txs, _ = await get_transactions(+ march_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 2, 16), to_date=date(2026, 3, 15),accounting_mode="cash",@@ -744,7 +744,7 @@ class TestEffectiveBillDateFiltersList:assert any(t.id == tx.id for t in march_txs)# May window: should NOT include it anymore.- may_txs, _ = await get_transactions(+ may_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 16), to_date=date(2026, 5, 15),accounting_mode="cash",@@ -767,7 +767,7 @@ class TestEffectiveBillDateFiltersList:tx.effective_bill_date = date(2026, 3, 1)await session.commit()- march_txs, _ = await get_transactions(+ march_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 2, 16), to_date=date(2026, 3, 15),accounting_mode="accrual",@@ -815,7 +815,7 @@ class TestEffectiveBillDateFiltersList:await session.commit()# Cycle window for this bill = [Mar 17, Apr 16]- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=bill.id,from_date=date(2026, 3, 17), to_date=date(2026, 4, 16),@@ -861,7 +861,7 @@ class TestEffectiveBillDateFiltersList:pending.status = "pending"await session.commit()- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=may_bill.id,from_date=date(2026, 4, 11), to_date=date(2026, 5, 10),@@ -893,7 +893,7 @@ class TestEffectiveBillDateFiltersList:# In-progress June cycle (cycle-math fallback, no bill_id passed)# range = [April 30, May 29] — the start INCLUDES the prev close day.- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 30), to_date=date(2026, 5, 29),accounting_mode="cash",@@ -935,7 +935,7 @@ class TestEffectiveBillDateFiltersList:# In-progress cycle window happens to include May 5. With the# `unbilled_only` flag set (which account-detail uses for the# in-progress cycle), the prior-bill tx must NOT appear.- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 30), to_date=date(2026, 5, 29),accounting_mode="cash",@@ -945,7 +945,7 @@ class TestEffectiveBillDateFiltersList:# Without unbilled_only (e.g., the global /transactions list page),# the same tx IS visible — the flag is opt-in.- txs_unfiltered, _ = await get_transactions(+ txs_unfiltered, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 30), to_date=date(2026, 5, 29),accounting_mode="cash",@@ -977,7 +977,7 @@ class TestEffectiveBillDateFiltersList:await session.commit()for mode in ("cash", "accrual"):- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 30), to_date=date(2026, 5, 29),accounting_mode=mode,@@ -1008,7 +1008,7 @@ class TestEffectiveBillDateFiltersList:await session.commit()# Cash mode: filtered by purchase date → in April window- txs_cash_apr, _ = await get_transactions(+ txs_cash_apr, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 1), to_date=date(2026, 4, 30),accounting_mode="cash",@@ -1018,14 +1018,14 @@ class TestEffectiveBillDateFiltersList:# Accrual mode: filtered by effective_date → NOT in April window,# but IS in June window. This is the existing mode-aware semantic# callers outside the bill view rely on.- txs_accrual_apr, _ = await get_transactions(+ txs_accrual_apr, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 1), to_date=date(2026, 4, 30),accounting_mode="accrual",)assert tx.id not in {t.id for t in txs_accrual_apr}- txs_accrual_jun, _ = await get_transactions(+ txs_accrual_jun, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 6, 1), to_date=date(2026, 6, 30),accounting_mode="accrual",@@ -1064,7 +1064,7 @@ class TestEffectiveBillDateFiltersList:await session.commit()# Viewing April bill — must NOT include this pending tx- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=april_bill.id,from_date=date(2026, 3, 11), to_date=date(2026, 4, 10),@@ -1125,7 +1125,7 @@ class TestEffectiveBillDateFiltersList:)await session.commit()- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=april.id,from_date=date(2026, 3, 17), to_date=date(2026, 4, 16),@@ -1167,7 +1167,7 @@ class TestEffectiveBillDateFiltersList:)await session.commit()- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=bill.id,from_date=date(2026, 3, 17), to_date=date(2026, 4, 16),@@ -1208,7 +1208,7 @@ class TestEffectiveBillDateFiltersList:tx.status = "pending"await session.commit()- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=bill.id,from_date=date(2026, 3, 17), to_date=date(2026, 4, 16),@@ -1248,7 +1248,7 @@ class TestEffectiveBillDateFiltersList:# bill_id stays Noneawait session.commit()- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=bill.id,from_date=date(2026, 3, 17), to_date=date(2026, 4, 16),@@ -1285,7 +1285,7 @@ class TestEffectiveBillDateFiltersList:)await session.commit()- txs, _ = await get_transactions(+ txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=bill.id,from_date=date(2026, 3, 17), to_date=date(2026, 4, 16),@@ -1476,7 +1476,7 @@ class TestEffectiveBillDateFiltersList:await session.commit()# December window: tx must NOT appear (override moved it to Jan)- dec_txs, _ = await get_transactions(+ dec_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2025, 12, 1), to_date=date(2025, 12, 31),accounting_mode="cash",@@ -1484,7 +1484,7 @@ class TestEffectiveBillDateFiltersList:assert tx.id not in {t.id for t in dec_txs}# January window: tx must appear- jan_txs, _ = await get_transactions(+ jan_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 1, 1), to_date=date(2026, 1, 31),accounting_mode="cash",@@ -1555,7 +1555,7 @@ class TestEffectiveBillDateFiltersList:await session.commit()# April window: cash mode uses date (Apr 18), should include- apr_txs, _ = await get_transactions(+ apr_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 1), to_date=date(2026, 4, 30),accounting_mode="cash",@@ -1600,7 +1600,7 @@ class TestEffectiveBillDateFiltersList:tx.effective_bill_date = date(2026, 5, 10)await session.commit()- may_txs, _ = await get_transactions(+ may_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,bill_id=may.id,from_date=date(2026, 4, 17), to_date=date(2026, 5, 16),@@ -1677,7 +1677,7 @@ class TestEffectiveBillDateFiltersList:# In-progress cycle window for close=11/due=16 around early May:# cycle = [Apr 12, May 11]. Override 6/11 lies past 5/11.- in_prog_txs, _ = await get_transactions(+ in_prog_txs, _, _ = await get_transactions(session, test_user.id, account_id=cc_account.id,from_date=date(2026, 4, 12), to_date=date(2026, 5, 11),unbilled_only=True,diff --git a/backend/tests/test_transaction_service.py b/backend/tests/test_transaction_service.pyindex adf0ea01..cec1d66d 100644--- a/backend/tests/test_transaction_service.py+++ b/backend/tests/test_transaction_service.py@@ -162,11 +162,11 @@ async def test_get_transactions_pagination(session: AsyncSession, test_user, txnsession.add(txn)await session.commit()- page1, total = await get_transactions(session, test_user.id, limit=2, page=1)+ page1, total, _ = await get_transactions(session, test_user.id, limit=2, page=1)assert total >= 5assert len(page1) == 2- page2, _ = await get_transactions(session, test_user.id, limit=2, page=2)+ page2, _, _ = await get_transactions(session, test_user.id, limit=2, page=2)assert len(page2) == 2# No overlap@@ -213,7 +213,7 @@ async def test_get_transactions_filter_by_account(session: AsyncSession, test_ussession.add_all([txn1, txn2])await session.commit()- results, _ = await get_transactions(session, test_user.id, account_id=txn_account.id)+ results, _, _ = await get_transactions(session, test_user.id, account_id=txn_account.id)descs = {t.description for t in results}assert "In main" in descsassert "In other" not in descs@@ -250,7 +250,7 @@ async def test_get_transactions_filter_by_category(session.add_all([txn1, txn2])await session.commit()- results, _ = await get_transactions(session, test_user.id, category_id=test_categories[0].id)+ results, _, _ = await get_transactions(session, test_user.id, category_id=test_categories[0].id)descs = {t.description for t in results}assert "Cat A" in descsassert "Cat B" not in descs@@ -283,7 +283,7 @@ async def test_get_transactions_filter_by_date_range(session: AsyncSession, testsession.add_all([txn_jan, txn_mar])await session.commit()- results, _ = await get_transactions(+ results, _, _ = await get_transactions(session,test_user.id,from_date=date(2025, 3, 1),@@ -331,19 +331,19 @@ async def test_get_transactions_date_filter_respects_accounting_mode(march_window = dict(from_date=date(2025, 3, 1), to_date=date(2025, 3, 31))# Cash mode (default): the CC purchase lives in March, regular in April.- cash_april, _ = await get_transactions(session, test_user.id, **april_window)+ cash_april, _, _ = await get_transactions(session, test_user.id, **april_window)assert {t.description for t in cash_april} == {"Regular"}- cash_march, _ = await get_transactions(session, test_user.id, **march_window)+ cash_march, _, _ = await get_transactions(session, test_user.id, **march_window)assert {t.description for t in cash_march} == {"CC purchase"}# Accrual mode: both buckets shift to the bill-due month.- accrual_april, _ = await get_transactions(+ accrual_april, _, _ = await get_transactions(session, test_user.id, accounting_mode="accrual", **april_window)assert {t.description for t in accrual_april} == {"CC purchase", "Regular"}- accrual_march, _ = await get_transactions(+ accrual_march, _, _ = await get_transactions(session, test_user.id, accounting_mode="accrual", **march_window)assert {t.description for t in accrual_march} == set()@@ -365,7 +365,7 @@ async def test_get_transactions_filter_by_search(session: AsyncSession, test_usesession.add(txn)await session.commit()- results, _ = await get_transactions(session, test_user.id, search="netflix")+ results, _, _ = await get_transactions(session, test_user.id, search="netflix")descs = {t.description for t in results}assert "NETFLIX SUBSCRIPTION" in descs@@ -397,7 +397,7 @@ async def test_get_transactions_filter_by_type(session: AsyncSession, test_user,session.add_all([txn_debit, txn_credit])await session.commit()- results, _ = await get_transactions(session, test_user.id, txn_type="credit")+ results, _, _ = await get_transactions(session, test_user.id, txn_type="credit")types = {t.type for t in results}assert "credit" in typesassert all(t.type == "credit" for t in results)@@ -730,7 +730,7 @@ async def test_get_transactions_uncategorized(session: AsyncSession, test_user,amount=Decimal("50"), date=date.today(), type="debit",category_id=test_categories[0].id,))- txns, _ = await get_transactions(session, test_user.id, uncategorized=True)+ txns, _, _ = await get_transactions(session, test_user.id, uncategorized=True)descs = [t.description for t in txns]assert "Uncategorized" in descsassert "Categorized" not in descs@@ -749,7 +749,7 @@ async def test_get_transactions_date_filter(session: AsyncSession, test_user, txaccount_id=txn_account.id, description="Yesterday",amount=Decimal("10"), date=yesterday, type="debit",))- txns, _ = await get_transactions(session, test_user.id, from_date=today, to_date=today)+ txns, _, _ = await get_transactions(session, test_user.id, from_date=today, to_date=today)descs = [t.description for t in txns]assert "Today" in descsassert "Yesterday" not in descs@@ -772,7 +772,7 @@ async def test_get_transactions_exclude_transfers(session: AsyncSession, test_usaccount_id=txn_account.id, description="Regular",amount=Decimal("50"), date=date.today(), type="debit",))- txns, _ = await get_transactions(session, test_user.id, exclude_transfers=True)+ txns, _, _ = await get_transactions(session, test_user.id, exclude_transfers=True)descs = [t.description for t in txns]assert "Regular" in descs@@ -784,7 +784,7 @@ async def test_get_transactions_skip_pagination(session: AsyncSession, test_useraccount_id=txn_account.id, description=f"Txn{i}",amount=Decimal("10"), date=date.today(), type="debit",))- txns, total = await get_transactions(session, test_user.id, skip_pagination=True, limit=2)+ txns, total, _ = await get_transactions(session, test_user.id, skip_pagination=True, limit=2)assert len(txns) == total@@ -977,7 +977,7 @@ async def test_get_transactions_filters_tags_with_exact_match(session.add_all(txns)await session.commit()- matches, total = await get_transactions(+ matches, total, _ = await get_transactions(session, test_user.id, tags=["#test"])descriptions = {tx.description for tx in matches}@@ -1008,7 +1008,7 @@ async def test_get_transactions_filters_multiple_tags_with_or(session.add_all(txns)await session.commit()- matches, _ = await get_transactions(+ matches, _, _ = await get_transactions(session, test_user.id, tags=["#test", "#hey"])assert {tx.description for tx in matches} == {"A", "B", "C"}diff --git a/backend/tests/test_transactions_api.py b/backend/tests/test_transactions_api.pyindex 8e13c683..ffd212aa 100644--- a/backend/tests/test_transactions_api.py+++ b/backend/tests/test_transactions_api.py@@ -631,3 +631,52 @@ async def test_create_transfer_invalid_account(client: AsyncClient, auth_headersheaders=auth_headers,)assert resp.status_code == 400+++async def test_list_transactions_summary(+ client: AsyncClient, auth_headers, test_transactions: list[Transaction]+):+ """The list response carries an income/expense/net summary across all+ matching rows (issue #185). Fixture: credits 8000 + 150, debits+ 25.50 + 45.00 + 39.90."""+ response = await client.get("/api/transactions", headers=auth_headers)+ assert response.status_code == 200+ summary = response.json()["summary"]+ assert summary is not None+ assert summary["income"] == pytest.approx(8150.0)+ assert summary["expense"] == pytest.approx(110.4)+ assert summary["net"] == pytest.approx(8039.6)+ assert summary["currency"]+++async def test_list_transactions_summary_spans_all_pages(+ client: AsyncClient, auth_headers, test_transactions: list[Transaction]+):+ """The summary covers every matching row, not just the current page —+ so a paginated request still totals the full result set."""+ response = await client.get(+ "/api/transactions?page=1&limit=2", headers=auth_headers+ )+ assert response.status_code == 200+ data = response.json()+ assert len(data["items"]) == 2 # page is capped+ assert data["summary"]["net"] == pytest.approx(8039.6) # total is not+++async def test_list_transactions_summary_respects_filters(+ client: AsyncClient, auth_headers, test_transactions: list[Transaction],+ test_categories: list[Category],+):+ """Filtering narrows the summary the same way it narrows the rows."""+ cat_id = test_categories[1].id # Transporte → UBER TRIP, 25.50 debit+ response = await client.get(+ f"/api/transactions?category_id={cat_id}", headers=auth_headers+ )+ assert response.status_code == 200+ summary = response.json()["summary"]+ assert summary["income"] == pytest.approx(0.0)+ assert summary["expense"] == pytest.approx(25.5)+ assert summary["net"] == pytest.approx(-25.5)diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex c78fc9d2..2d534c93 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -33,7 +33,7 @@ import type {SpendingByCategory,MonthlyTrend,BalanceHistory,- PaginatedResponse,+ PaginatedTransactions,ReportResponse,Group,GroupKind,@@ -275,7 +275,7 @@ export const transactions = {tags?: string[]sort_by?: stringsort_dir?: 'asc' | 'desc'- }): Promise<PaginatedResponse<Transaction>> => {+ }): Promise<PaginatedTransactions> => {const { data } = await api.get('/transactions', {params,paramsSerializer: { indexes: null },diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.jsonindex fb46fd37..a7d84574 100644--- a/frontend/src/locales/en.json+++ b/frontend/src/locales/en.json@@ -218,6 +218,10 @@"syncedInfo": "Bank-synced transaction — only category and notes can be edited","uncategorized": "Uncategorized","selected": "selected",+ "summaryCount": "{{count}} transactions",+ "summaryIncome": "Income",+ "summaryExpenses": "Expenses",+ "summaryNet": "Net","bulkCategorize": "Apply","bulkSuccess": "{{count}} transactions categorized","selectCategory": "Select category...",diff --git a/frontend/src/locales/pt-BR.json b/frontend/src/locales/pt-BR.jsonindex 80b9f647..f481298f 100644--- a/frontend/src/locales/pt-BR.json+++ b/frontend/src/locales/pt-BR.json@@ -218,6 +218,10 @@"syncedInfo": "Transação sincronizada — apenas categoria e notas podem ser editadas","uncategorized": "Sem categoria","selected": "selecionadas",+ "summaryCount": "{{count}} transações",+ "summaryIncome": "Receitas",+ "summaryExpenses": "Despesas",+ "summaryNet": "Saldo","bulkCategorize": "Aplicar","bulkSuccess": "{{count}} transações categorizadas","selectCategory": "Selecionar categoria...",diff --git a/frontend/src/pages/transactions.tsx b/frontend/src/pages/transactions.tsxindex aa7a32d2..e798e9e7 100644--- a/frontend/src/pages/transactions.tsx+++ b/frontend/src/pages/transactions.tsx@@ -512,6 +512,20 @@ export default function TransactionsPage() {const allSelected = selectableItems.length > 0 && selectableItems.every(tx => selectedIds.has(tx.id))const someSelected = selectableItems.some(tx => selectedIds.has(tx.id)) && !allSelected+ // Net total of the currently-selected rows (issue #185). Selection is+ // always page-scoped (cleared on page/filter change), so summing the+ // visible page covers every selected id. Cross-currency rows use their+ // primary-currency amount; credits add, debits subtract.+ const selectedNet = useMemo(() => {+ let net = 0+ for (const tx of data?.items ?? []) {+ if (!selectedIds.has(tx.id)) continue+ const base = Math.abs(Number(tx.amount_primary ?? tx.amount))+ net += tx.type === 'credit' ? base : -base+ }+ return net+ }, [data?.items, selectedIds])+// Resolve the currently-selected transactions into a valid debit/credit pair// for the "Link as transfer" action. Returns null if the pair is invalid// (wrong count, same account, same type, or already linked).@@ -1133,6 +1147,37 @@ export default function TransactionsPage() {</Table></div>)}+ {/* Filtered summary (issue #185): income / expenses / net across+ ALL rows matching the active filters — not just this page. */}+ {!isLoading && data?.summary && filteredItems.length > 0 && (+ <div className="flex flex-wrap items-center gap-x-5 gap-y-1 border-t border-border bg-muted/30 px-4 py-2.5">+ <span className="mr-auto text-xs text-muted-foreground">+ {t('transactions.summaryCount', { count: data.total })}+ </span>+ <span className="flex items-baseline gap-1.5 text-xs">+ <span className="text-muted-foreground">{t('transactions.summaryIncome')}</span>+ <span className="text-sm font-semibold tabular-nums text-emerald-600">+ {mask(formatCurrency(data.summary.income, data.summary.currency, locale))}+ </span>+ </span>+ <span className="flex items-baseline gap-1.5 text-xs">+ <span className="text-muted-foreground">{t('transactions.summaryExpenses')}</span>+ <span className="text-sm font-semibold tabular-nums text-rose-500">+ {mask(formatCurrency(data.summary.expense, data.summary.currency, locale))}+ </span>+ </span>+ <span className="flex items-baseline gap-1.5 text-xs">+ <span className="text-muted-foreground">{t('transactions.summaryNet')}</span>+ <span+ className={`text-sm font-bold tabular-nums ${+ data.summary.net >= 0 ? 'text-emerald-600' : 'text-rose-500'+ }`}+ >+ {mask(formatCurrency(data.summary.net, data.summary.currency, locale))}+ </span>+ </span>+ </div>+ )}</div>{/* Pagination */}@@ -1169,12 +1214,32 @@ export default function TransactionsPage() {><div className="mx-auto max-w-7xl px-3 md:px-6 pb-4 md:pb-6"><div className="flex items-stretch gap-1.5 bg-card border border-border shadow-xl rounded-2xl p-2">- {/* Selection count */}- <div className="flex items-center gap-2 pl-3 pr-4 text-sm font-medium text-foreground whitespace-nowrap">- <span className="inline-flex items-center justify-center size-6 rounded-full bg-primary/10 text-primary text-xs font-semibold">+ {/* Selection count + net total — stacked vertically so the+ sum (issue #185) adds no horizontal width to an already+ crowded bar. The sum is hidden below sm where only the+ count pill shows. */}+ <div className="flex items-center gap-2.5 pl-3 pr-4 whitespace-nowrap">+ <span className="inline-flex items-center justify-center size-6 rounded-full bg-primary/10 text-primary text-xs font-semibold shrink-0">{selectedIds.size}</span>- <span className="hidden sm:inline">{t('transactions.selected')}</span>+ <div className="hidden sm:flex flex-col leading-tight">+ <span className="text-[11px] font-medium text-muted-foreground">+ {t('transactions.selected')}+ </span>+ <span+ className={`text-sm font-bold tabular-nums ${+ selectedNet >= 0 ? 'text-emerald-600' : 'text-rose-500'+ }`}+ >+ {mask(+ `${selectedNet >= 0 ? '+' : '−'}${formatCurrency(+ Math.abs(selectedNet),+ userCurrency,+ locale,+ )}`,+ )}+ </span>+ </div></div><div className="w-px bg-border/60 self-stretch" />diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex db696d7c..7164ceb4 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -552,6 +552,19 @@ export interface PaginatedResponse<T> {limit: number}+// Income / expense / net totals for all transactions matching the active+// filters (issue #185) — accompanies the paginated /transactions response.+export interface TransactionsSummary {+ income: number+ expense: number+ net: number+ currency: string+}++export interface PaginatedTransactions extends PaginatedResponse<Transaction> {+ summary?: TransactionsSummary+}+// Reports (universal schema for all report types)export interface ReportBreakdown {key: string