label(function ($row) { return <<
{$row->name}
{$row->code} HTML; }) ->searchable(function ($query, $searchTerm) { $query->where('name', 'like', "%{$searchTerm}%") ->orWhere('code', 'like', "%{$searchTerm}%"); }) ->html(), Column::make('Tags', 'tags') ->searchable() ->sortable(), Column::make('Min. Belanja', 'min_purchase') ->format(fn ($value) => formatCurrencyNumber($value, 'Rp')) ->searchable() ->sortable(), ArrayColumn::make('Tier') ->data( fn ($value, $row) => $row->tiers->pluck('name')->toArray() ?: ['Semua Tier'] ) ->outputFormat(fn ($index, $value) => Blade::render(''.$value.'')) ->flexRow(['class' => 'gap-2 flex-wrap']), Column::make('Jumlah Diskon', 'discount_amount') ->label(fn ($row, $column) => formatDiscount($row->discount_amount, $row->type)) ->searchable() ->sortable(), Column::make('Maks. Diskon') ->label(fn ($row, $column) => formatCurrencyNumber($row->max_discount, 'Rp')) ->searchable() ->sortable(), Column::make('Kuota / Sisa Voucher') ->label(function ($record) { $quota = $record->quota ? formatCurrencyNumber($record->quota) : 'Tidak Terbatas'; $available = $record->available_count ? formatCurrencyNumber($record->available_count) : 'Tidak Terbatas'; return "{$quota} / {$available}"; }) ->searchable() ->sortable(), Column::make('Batas Per Pembali', 'limit_per_user') ->format(fn ($value) => $value ? $value : 'Tidak Terbatas') ->searchable() ->sortable(), ArrayColumn::make('Outlet') ->data( fn ($value, $row) => $row->outlets->pluck('name')->toArray() ) ->outputFormat(fn ($index, $value) => Blade::render(''.$value.'')) ->flexRow(['class' => 'gap-2 flex-wrap']), Column::make('Visibilitas', 'is_show') ->label(fn ($row, $column) => Blade::render(''.$row->is_show->label().'')) ->html(), Column::make('Tanggal') ->label(function ($row) { $startDate = formatDateLocalized($row->start_date); $startAgo = formatRelativeTime($row->start_date); $endDate = formatDateLocalized($row->end_date); $endAgo = formatRelativeTime($row->end_date); return <<
Tgl Dimulai: {$startDate} ({$startAgo})
Tgl Berakhir: {$endDate} ({$endAgo})
HTML; }) ->html(), Column::make('Aksi') ->label(function ($row) { $actions = ''; if (auth()->user()->can('update voucher')) { $actions .= view('components.actions.table.edit', [ 'id' => $row->hash, 'editRoute' => route('studio.loyalty.voucher.edit', $row->hash), ])->render(); } if (auth()->user()->can('delete voucher')) { $actions .= view('components.actions.table.delete', [ 'id' => $row->hash, ])->render(); } return $actions; }) ->html() ->hideIf(auth()->user()->cannot('update voucher') && auth()->user()->cannot('delete voucher')), ]; } 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', 'is_show', 'vouchers.created_at') ->with(['outlets', 'tiers']) ->whereHas( 'outlets', fn ($q) => $q->whereIn('outlets.id', auth()->user()->outlets()->pluck('outlets.id')) ); } }