feat: Add voucher visibility functionality and refactor quota/available count display in the voucher table.
This commit is contained in:
parent
d25dd7b9c3
commit
bc9e929a50
@ -62,13 +62,18 @@ public function columns(): array
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Column::make('Kuota', 'quota')
|
||||
->format(fn($value) => $value ? formatCurrencyNumber($value) : 'Tidak Terbatas')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Column::make('Kuota / Sisa Voucher')
|
||||
->label(function ($record) {
|
||||
$quota = $record->quota
|
||||
? formatCurrencyNumber($record->quota)
|
||||
: 'Tidak Terbatas';
|
||||
|
||||
Column::make('Sisa Voucher', 'available_count')
|
||||
->format(fn($value) => $value ? formatCurrencyNumber($value) : 'Tidak Terbatas')
|
||||
$available = $record->available_count
|
||||
? formatCurrencyNumber($record->available_count)
|
||||
: 'Tidak Terbatas';
|
||||
|
||||
return "{$quota} / {$available}";
|
||||
})
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
@ -90,6 +95,10 @@ public function columns(): array
|
||||
</div>', ['value' => $value]))
|
||||
->flexRow(['class' => 'gap-2 flex-wrap']),
|
||||
|
||||
Column::make('Visibilitas', 'is_show')
|
||||
->label(fn ($row, $column) => Blade::render('<flux:badge color="'.$row->is_show->color().'">'.$row->is_show->label().'</flux:badge>'))
|
||||
->html(),
|
||||
|
||||
Column::make('Tanggal')
|
||||
->label(function ($row) {
|
||||
$startDate = formatDateLocalized($row->start_date);
|
||||
@ -141,7 +150,7 @@ public function columns(): array
|
||||
|
||||
public function builder(): Builder
|
||||
{
|
||||
return Voucher::select('vouchers.id', 'vouchers.name', 'code', 'tags', 'min_purchase', 'discount_amount', 'max_discount', 'quota', 'available_count', 'limit_per_user', 'start_date', 'end_date', 'type', 'vouchers.created_at')
|
||||
return Voucher::select('vouchers.id', 'vouchers.name', 'code', 'tags', 'min_purchase', 'discount_amount', 'max_discount', 'quota', 'available_count', 'limit_per_user', 'start_date', 'end_date', 'type', 'is_show', 'vouchers.created_at')
|
||||
->with(['outlets', 'tiers'])
|
||||
->whereHas(
|
||||
'outlets',
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Livewire\Forms\Studio\Loyalty;
|
||||
|
||||
use App\Enums\IsShow;
|
||||
use App\Enums\VoucherType;
|
||||
use App\Models\Voucher;
|
||||
use App\Rules\UnsignedInteger;
|
||||
@ -41,6 +42,8 @@ class VoucherForm extends Form
|
||||
|
||||
public array $outlet_ids = [];
|
||||
|
||||
public int $is_show = 1;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
@ -79,6 +82,7 @@ public function rules(): array
|
||||
'tier_ids.*' => Rule::exists('tiers', 'id'),
|
||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
||||
'is_show' => ['required', Rule::in(IsShow::values())],
|
||||
];
|
||||
}
|
||||
|
||||
@ -100,6 +104,7 @@ public function validationAttributes(): array
|
||||
'tier_ids.*' => 'tier',
|
||||
'outlet_ids' => 'outlet',
|
||||
'outlet_ids.*' => 'outlet',
|
||||
'is_show' => 'visibilitas',
|
||||
];
|
||||
}
|
||||
|
||||
@ -121,6 +126,7 @@ public function setVoucher(Voucher $voucher): void
|
||||
$this->summary = $this->voucher->summary;
|
||||
$this->start_date = $this->voucher->start_date;
|
||||
$this->end_date = $this->voucher->end_date;
|
||||
$this->is_show = $this->voucher->is_show->value;
|
||||
|
||||
$this->tier_ids = $this->voucher->tiers->pluck('id')->toArray();
|
||||
|
||||
@ -178,6 +184,7 @@ private function prepareSavedData(): array
|
||||
'summary' => $this->summary,
|
||||
'start_date' => $this->start_date,
|
||||
'end_date' => $this->end_date,
|
||||
'is_show' => $this->is_show,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\IsShow;
|
||||
use App\Enums\VoucherType;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@ -28,6 +29,7 @@ protected function casts(): array
|
||||
'quota' => 'int',
|
||||
'available_count' => 'int',
|
||||
'limit_per_user' => 'int',
|
||||
'is_show' => IsShow::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -154,6 +154,17 @@
|
||||
<flux:error name="form.tier_ids" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>Visibilitas <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:radio.group wire:model="form.is_show" variant="buttons" class="w-full *:flex-1">
|
||||
@foreach (\App\Enums\IsShow::cases() as $item)
|
||||
<flux:radio value="{{ $item->value }}">
|
||||
{{ $item->label() }}
|
||||
</flux:radio>
|
||||
@endforeach
|
||||
</flux:radio.group>
|
||||
<flux:error name="form.is_show" />
|
||||
</flux:field>
|
||||
</flux:card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user