fix: exclude deferred transactions from expected totals in Balance View and ledger calculations #233
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nidde/parenting-tool!233
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "copilot/debug-deferred-amount-calculation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Deferred transactions were being counted in both the "Expected" total and the separate "Deferred" breakdown on the Balance View page and ledger view — inflating Expected by the full deferred amount (e.g. 3 667 kr too high).
Description
DeferredTransactionDTOs haveexpected_amountset andactual_amount = null. Several frontend functions accumulated expected amounts without guarding against deferred state:The following components were affected and have been fixed:
CategorySummaryList.vue—expectedTotalaccumulation: drives the "Category Total: Expected" and "Grand Total: Expected" display on the Balance View pageMonthView.vuegroupByCategory— expected dataset used by the Balance View donut chartsCombinedMonthlyAccordion.vuecalculateSectionTotals— used bygetIncomeSectionTotals,getExpenseSectionTotals, andmonthlyTotals(affects section headers and month-level expected/net totals on the ledger view)CombinedMonthlyAccordion.vuecategoryTotals— used byCategoryTotalsRow(affects the per-category "Expected" display on the ledger view)All four now skip
is_deferredtransactions when accumulating expected, consistent with howBalanceService.phphas always handled this server-side.Type of Change
Testing
Code Quality
CI/CD Checks
Additional Notes
No backend changes required —
BalanceService.phpalready excluded deferred transactions from$expectedExpensesvia! $t->isDeferred(). This fix brings all affected frontend calculations in line with that existing behaviour.Comment
@coderabbitai helpto get the list of available commands and usage tips.@copilot
I thought it was the Balance View page that was incorrect and showing too high of an expected amount?
Pull request overview
Fixes ledger “Expected” totals being overstated by excluding deferred transactions from expected-amount rollups, aligning frontend calculations with existing backend behavior.
Changes:
is_deferredtransactions when accumulatingexpectedin section totals.is_deferredtransactions when accumulatingexpectedin per-category totals.Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
@ -10,6 +10,9 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and### Bug Fixes#### 💸 Deferred Expenses No Longer Inflate the Expected TotalSimilar to DEVLOG: this entry says 'Deferred Expenses' but the fix is implemented at the transaction aggregation layer and may affect any deferred transaction shown in the ledger view. Consider changing this to 'Deferred transactions…' (or explicitly stating it's expenses-only if that’s guaranteed by the data model for this view).
@ -8,6 +8,14 @@ Use `[1.CURRENT]` as the version heading for unreleased changes. This section mu## [1.CURRENT]### 🐛 Fix: Deferred Expenses Inflating Expected TotalsThe PR description/title refer to 'deferred transactions' (not only expenses), and the code change applies to shared section/category aggregation logic that may include both income and expenses. Consider renaming this heading (and related wording below) to 'Deferred transactions…' to match the actual scope and avoid confusion.
@ -431,3 +431,3 @@if (t.expected_amount !== null)if (!t.is_deferred && t.expected_amount !== null)expected += parseFloat(t.expected_amount) || 0;if (t.actual_amount !== null)This relies on
t.is_deferredbeing a real boolean (or numeric 0/1). If the API ever serializes it as a string (e.g.'0'/'1'),!t.is_deferredwill treat'0'as truthy and incorrectly exclude non-deferred transactions fromexpected. Consider normalizing the DTO field to a boolean when ingesting data (or using a stricter deferred check liket.is_deferred === true/=== 1) and then using that normalized value here.Same concern as the section totals: if
is_deferredcan be'0'/'1'(string) rather than boolean/number, this condition will misclassify transactions and undercountexpected. Normalizeis_deferredonce (preferred) or apply a strict deferred predicate here to avoid relying on JS truthiness.You're right — the same bug was present in two components that back the Balance View page:
CategorySummaryList.vue— theexpectedTotalaccumulation (drives the "Category Total: Expected" display and the Grand Total Expected row)MonthView.vuegroupByCategory— the expected data used by the donut chartsBoth now skip deferred transactions when accumulating expected (commit
1b659e2). The previous commit only fixed the ledger-side components (CombinedMonthlyAccordion.vue), not the Balance View ones.@copilot
The Balance View page, where individual months are broken down, still seem to have issues both in the category totals and grand total