From f648c118c032f997d7a3d5c3a0d2d2276abbfb31 Mon Sep 17 00:00:00 2001 From: Jean-Philippe THEVENOUX Date: Thu, 14 Mar 2024 09:24:14 +0100 Subject: [PATCH] feat: Summaries add summaries by category change UI to mobile compat --- app/Livewire/Dashboard.php | 18 ++++++++-- resources/views/components/section.blade.php | 2 +- resources/views/livewire/dashboard.blade.php | 35 +++++++++++++++----- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php index b7412c0..95b93e8 100644 --- a/app/Livewire/Dashboard.php +++ b/app/Livewire/Dashboard.php @@ -136,6 +136,7 @@ public function render() $query->where('notes.year', $this->year) ->where('notes.month', $this->month); }], 'price') + ->orderBy('label') ->with(['notes' => function (HasMany $query) { $query->where('notes.year', $this->year) ->where('notes.month', $this->month) @@ -143,10 +144,21 @@ public function render() }, 'notes.poste']) ->get(); - $total = $categories->sum(function (Category $category) { - return $category->notes_sum_price * ($category->credit ? 1 : -1); + $summaries = collect(['Extra' => 0]); + $total = 0; + + $categories->each(function (Category $category) use (&$summaries, &$total) { + $montant = $category->notes_sum_price * ($category->credit ? 1 : -1); + if ($category->extra) { + $summaries->put('Extra', $summaries->get('Extra', 0) + $montant); + } else { + $summaries->put($category->label, $montant); + } + $total = $total + $montant; }); - return view('livewire.dashboard', compact('categories', 'total')); + $summaries = $summaries->sortKeys(); + + return view('livewire.dashboard', compact('categories', 'total', 'summaries')); } } diff --git a/resources/views/components/section.blade.php b/resources/views/components/section.blade.php index f54ad3a..615639a 100644 --- a/resources/views/components/section.blade.php +++ b/resources/views/components/section.blade.php @@ -1,4 +1,4 @@ -
+
merge(['class' => 'rounded-lg border border-black bg-white ']) }}> @if (isset($header))
{{ $header }} diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index 204b7a2..15d8a1d 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -1,21 +1,24 @@
-
+

Filtres

+ + {{ Number::currency(($total ?? 0) / 100, 'EUR', 'fr') }} +
-
-
+ +