searchable(), Column::make('Voucher', 'voucher.name')->searchable(), Column::make('Nomor Invoice') ->label(function ($row) { return <<
{$row->invoice_number}
{$row?->customer?->name} HTML; }) ->searchable(function ($query, $searchTerm) { $query->where('invoice_number', 'like', "%{$searchTerm}%") ->orWhereHas('customer', function (Builder $query) use ($searchTerm) { $query->where('name', 'like', "%{$searchTerm}%"); }); }) ->html(), Column::make('Tanggal', 'ordered_at') ->format(fn ($value) => formatDate($value)) ->searchable(), Column::make('HPP', 'cogs') ->format(fn ($value) => currency($value, 'Rp')) ->searchable(), ArrayColumn::make('Item') ->data( fn ($value, $row) => $row->items->map(fn ($item) => [ 'name' => $item->orderable?->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('Ringkasan') ->label(function ($value) { $subtotal = currency($value->subtotal, 'Rp'); $discount = currency($value->discount, 'Rp'); $total = currency($value->total, 'Rp'); return Blade::render('
{{ $subtotal }}
-{{ $discount }}
{{ $total }}
', ['value' => $value, 'subtotal' => $subtotal, 'discount' => $discount, 'total' => $total]); }) ->html(), Column::make('Channel', 'channel') ->format(fn ($value) => Blade::render( '' .$value->label() .'' )) ->html(), Column::make('Status', 'status') ->format(fn ($value) => Blade::render( '' .$value->label() .'' )) ->html(), Column::make('Aksi') ->label(function ($row) { $actions = ''; if (auth()->user()->can('create order') && auth()->user()->can('show order')) { $actions .= view('components.datatables.print', [ 'id' => $row->hash, ])->render(); } if (auth()->user()->can('show order')) { $actions .= view('components.datatables.show', [ 'id' => $row->hash, 'showRoute' => route('studio.manage.order.show', $row->hash), ])->render(); } if (auth()->user()->can('delete order')) { $actions .= view('components.datatables.delete', [ 'id' => $row->hash, 'deleteRoute' => route('studio.manage.order.delete', $row->hash), ])->render(); } return $actions; }) ->html() ->hideIf(auth()->user()->cannot('show order') && auth()->user()->cannot('delete order')), ]; } public function builder(): Builder { return Order::select( 'orders.id', 'orders.user_id', 'invoice_number', 'customer_id', 'orders.ordered_at', 'cogs', 'subtotal', 'discount', 'total', 'orders.status', 'channel', 'orders.voucher_id', 'orders.created_at' ) ->with(['user', 'user.employee', 'customer', 'voucher']) ->whereHas( 'outlet', fn ($q) => $q->whereIn('outlets.id', auth()->user()->outlets()->pluck('outlets.id')) ); } }