searchable(), Column::make('Nomor Invoice', 'invoice_number')->searchable(), Column::make('Tanggal Belanja', 'purchase_date') ->format(fn ($value) => formatDateLocalized($value)) ->searchable() ->sortable(), Column::make('Total', 'total') ->format(fn ($value) => formatCurrencyNumber($value, 'Rp')) ->searchable() ->sortable(), Column::make('Catatan', 'note')->searchable(), ArrayColumn::make('Item') ->data( fn ($value, $row) => $row->items->map(fn ($item) => [ 'name' => $item->purchasable?->name, 'quantity' => formatCurrencyNumber($item->quantity, ''), 'unit_price' => formatCurrencyNumber($item->unit_price, 'Rp'), 'total_price' => formatCurrencyNumber($item->total_price, 'Rp'), ])->toArray() ) ->outputFormat( fn ($index, $value) => "
{$value['name']}
{$value['quantity']} x {$value['unit_price']}
{$value['total_price']}
" ) ->flexCol(['class' => 'flex-col gap-3']), Column::make('Aksi') ->label(function ($row) { $actions = ''; if (auth()->user()->can('delete purchase')) { $actions .= view('components.actions.table.delete', [ 'id' => $row->hash, ])->render(); } return $actions; }) ->html() ->hideIf(auth()->user()->cannot('update purchase')), ]; } public function builder(): Builder { return Purchase::select('purchases.id', 'outlet_id', 'invoice_number', 'purchase_date', 'total') ->with(['outlet', 'items', 'items.purchasable']) ->whereIn('outlet_id', auth()->user()->outlets->pluck('id')->toArray()); } }