feat(voucher): membuat stats dan menambahkan scope di model
This commit is contained in:
parent
54a7fcec5a
commit
30c30c7642
@ -14,6 +14,30 @@ class Index extends Component
|
|||||||
{
|
{
|
||||||
use WithConfirmation, WithToast;
|
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)
|
public function delete(Voucher $voucher)
|
||||||
{
|
{
|
||||||
$voucher->delete();
|
$voucher->delete();
|
||||||
|
|||||||
@ -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
|
public function outlets(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Outlet::class);
|
return $this->belongsToMany(Outlet::class);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<flux:heading size="xl">{{ $pageTitle }}</flux:heading>
|
<flux:heading size="xl">{{ $pageTitle }}</flux:heading>
|
||||||
</div>
|
</div>
|
||||||
@can ('create voucher')
|
@can('create voucher')
|
||||||
<div>
|
<div>
|
||||||
<flux:button href="{{ route('studio.loyalty.voucher.create') }}" variant="primary" wire:navigate.hover
|
<flux:button href="{{ route('studio.loyalty.voucher.create') }}" variant="primary" wire:navigate.hover
|
||||||
class="text-sm">
|
class="text-sm">
|
||||||
@ -14,6 +14,17 @@ class="text-sm">
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
|
@if (!empty($stats))
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
|
||||||
|
@foreach ($stats as $stat)
|
||||||
|
<div class="rounded-lg px-6 py-4 bg-zinc-200 dark:bg-zinc-700">
|
||||||
|
<flux:subheading>{{ $stat['title'] }}</flux:subheading>
|
||||||
|
<flux:heading size="xl" class="mb-2">{{ $stat['value'] }}</flux:heading>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<livewire:datatable.studio.loyalty.vouchers-table />
|
<livewire:datatable.studio.loyalty.vouchers-table />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user