simedkom/app/Filament/Widgets/OverviewStats.php

78 lines
3.2 KiB
PHP

<?php
namespace App\Filament\Widgets;
use App\Models\Company;
use App\Models\DataChangeRequest;
use App\Models\Journalist;
use App\Models\PartnerMedia;
use App\Models\VerificationRequest;
use App\Models\Visitor;
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
use Filament\Support\Icons\Heroicon;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class OverviewStats extends BaseWidget
{
use HasWidgetShield, InteractsWithPageFilters;
protected static ?int $sort = 1;
protected int|string|array $columnSpan = 'full';
protected function getStats(): array
{
$startDate = $this->filters['startDate'] ?? null;
$endDate = $this->filters['endDate'] ?? null;
return [
Stat::make('Total Perusahaan', Company::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
->count())
->description('Perusahaan terdaftar')
->descriptionIcon(Heroicon::BuildingOffice2)
->color('primary'),
Stat::make('Media Terverifikasi', PartnerMedia::approved()
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
->count())
->description('Media aktif')
->descriptionIcon(Heroicon::CheckBadge)
->color('success'),
Stat::make('Total Jurnalis', Journalist::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
->count())
->description('Jurnalis terdaftar')
->descriptionIcon(Heroicon::Identification)
->color('info'),
Stat::make('Antrean Verifikasi', VerificationRequest::pending()
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
->count())
->description('Butuh tindakan')
->descriptionIcon(Heroicon::PencilSquare)
->color('warning'),
Stat::make('Antrean Perubahan', DataChangeRequest::pending()
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
->count())
->description('Perubahan data')
->descriptionIcon(Heroicon::DocumentText)
->color('warning'),
Stat::make('Total Pengunjung', Visitor::when($startDate, fn ($q) => $q->whereDate('date', '>=', $startDate))
->when($endDate, fn ($q) => $q->whereDate('date', '<=', $endDate))
->count())
->description('Total traffic')
->descriptionIcon(Heroicon::ChartBar)
->color('info'),
];
}
}