2026-04-03 04:27:07 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
|
|
|
|
|
|
use App\Models\Activity;
|
|
|
|
|
use App\Models\CashRecord;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Filament\Widgets\StatsOverviewWidget;
|
|
|
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
|
|
|
|
|
|
class StatsOverview extends StatsOverviewWidget
|
|
|
|
|
{
|
|
|
|
|
protected function getStats(): array
|
|
|
|
|
{
|
2026-04-03 08:51:47 +07:00
|
|
|
$totalKas = CashRecord::whereNotNull('verified_at')
|
|
|
|
|
->join('cash_categories', 'cash_records.category_id', '=', 'cash_categories.id')
|
2026-04-03 04:27:07 +07:00
|
|
|
->selectRaw("SUM(CASE WHEN cash_categories.name = 'pemasukan' THEN amount ELSE -amount END) as saldo")
|
|
|
|
|
->value('saldo') ?? 0;
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
Stat::make('Anggota Aktif', User::where('status', 'aktif')->count())
|
|
|
|
|
->icon('heroicon-o-users')
|
|
|
|
|
->color('success'),
|
|
|
|
|
|
|
|
|
|
Stat::make('Total Kas', 'Rp ' . number_format($totalKas, 0, ',', '.'))
|
|
|
|
|
->icon('heroicon-o-banknotes')
|
|
|
|
|
->color($totalKas >= 0 ? 'success' : 'danger'),
|
|
|
|
|
|
|
|
|
|
Stat::make('Kegiatan Berjalan', Activity::where('status', 'approved')
|
|
|
|
|
->whereNull('executed_at')->count())
|
|
|
|
|
->icon('heroicon-o-calendar-days')
|
|
|
|
|
->color('info'),
|
|
|
|
|
|
|
|
|
|
Stat::make('Kegiatan Pending', Activity::where('status', 'pending')->count())
|
|
|
|
|
->icon('heroicon-o-clock')
|
|
|
|
|
->color('warning'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|