feat: phase 6 — dashboard widgets, sales & stock reports, user management, activity log
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Services\ComplaintService;
|
||||
use App\Services\InsForge\InsForgeClient;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\StockService;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class DashboardStats extends StatsOverviewWidget
|
||||
{
|
||||
protected static ?int $sort = 0;
|
||||
|
||||
protected ?string $heading = 'Ringkasan Operasional';
|
||||
|
||||
public function getStats(): array
|
||||
{
|
||||
$orderService = app(OrderService::class);
|
||||
|
||||
$counts = $orderService->countByStatus();
|
||||
|
||||
$openComplaints = app(InsForgeClient::class)->countRecords('complaints', [
|
||||
'status' => ComplaintService::STATUS_OPEN,
|
||||
]);
|
||||
|
||||
$critical = collect(app(StockService::class)->paginate(perPage: 100)->items())
|
||||
->filter(fn (array $row): bool => (int) $row['quantity'] <= (int) data_get($row, 'products.stock_minimum', 0))
|
||||
->count();
|
||||
|
||||
return [
|
||||
Stat::make('Pending', (string) ($counts[OrderService::STATUS_PENDING] ?? 0))->color('gray'),
|
||||
Stat::make('Diproses', (string) ($counts[OrderService::STATUS_PROCESSING] ?? 0))->color('info'),
|
||||
Stat::make('Dikirim', (string) ($counts[OrderService::STATUS_DELIVERING] ?? 0))->color('warning'),
|
||||
Stat::make('Selesai', (string) ($counts[OrderService::STATUS_COMPLETED] ?? 0))->color('success'),
|
||||
Stat::make('Komplain Terbuka', (string) $openComplaints)->color($openComplaints > 0 ? 'danger' : 'success'),
|
||||
Stat::make('Stok Kritis', (string) $critical)->color($critical > 0 ? 'danger' : 'success'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user