Balance View: collapse purchases into single aggregate line #236

Merged
Copilot merged 1 commit from copilot/update-balance-view-purchases into main 2026-04-27 12:01:21 +00:00
Copilot commented 2026-04-27 11:53:30 +00:00 (Migrated from github.com)

The Balance View was listing every individual purchase as a separate expense entry with its own category, making the breakdown noisy. Instead, all purchases for the period should appear as a single "Purchases" total.

Description

BalanceService::getDetailedMonthlyBalance() was iterating over every Purchase record via getPurchasesForUser() and pushing one entry per item using the purchase's category name. Replaced with a single call to the already-available getPurchaseTotalForUser(), pushing one aggregate entry:

// Before: one entry per purchase, category-per-item
foreach ($purchases as $purchase) {
    $expenseDetails->push((object) [
        'name' => $purchase->name,
        'category' => (object) ['name' => $purchase->category?->name ?? 'Purchases'],
        ...
    ]);
}

// After: single aggregate
$purchasesTotal = $this->purchaseService->getPurchaseTotalForUser($user, $startDate, $endDate);
if ($purchasesTotal > 0) {
    $expenseDetails->push((object) [
        'name' => 'Purchases',
        'category' => (object) ['name' => 'Purchases'],
        ...
    ]);
}

No frontend changes needed — MonthView.vue's groupByCategory already groups by category.name, so the single entry collapses naturally into one chart slice and one summary row.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (code change that neither fixes a bug nor adds a feature)
  • Performance improvement
  • Test coverage improvement

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this manually (if applicable)

Code Quality

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors

CI/CD Checks

  • All automated tests pass
  • Code formatting (Pint) passes
  • JavaScript/TypeScript linting passes
  • Build process completes successfully

Additional Notes

Also a minor performance improvement: getPurchaseTotalForUser() issues a single SUM query vs. fetching all purchase rows with eager-loaded categories.

The Balance View was listing every individual purchase as a separate expense entry with its own category, making the breakdown noisy. Instead, all purchases for the period should appear as a single "Purchases" total. ## Description `BalanceService::getDetailedMonthlyBalance()` was iterating over every `Purchase` record via `getPurchasesForUser()` and pushing one entry per item using the purchase's category name. Replaced with a single call to the already-available `getPurchaseTotalForUser()`, pushing one aggregate entry: ```php // Before: one entry per purchase, category-per-item foreach ($purchases as $purchase) { $expenseDetails->push((object) [ 'name' => $purchase->name, 'category' => (object) ['name' => $purchase->category?->name ?? 'Purchases'], ... ]); } // After: single aggregate $purchasesTotal = $this->purchaseService->getPurchaseTotalForUser($user, $startDate, $endDate); if ($purchasesTotal > 0) { $expenseDetails->push((object) [ 'name' => 'Purchases', 'category' => (object) ['name' => 'Purchases'], ... ]); } ``` No frontend changes needed — `MonthView.vue`'s `groupByCategory` already groups by `category.name`, so the single entry collapses naturally into one chart slice and one summary row. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [ ] Refactoring (code change that neither fixes a bug nor adds a feature) - [ ] Performance improvement - [ ] Test coverage improvement ## Testing - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [x] I have tested this manually (if applicable) ## Code Quality - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] My changes generate no new warnings or errors ## CI/CD Checks - [ ] All automated tests pass - [ ] Code formatting (Pint) passes - [ ] JavaScript/TypeScript linting passes - [ ] Build process completes successfully ## Additional Notes Also a minor performance improvement: `getPurchaseTotalForUser()` issues a single `SUM` query vs. fetching all purchase rows with eager-loaded categories.
coderabbitai[bot] commented 2026-04-27 11:53:37 +00:00 (Migrated from github.com)

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: f453c3e5-9d47-4e8d-b731-865f59aa5145

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands and usage tips.

<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- This is an auto-generated comment: skip review by coderabbit.ai --> > [!IMPORTANT] > ## Review skipped > > Bot user detected. > > To trigger a single review, invoke the `@coderabbitai review` command. > > <details> > <summary>⚙️ Run configuration</summary> > > **Configuration used**: defaults > > **Review profile**: CHILL > > **Plan**: Free > > **Run ID**: `f453c3e5-9d47-4e8d-b731-865f59aa5145` > > </details> > > You can disable this status message by setting the `reviews.review_status` to `false` in the CodeRabbit configuration file. > > Use the checkbox below for a quick retry: > - [ ] <!-- {"checkboxId": "e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: skip review by coderabbit.ai --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub> <!-- tips_end -->
Sign in to join this conversation.
No description provided.