From 5ef655d16f8019c8039bb24f973f40e885bf4882 Mon Sep 17 00:00:00 2001 From: jeremy bayse Date: Sun, 26 Jul 2026 13:41:48 +0200 Subject: [PATCH] =?UTF-8?q?Add=20"reste=20=C3=A0=20d=C3=A9penser"=20tile?= =?UTF-8?q?=20to=20the=20dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shows the total remaining depense budget for the selected period, above the breakdown table — reuses the totals.reste figure already computed per section, no new query. Co-Authored-By: Claude Sonnet 5 --- .../views/livewire/dashboard/index.blade.php | 5 ++++ tests/Feature/DashboardTest.php | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/resources/views/livewire/dashboard/index.blade.php b/resources/views/livewire/dashboard/index.blade.php index f247380..b607563 100644 --- a/resources/views/livewire/dashboard/index.blade.php +++ b/resources/views/livewire/dashboard/index.blade.php @@ -22,6 +22,11 @@ +
+

Reste à dépenser

+

{{ number_format($sections['depense']['totals']['reste'], 2, ',', ' ') }} €

+
+ @php $colors = [ 'revenu' => ['bg' => 'bg-positive-fill', 'row' => 'bg-positive-surface/40'], diff --git a/tests/Feature/DashboardTest.php b/tests/Feature/DashboardTest.php index e361376..a08be2c 100644 --- a/tests/Feature/DashboardTest.php +++ b/tests/Feature/DashboardTest.php @@ -50,6 +50,29 @@ it('filters tracked and budget to a single month when a period is selected', fun expect($sections['depense']['totals']['budget'])->toBe(270.0); }); +it('computes the remaining depense budget total for the tile', function (): void { + $user = User::factory()->create(); + $household = $user->currentHousehold; + $loyer = $household->categories()->create(['name' => 'Loyer', 'type' => 'depense', 'position' => 1]); + $courses = $household->categories()->create(['name' => 'Courses', 'type' => 'depense', 'position' => 2]); + + $loyer->budgetLines()->create(['household_id' => $household->id, 'year' => 2026, 'month' => null, 'amount' => 1000]); + $courses->budgetLines()->create(['household_id' => $household->id, 'year' => 2026, 'month' => null, 'amount' => 400]); + + $household->transactions()->create([ + 'category_id' => $loyer->id, 'user_id' => $user->id, + 'date' => '2026-03-05', 'date_effective' => '2026-03-05', 'amount' => 1000, + ]); + $household->transactions()->create([ + 'category_id' => $courses->id, 'user_id' => $user->id, + 'date' => '2026-03-05', 'date_effective' => '2026-03-05', 'amount' => 150, + ]); + + $component = Livewire::actingAs($user)->test(Index::class)->set('year', 2026)->set('period', '3'); + + expect($component->viewData('sections')['depense']['totals']['reste'])->toBe(250.0); +}); + it('excludes zero-tracked categories from chart data and caps it at 6', function (): void { $user = User::factory()->create(); $household = $user->currentHousehold;