diff --git a/app/Livewire/Studio/Loyalty/Voucher/Index.php b/app/Livewire/Studio/Loyalty/Voucher/Index.php index a6cf55b..91e149d 100644 --- a/app/Livewire/Studio/Loyalty/Voucher/Index.php +++ b/app/Livewire/Studio/Loyalty/Voucher/Index.php @@ -14,6 +14,30 @@ class Index extends Component { use WithConfirmation, WithToast; + public array $stats = []; + + public function mount() + { + $this->stats = [ + [ + 'title' => 'Total Voucher', + 'value' => Voucher::count(), + ], + [ + 'title' => 'Voucher Aktif', + 'value' => Voucher::query()->active()->count(), + ], + [ + 'title' => 'Voucher Tidak Aktif', + 'value' => Voucher::query()->inactive()->count(), + ], + [ + 'title' => 'Voucher Akan Datang', + 'value' => Voucher::query()->upcoming()->count(), + ], + ]; + } + public function delete(Voucher $voucher) { $voucher->delete(); diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php index 20a5970..46d9e5f 100644 --- a/app/Models/Voucher.php +++ b/app/Models/Voucher.php @@ -41,6 +41,18 @@ public function active(Builder $query): void }); } + #[Scope] + public function inactive(Builder $query): void + { + $query->whereDate('end_date', '<', now()); + } + + #[Scope] + public function upcoming(Builder $query): void + { + $query->whereDate('start_date', '>', now()); + } + public function outlets(): BelongsToMany { return $this->belongsToMany(Outlet::class); diff --git a/resources/views/livewire/studio/loyalty/voucher/index.blade.php b/resources/views/livewire/studio/loyalty/voucher/index.blade.php index 15641ad..4daaf7f 100644 --- a/resources/views/livewire/studio/loyalty/voucher/index.blade.php +++ b/resources/views/livewire/studio/loyalty/voucher/index.blade.php @@ -3,7 +3,7 @@