feat: Add Filament widgets to visualize verification performance and issue distribution by location.
This commit is contained in:
parent
56535076ad
commit
7d970587fa
57
app/Filament/Widgets/IssueLocationChart.php
Normal file
57
app/Filament/Widgets/IssueLocationChart.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use App\Models\IssueManagement;
|
||||||
|
use Filament\Widgets\ChartWidget;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class IssueLocationChart extends ChartWidget
|
||||||
|
{
|
||||||
|
protected ?string $heading = 'Sebaran Isu Berdasarkan Wilayah';
|
||||||
|
|
||||||
|
protected static ?int $sort = 15;
|
||||||
|
|
||||||
|
protected int|string|array $columnSpan = 'full';
|
||||||
|
|
||||||
|
protected function getData(): array
|
||||||
|
{
|
||||||
|
$issueTable = (new IssueManagement)->getTable();
|
||||||
|
$locationTable = (new \App\Models\Location)->getTable();
|
||||||
|
|
||||||
|
$data = IssueManagement::query()
|
||||||
|
->join($locationTable, "{$issueTable}.location_id", '=', "{$locationTable}.id")
|
||||||
|
->select("{$locationTable}.name", DB::raw('count(*) as total'))
|
||||||
|
->groupBy("{$locationTable}.id", "{$locationTable}.name")
|
||||||
|
->orderByDesc('total')
|
||||||
|
->limit(10)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'datasets' => [
|
||||||
|
[
|
||||||
|
'label' => 'Jumlah Isu',
|
||||||
|
'data' => $data->pluck('total')->toArray(),
|
||||||
|
'backgroundColor' => [
|
||||||
|
'#6366F1',
|
||||||
|
'#8B5CF6',
|
||||||
|
'#EC4899',
|
||||||
|
'#F43F5E',
|
||||||
|
'#F59E0B',
|
||||||
|
'#10B981',
|
||||||
|
'#06B6D4',
|
||||||
|
'#3B82F6',
|
||||||
|
'#6366F1',
|
||||||
|
'#8B5CF6',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'labels' => $data->pluck('name')->toArray(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getType(): string
|
||||||
|
{
|
||||||
|
return 'bar';
|
||||||
|
}
|
||||||
|
}
|
||||||
63
app/Filament/Widgets/VerificationPerformanceChart.php
Normal file
63
app/Filament/Widgets/VerificationPerformanceChart.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use App\Enums\VerificationStatus;
|
||||||
|
use App\Models\VerificationRequest;
|
||||||
|
use Filament\Widgets\ChartWidget;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class VerificationPerformanceChart extends ChartWidget
|
||||||
|
{
|
||||||
|
protected ?string $heading = 'Performa Verifikasi (Approved vs Rejected)';
|
||||||
|
|
||||||
|
protected static ?int $sort = 14;
|
||||||
|
|
||||||
|
protected int|string|array $columnSpan = 'full';
|
||||||
|
|
||||||
|
protected function getData(): array
|
||||||
|
{
|
||||||
|
$data = VerificationRequest::query()
|
||||||
|
->select(
|
||||||
|
DB::raw('COUNT(*) as count'),
|
||||||
|
DB::raw('status'),
|
||||||
|
DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month")
|
||||||
|
)
|
||||||
|
->whereIn('status', [VerificationStatus::APPROVED, VerificationStatus::REJECTED])
|
||||||
|
->where('created_at', '>=', now()->subMonths(6))
|
||||||
|
->groupBy('month', 'status')
|
||||||
|
->orderBy('month')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$months = $data->pluck('month')->unique()->sort()->values();
|
||||||
|
|
||||||
|
$approvedData = [];
|
||||||
|
$rejectedData = [];
|
||||||
|
|
||||||
|
foreach ($months as $month) {
|
||||||
|
$approvedData[] = $data->where('month', $month)->where('status', VerificationStatus::APPROVED)->first()?->count ?? 0;
|
||||||
|
$rejectedData[] = $data->where('month', $month)->where('status', VerificationStatus::REJECTED)->first()?->count ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'datasets' => [
|
||||||
|
[
|
||||||
|
'label' => 'Disetujui',
|
||||||
|
'data' => $approvedData,
|
||||||
|
'backgroundColor' => '#10B981',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'label' => 'Ditolak',
|
||||||
|
'data' => $rejectedData,
|
||||||
|
'backgroundColor' => '#EF4444',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'labels' => $months->map(fn ($m) => \Carbon\Carbon::createFromFormat('Y-m', $m)->translatedFormat('M Y'))->toArray(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getType(): string
|
||||||
|
{
|
||||||
|
return 'bar';
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user