fix: Balance View category/grand totals still counting deferred transactions #234
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!234
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "copilot/fix-balance-view-issues"
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?
The Balance View's category totals and grand total continued to inflate expected amounts with deferred transactions despite the previous frontend fix, because the frontend checks (
is_deferred,is_virtual) were alwaysundefined.Root Cause
BalanceService::getDetailedMonthlyBalancereturned DTO objects directly to Inertia. PHP'sjson_encodeonly serializes public properties — it never callstoArray(). The fieldsis_virtualandis_deferredare computed intoArray(), not public properties, so they were absent from the serialized JSON.On the frontend,
transaction.is_deferred === undefined, and!undefined === true, so every deferred transaction bypassed the exclusion guard added in the previous fix.Fix
Map both collections through
->toArray()before returning fromgetDetailedMonthlyBalance:The manually-pushed stdClass items (mortgages, credit payments, purchases) already had explicit
is_deferred/is_virtualproperties and are unaffected.Type of Change
Testing
Code Quality
CI/CD Checks
Additional Notes
The real fix lives entirely in
BalanceService.php. The frontend logic from the previous commit (CategorySummaryList.vue,MonthView.vue) was correct — it just never had valid data to act on.Comment
@coderabbitai helpto get the list of available commands and usage tips.Pull request overview
Fixes Balance View category/grand totals incorrectly including deferred transactions by ensuring computed DTO fields (
is_deferred,is_virtual) are serialized to the frontend.Changes:
DEVLOG.md.CHANGELOG.md.Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
toArray()so computed flags are present in serialized JSON@ -344,0 +343,4 @@// Convert DTOs to arrays so that computed fields like is_virtual and is_deferred// are included in the JSON serialized to the frontend (plain PHP objects only// expose public properties, not toArray() results, when json_encode'd).$incomeDetails = $transactionsThis comment is slightly over-broad:
json_encode()also respectsJsonSerializable(and in Laravel, some response paths may also useArrayable/Jsonable). Consider rewording to specifically reflect the observed behavior here (DTOs being encoded as plain objects without computedtoArray()fields), so readers don’t infer thatjson_encode()never serializes anything other than public properties.@ -349,2 +356,4 @@->values()->map(fn ($t) => $t->toArray())->values();The intermediate
->values()calls before->map(...)are redundant since you call->values()again at the end. You can simplify these chains (and do slightly less work) by removing the earlier->values()and keeping a single->values()aftermap()(or at the very end of the pipeline).