feat: Add voucher visibility functionality and refactor quota/available count display in the voucher table.
This commit is contained in:
parent
d25dd7b9c3
commit
bc9e929a50
@ -41,55 +41,64 @@ public function columns(): array
|
|||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
Column::make('Min. Belanja', 'min_purchase')
|
Column::make('Min. Belanja', 'min_purchase')
|
||||||
->format(fn($value) => formatCurrencyNumber($value, 'Rp'))
|
->format(fn ($value) => formatCurrencyNumber($value, 'Rp'))
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
ArrayColumn::make('Tier')
|
ArrayColumn::make('Tier')
|
||||||
->data(
|
->data(
|
||||||
fn($value, $row) => $row->tiers->pluck('name')->toArray() ?: ['Semua Tier']
|
fn ($value, $row) => $row->tiers->pluck('name')->toArray() ?: ['Semua Tier']
|
||||||
)
|
)
|
||||||
->outputFormat(fn($index, $value) => Blade::render('<span class="text-xs text-gray-400 border border-gray-400 rounded px-1">' . $value . '</span>'))
|
->outputFormat(fn ($index, $value) => Blade::render('<span class="text-xs text-gray-400 border border-gray-400 rounded px-1">'.$value.'</span>'))
|
||||||
->flexRow(['class' => 'gap-2 flex-wrap']),
|
->flexRow(['class' => 'gap-2 flex-wrap']),
|
||||||
|
|
||||||
Column::make('Jumlah Diskon', 'discount_amount')
|
Column::make('Jumlah Diskon', 'discount_amount')
|
||||||
->label(fn($row, $column) => formatDiscount($row->discount_amount, $row->type))
|
->label(fn ($row, $column) => formatDiscount($row->discount_amount, $row->type))
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
Column::make('Maks. Diskon')
|
Column::make('Maks. Diskon')
|
||||||
->label(fn($row, $column) => formatCurrencyNumber($row->max_discount, 'Rp'))
|
->label(fn ($row, $column) => formatCurrencyNumber($row->max_discount, 'Rp'))
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
Column::make('Kuota', 'quota')
|
Column::make('Kuota / Sisa Voucher')
|
||||||
->format(fn($value) => $value ? formatCurrencyNumber($value) : 'Tidak Terbatas')
|
->label(function ($record) {
|
||||||
->searchable()
|
$quota = $record->quota
|
||||||
->sortable(),
|
? formatCurrencyNumber($record->quota)
|
||||||
|
: 'Tidak Terbatas';
|
||||||
|
|
||||||
Column::make('Sisa Voucher', 'available_count')
|
$available = $record->available_count
|
||||||
->format(fn($value) => $value ? formatCurrencyNumber($value) : 'Tidak Terbatas')
|
? formatCurrencyNumber($record->available_count)
|
||||||
|
: 'Tidak Terbatas';
|
||||||
|
|
||||||
|
return "{$quota} / {$available}";
|
||||||
|
})
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
Column::make('Batas Per Pembali', 'limit_per_user')
|
Column::make('Batas Per Pembali', 'limit_per_user')
|
||||||
->format(fn($value) => $value ? $value : 'Tidak Terbatas')
|
->format(fn ($value) => $value ? $value : 'Tidak Terbatas')
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
|
||||||
ArrayColumn::make('Outlet')
|
ArrayColumn::make('Outlet')
|
||||||
->data(
|
->data(
|
||||||
fn($value, $row) => $row->outlets->map(fn($outlet) => [
|
fn ($value, $row) => $row->outlets->map(fn ($outlet) => [
|
||||||
'name' => $outlet->name,
|
'name' => $outlet->name,
|
||||||
'stock' => formatCurrencyNumber($outlet->pivot->stock, ''),
|
'stock' => formatCurrencyNumber($outlet->pivot->stock, ''),
|
||||||
])->toArray()
|
])->toArray()
|
||||||
)
|
)
|
||||||
->outputFormat(fn($index, $value) => Blade::render('
|
->outputFormat(fn ($index, $value) => Blade::render('
|
||||||
<div class="flex items-center space-x-2 bg-gray-50 border border-gray-200 rounded-lg px-2 py-1 text-xs">
|
<div class="flex items-center space-x-2 bg-gray-50 border border-gray-200 rounded-lg px-2 py-1 text-xs">
|
||||||
<span class="font-medium text-gray-700">{{ $value["name"] }}</span>
|
<span class="font-medium text-gray-700">{{ $value["name"] }}</span>
|
||||||
</div>', ['value' => $value]))
|
</div>', ['value' => $value]))
|
||||||
->flexRow(['class' => 'gap-2 flex-wrap']),
|
->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')
|
Column::make('Tanggal')
|
||||||
->label(function ($row) {
|
->label(function ($row) {
|
||||||
$startDate = formatDateLocalized($row->start_date);
|
$startDate = formatDateLocalized($row->start_date);
|
||||||
@ -141,11 +150,11 @@ public function columns(): array
|
|||||||
|
|
||||||
public function builder(): Builder
|
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'])
|
->with(['outlets', 'tiers'])
|
||||||
->whereHas(
|
->whereHas(
|
||||||
'outlets',
|
'outlets',
|
||||||
fn($q) => $q->whereIn('outlets.id', auth()->user()->outlets()->pluck('outlets.id'))
|
fn ($q) => $q->whereIn('outlets.id', auth()->user()->outlets()->pluck('outlets.id'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Livewire\Forms\Studio\Loyalty;
|
namespace App\Livewire\Forms\Studio\Loyalty;
|
||||||
|
|
||||||
|
use App\Enums\IsShow;
|
||||||
use App\Enums\VoucherType;
|
use App\Enums\VoucherType;
|
||||||
use App\Models\Voucher;
|
use App\Models\Voucher;
|
||||||
use App\Rules\UnsignedInteger;
|
use App\Rules\UnsignedInteger;
|
||||||
@ -41,6 +42,8 @@ class VoucherForm extends Form
|
|||||||
|
|
||||||
public array $outlet_ids = [];
|
public array $outlet_ids = [];
|
||||||
|
|
||||||
|
public int $is_show = 1;
|
||||||
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -79,6 +82,7 @@ public function rules(): array
|
|||||||
'tier_ids.*' => Rule::exists('tiers', 'id'),
|
'tier_ids.*' => Rule::exists('tiers', 'id'),
|
||||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||||
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
||||||
|
'is_show' => ['required', Rule::in(IsShow::values())],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +104,7 @@ public function validationAttributes(): array
|
|||||||
'tier_ids.*' => 'tier',
|
'tier_ids.*' => 'tier',
|
||||||
'outlet_ids' => 'outlet',
|
'outlet_ids' => 'outlet',
|
||||||
'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->summary = $this->voucher->summary;
|
||||||
$this->start_date = $this->voucher->start_date;
|
$this->start_date = $this->voucher->start_date;
|
||||||
$this->end_date = $this->voucher->end_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();
|
$this->tier_ids = $this->voucher->tiers->pluck('id')->toArray();
|
||||||
|
|
||||||
@ -178,6 +184,7 @@ private function prepareSavedData(): array
|
|||||||
'summary' => $this->summary,
|
'summary' => $this->summary,
|
||||||
'start_date' => $this->start_date,
|
'start_date' => $this->start_date,
|
||||||
'end_date' => $this->end_date,
|
'end_date' => $this->end_date,
|
||||||
|
'is_show' => $this->is_show,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\IsShow;
|
||||||
use App\Enums\VoucherType;
|
use App\Enums\VoucherType;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@ -28,6 +29,7 @@ protected function casts(): array
|
|||||||
'quota' => 'int',
|
'quota' => 'int',
|
||||||
'available_count' => 'int',
|
'available_count' => 'int',
|
||||||
'limit_per_user' => 'int',
|
'limit_per_user' => 'int',
|
||||||
|
'is_show' => IsShow::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -154,6 +154,17 @@
|
|||||||
<flux:error name="form.tier_ids" />
|
<flux:error name="form.tier_ids" />
|
||||||
</flux:field>
|
</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>
|
</flux:card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user