49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Services\OrderService;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Filament\Widgets\TableWidget;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class RecentOrders extends TableWidget
|
|
{
|
|
protected static ?int $sort = 2;
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
$service = app(OrderService::class);
|
|
|
|
return $table
|
|
->heading('Pesanan Terbaru')
|
|
->records(fn () => new Collection($service->recent(8)))
|
|
->columns([
|
|
TextColumn::make('order_number')->label('No. Order')->badge(),
|
|
TextColumn::make('customers.name')->label('Pelanggan'),
|
|
TextColumn::make('order_date')->label('Tgl')->date('d M Y'),
|
|
TextColumn::make('order_status')
|
|
->label('Status')
|
|
->badge()
|
|
->color(fn (string $state): string => match ($state) {
|
|
'pending' => 'gray',
|
|
'processing' => 'info',
|
|
'delivering' => 'warning',
|
|
'completed' => 'success',
|
|
default => 'danger',
|
|
})
|
|
->formatStateUsing(fn (string $state): string => match ($state) {
|
|
'pending' => 'Pending',
|
|
'processing' => 'Diproses',
|
|
'delivering' => 'Dikirim',
|
|
'completed' => 'Selesai',
|
|
default => 'Batal',
|
|
}),
|
|
])
|
|
->paginated(false);
|
|
}
|
|
}
|