Include purchases, credits, and credit cards in all balance components #224
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!224
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "copilot/update-balance-components"
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?
Balance totals were missing ad-hoc purchases entirely, and the dashboard
BalanceSummaryCardbreakdown omitted credits and credit card statements as line items (despite them already being folded into the totals).Description
Backend —
BalanceServicePurchaseService;getMonthBalance()andcalculateYearBalance()now fetch purchase totals viagetPurchaseTotalForUser()and surface them aspurchases_actualactual_outvia the existingPurchaseAggregateTransactionDTOinTransactionAggregatorService;purchases_actualis fetched separately only to power the UI breakdown —expenses_actualin the breakdown is set to$actualExpenses - $purchasesActualso the two categories are distinctactual_out_breakdownextended with apurchaseskey;expected_out_breakdownextended withcredit_cardgetDetailedMonthlyBalance()(MonthView page) filters out the aggregatePurchaseAggregateTransactionentry and appends individualPurchaserecords instead, so they appear as granular line items in the chart and category summaryFrontend
balanceStore.ts/types/finance.ts:MonthBalanceData/BalanceDatainterfaces extended withcredit_expected,credit_actual,credit_card_expected,credit_card_actual,purchases_actual; breakdown sub-types updated accordinglyBalanceSummaryCard.vue: Added three new outgoing-breakdown sections — Purchases (actual only, shown when > 0), Credits (expected + actual, P+I chip), Credit Cards (expected + actual); simplified "Total Outgoing" label which previously read "(Expenses + Mortgage)" — an incomplete descriptionType of Change
Testing
Unit tests in
BalanceServiceTest: verifiespurchases_actualequals the purchase total,expenses_actualexcludes purchases,actual_outincludes purchases,expected_outis unaffected, and purchases outside the period boundary are excluded.BalanceTestupdated to pass the newPurchaseServiceargument to the manually-constructedBalanceService. All tests pass.Code Quality
CI/CD Checks
Additional Notes
The
PurchaseObserverwas already clearing the balance cache on purchase mutations — the service just wasn't reading purchases. No observer changes needed.TransactionAggregatorServicealready appends aPurchaseAggregateTransactionDTO(typeEXPENSE, stateACTUALIZED) to its collection, so purchases were already counted inside$actualExpenses. The previous revision accidentally added$purchasesActualon top of that, double-counting purchases. This has been corrected.Comment
@coderabbitai helpto get the list of available commands and usage tips.@copilot
Some unit and feature tests are failing
Perhaps they need to be updated?
Fixed in
c4ca9a5. Two issues were causing the failures:BalanceTest.php— tests were manually constructingBalanceServicewith 4 args, but the constructor now requires 5 (the newPurchaseService). Added the missing argument.Purchase double-counting —
TransactionAggregatorServicealready includes aPurchaseAggregateTransactionDTOin its transactions collection (making purchases part of$actualExpenses). My previous change was also adding$purchasesActualseparately toactual_out, which counted purchases twice (explaining the +100 delta inBalanceSanityTest). Fixed by removing the duplicate addition;purchases_actualis still fetched separately to power the UI breakdown, andexpenses_actualin the breakdown is now$actualExpenses - $purchasesActualso the two categories are distinct. Also fixedgetDetailedMonthlyBalance()to filter out the aggregate "Purchases" entry before appending individual purchase line items.All 18 previously-failing tests now pass.