searchable(),
Column::make('module', 'module')
->format(fn ($row) => ucfirst($row))
->searchable(),
Column::make('Status', 'status')
->label(fn ($row, $column) => Blade::render(''.$row->status->label().''))
->html(),
Column::make('Tanggal')
->label(function ($row) {
$startDate = formatDate($row->created_at);
$startAgo = timeAgo($row->created_at);
$endDate = formatDate($row->finalized_at);
$endAgo = timeAgo($row->finalized_at);
return <<
Tgl Permohonan:
{$startDate}
({$startAgo})
Tgl Ditanggapi:
{$endDate}
({$endAgo})
HTML;
})
->html(),
Column::make('Aksi')
->label(function ($row) {
$actions = '';
if (auth()->user()->can('approve price request') && $row->status === PriceRequestStatus::PENDING) {
$actions .= view('components.datatables.confirm', [
'id' => $row->hash,
'message' => 'Pemohon yang diterima bisa melihat data harga beli.',
'confirmButtonText' => 'Ya, Terima',
'target' => 'approve',
'title' => 'Terima',
'confirmButtonColor' => 'primary',
'icon' => 'check-circle',
])->render();
}
if (auth()->user()->can('reject price request') && $row->status === PriceRequestStatus::PENDING) {
$actions .= view('components.datatables.confirm', [
'id' => $row->hash,
'message' => 'Jika ditolak, pomohon tidak dapat melihat data harga beli.',
'confirmButtonText' => 'Ya, Tolak',
'target' => 'reject',
'title' => 'Tolak',
'confirmButtonColor' => 'red',
'icon' => 'x-circle',
])->render();
}
return $actions;
})
->html()
->hideIf(auth()->user()->cannot('approve price request') && auth()->user()->cannot('reject price request')),
];
}
public function builder(): Builder
{
return PriceRequest::select(
'price_requests.id',
'price_requests.user_id',
'module',
'price_requests.status',
'price_requests.created_at',
'finalized_at'
)
->with(['user', 'user.employee']);
}
}