feat: add new Filament dashboard widgets for media cooperation ranking, task realization, and cooperation status.
This commit is contained in:
parent
a44c7181fd
commit
416739e25f
56
app/Filament/Widgets/CooperationStatusChart.php
Normal file
56
app/Filament/Widgets/CooperationStatusChart.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Enums\CooperationStatus;
|
||||
use App\Models\Cooperation;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class CooperationStatusChart extends ChartWidget
|
||||
{
|
||||
protected ?string $heading = 'Status Kerjasama';
|
||||
|
||||
protected static ?int $sort = 9;
|
||||
|
||||
protected int|string|array $columnSpan = 1;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Cooperation::query()
|
||||
->selectRaw('status, count(*) as total')
|
||||
->groupBy('status')
|
||||
->get();
|
||||
|
||||
$labels = [];
|
||||
$counts = [];
|
||||
$colors = [];
|
||||
|
||||
foreach (CooperationStatus::cases() as $case) {
|
||||
$labels[] = $case->getLabel();
|
||||
$counts[] = $data->where('status', $case)->first()?->total ?? 0;
|
||||
$colors[] = match ($case) {
|
||||
CooperationStatus::PENDING => '#F59E0B',
|
||||
CooperationStatus::ASSIGNMENT => '#3B82F6',
|
||||
CooperationStatus::VERIFICATION => '#6366F1',
|
||||
CooperationStatus::PAYMENT => '#8B5CF6',
|
||||
CooperationStatus::COMPLETED => '#10B981',
|
||||
};
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Jumlah Kerjasama',
|
||||
'data' => $counts,
|
||||
'backgroundColor' => $colors,
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'pie';
|
||||
}
|
||||
}
|
||||
45
app/Filament/Widgets/MediaCooperationRankingChart.php
Normal file
45
app/Filament/Widgets/MediaCooperationRankingChart.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Models\PartnerMedia;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MediaCooperationRankingChart extends ChartWidget
|
||||
{
|
||||
protected ?string $heading = 'Ranking Media (Kerjasama Disetujui)';
|
||||
|
||||
protected static ?int $sort = 11;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = PartnerMedia::query()
|
||||
->join('cooperation_media', 'partner_media.id', '=', 'cooperation_media.partner_media_id')
|
||||
->where('cooperation_media.status', ApprovalStatus::ACCEPTED)
|
||||
->select('partner_media.name', DB::raw('count(*) as total'))
|
||||
->groupBy('partner_media.id', 'partner_media.name')
|
||||
->orderByDesc('total')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Total Kerjasama',
|
||||
'data' => $data->pluck('total')->toArray(),
|
||||
'backgroundColor' => '#6366F1',
|
||||
],
|
||||
],
|
||||
'labels' => $data->pluck('name')->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
69
app/Filament/Widgets/TaskRealizationChart.php
Normal file
69
app/Filament/Widgets/TaskRealizationChart.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Models\Report;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TaskRealizationChart extends ChartWidget
|
||||
{
|
||||
protected ?string $heading = 'Realisasi Penugasan (Laporan)';
|
||||
|
||||
protected static ?int $sort = 10;
|
||||
|
||||
protected int|string|array $columnSpan = 1;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Report::query()
|
||||
->select(
|
||||
DB::raw('COUNT(*) as count'),
|
||||
DB::raw('status'),
|
||||
DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month")
|
||||
)
|
||||
->where('created_at', '>=', now()->subMonths(6))
|
||||
->groupBy('month', 'status')
|
||||
->orderBy('month')
|
||||
->get();
|
||||
|
||||
$months = $data->pluck('month')->unique()->sort()->values();
|
||||
|
||||
$acceptedData = [];
|
||||
$pendingData = [];
|
||||
$rejectedData = [];
|
||||
|
||||
foreach ($months as $month) {
|
||||
$acceptedData[] = $data->where('month', $month)->where('status', ApprovalStatus::ACCEPTED)->first()?->count ?? 0;
|
||||
$pendingData[] = $data->where('month', $month)->where('status', ApprovalStatus::PENDING)->first()?->count ?? 0;
|
||||
$rejectedData[] = $data->where('month', $month)->where('status', ApprovalStatus::REJECTED)->first()?->count ?? 0;
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Disetujui',
|
||||
'data' => $acceptedData,
|
||||
'backgroundColor' => '#10B981',
|
||||
],
|
||||
[
|
||||
'label' => 'Menunggu',
|
||||
'data' => $pendingData,
|
||||
'backgroundColor' => '#F59E0B',
|
||||
],
|
||||
[
|
||||
'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