Skip to content

Commit

Permalink
Total (#9)
Browse files Browse the repository at this point in the history
* feat: add "extra"

add a column named "extra" to category model

* feat: add total
  • Loading branch information
sylfel authored Mar 13, 2024
1 parent 6f40922 commit 6657906
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
3 changes: 3 additions & 0 deletions app/Livewire/ListCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public function table(Table $table): Table
->columns([
TextColumn::make('label'),
ToggleColumn::make('credit'),
ToggleColumn::make('extra'),
])
->headerActions([
CreateAction::make()
->form([
TextInput::make('label')
->required(),
Toggle::make('credit'),
Toggle::make('extra'),
]),
])
->actions([
Expand All @@ -46,6 +48,7 @@ public function table(Table $table): Table
TextInput::make('label')
->required(),
Toggle::make('credit'),
ToggleColumn::make('extra'),
]),
DeleteAction::make()
->iconButton(),
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Category extends Model
*
* @var array<int, string>
*/
protected $fillable = ['label', 'credit'];
protected $fillable = ['label', 'credit', 'extra'];

public function notes(): HasMany
{
Expand Down
28 changes: 28 additions & 0 deletions database/migrations/2024_03_13_145026_add_extra_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('categories', function (Blueprint $table) {
$table->boolean('extra')->default(true);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('categories', function (Blueprint $table) {
$table->removeColumn('extra');
});
}
};
12 changes: 11 additions & 1 deletion resources/views/livewire/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<header class="m-4 flex justify-center" wire:loading.class="opacity-50">
<header class="m-4 flex justify-center gap-4" wire:loading.class="opacity-50">
<x-section>
<x-slot:header>
<h2 class="text-center grow">Filtres</h2>
Expand All @@ -23,6 +23,16 @@ class="bg-gray-50 border border-l-0 border-gray-300 text-gray-900 text-sm rounde
</div>
</form>
</x-section>

<x-section>
<x-slot:header>
<h2 class="text-center grow">Total</h2>
</x-slot:header>

<span class="font-bold {{ $total >= 0 ? 'text-green-600' : 'text-red-600' }}">
{{ Number::currency(($total ?? 0) / 100, 'EUR', 'fr') }}</span>

</x-section>
</header>
<div class="grid grid-cols-[repeat(auto-fit,_minmax(min(30rem,_100%),_1fr))] gap-4 p-2 sm:p-4 lg:p-8">
@foreach ($categories as $category)
Expand Down

0 comments on commit 6657906

Please sign in to comment.