searchable(), Column::make('Nomor Invoice', 'invoice_number')->searchable(), Column::make('Tanggal Belanja', 'purchase_date') ->format(fn ($value) => formatDate($value)) ->searchable() ->sortable(), Column::make('Total', 'total') ->format(fn ($value) => currency($value, 'Rp')) ->searchable() ->sortable(), ArrayColumn::make('Item') ->data( fn ($value, $row) => $row->items->map(fn ($item) => [ 'name' => $item->purchasable?->name, 'quantity' => currency($item->quantity, ''), 'unit_price' => currency($item->unit_price, 'Rp'), 'total_price' => currency($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.datatables.delete', [ 'id' => $row->hash, 'deleteRoute' => route('studio.manage.purchase.delete', $row->hash), ])->render(); } return $actions; }) ->html(), ]; } public function builder(): Builder { return Purchase::select('purchases.id', 'invoice_number', 'purchase_date', 'total')->with('outlet'); } }