From 66579064a2835759a228176b8f61f978cec63e1f Mon Sep 17 00:00:00 2001 From: THEVENOUX Jean-Philippe Date: Wed, 13 Mar 2024 16:54:07 +0100 Subject: [PATCH] Total (#9) * feat: add "extra" add a column named "extra" to category model * feat: add total --- app/Livewire/Dashboard.php | 6 +++- app/Livewire/ListCategory.php | 3 ++ app/Models/Category.php | 2 +- .../2024_03_13_145026_add_extra_column.php | 28 +++++++++++++++++++ resources/views/livewire/dashboard.blade.php | 12 +++++++- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2024_03_13_145026_add_extra_column.php diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php index a603d52..b7412c0 100644 --- a/app/Livewire/Dashboard.php +++ b/app/Livewire/Dashboard.php @@ -143,6 +143,10 @@ public function render() }, 'notes.poste']) ->get(); - return view('livewire.dashboard', compact('categories')); + $total = $categories->sum(function (Category $category) { + return $category->notes_sum_price * ($category->credit ? 1 : -1); + }); + + return view('livewire.dashboard', compact('categories', 'total')); } } diff --git a/app/Livewire/ListCategory.php b/app/Livewire/ListCategory.php index 8f02090..a27ec51 100644 --- a/app/Livewire/ListCategory.php +++ b/app/Livewire/ListCategory.php @@ -30,6 +30,7 @@ public function table(Table $table): Table ->columns([ TextColumn::make('label'), ToggleColumn::make('credit'), + ToggleColumn::make('extra'), ]) ->headerActions([ CreateAction::make() @@ -37,6 +38,7 @@ public function table(Table $table): Table TextInput::make('label') ->required(), Toggle::make('credit'), + Toggle::make('extra'), ]), ]) ->actions([ @@ -46,6 +48,7 @@ public function table(Table $table): Table TextInput::make('label') ->required(), Toggle::make('credit'), + ToggleColumn::make('extra'), ]), DeleteAction::make() ->iconButton(), diff --git a/app/Models/Category.php b/app/Models/Category.php index cbcc694..20093b8 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -15,7 +15,7 @@ class Category extends Model * * @var array */ - protected $fillable = ['label', 'credit']; + protected $fillable = ['label', 'credit', 'extra']; public function notes(): HasMany { diff --git a/database/migrations/2024_03_13_145026_add_extra_column.php b/database/migrations/2024_03_13_145026_add_extra_column.php new file mode 100644 index 0000000..762ee6a --- /dev/null +++ b/database/migrations/2024_03_13_145026_add_extra_column.php @@ -0,0 +1,28 @@ +boolean('extra')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('categories', function (Blueprint $table) { + $table->removeColumn('extra'); + }); + } +}; diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index d38e3d9..204b7a2 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -1,5 +1,5 @@
-
+

Filtres

@@ -23,6 +23,16 @@ class="bg-gray-50 border border-l-0 border-gray-300 text-gray-900 text-sm rounde
+ + + +

Total

+
+ + + {{ Number::currency(($total ?? 0) / 100, 'EUR', 'fr') }} + +
@foreach ($categories as $category)