Initial commit
This commit is contained in:
76
app/Http/Controllers/AdminDashboardController.php
Normal file
76
app/Http/Controllers/AdminDashboardController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Member;
|
||||
use App\Models\MembershipPayment;
|
||||
use App\Models\FinanceDocument;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AdminDashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// Member statistics
|
||||
$totalMembers = Member::count();
|
||||
$activeMembers = Member::whereDate('membership_expires_at', '>=', now()->toDateString())->count();
|
||||
$expiredMembers = Member::where(function ($q) {
|
||||
$q->whereNull('membership_expires_at')
|
||||
->orWhereDate('membership_expires_at', '<', now()->toDateString());
|
||||
})->count();
|
||||
$expiringSoon = Member::whereBetween('membership_expires_at', [
|
||||
now()->toDateString(),
|
||||
now()->addDays(30)->toDateString()
|
||||
])->count();
|
||||
|
||||
// Payment statistics
|
||||
$totalPayments = MembershipPayment::count();
|
||||
$totalRevenue = MembershipPayment::sum('amount') ?? 0;
|
||||
$recentPayments = MembershipPayment::with('member')
|
||||
->orderByDesc('paid_at')
|
||||
->limit(5)
|
||||
->get();
|
||||
$paymentsThisMonth = MembershipPayment::whereYear('paid_at', now()->year)
|
||||
->whereMonth('paid_at', now()->month)
|
||||
->count();
|
||||
$revenueThisMonth = MembershipPayment::whereYear('paid_at', now()->year)
|
||||
->whereMonth('paid_at', now()->month)
|
||||
->sum('amount') ?? 0;
|
||||
|
||||
// Finance document statistics
|
||||
$pendingApprovals = FinanceDocument::where('status', '!=', FinanceDocument::STATUS_APPROVED_CHAIR)
|
||||
->where('status', '!=', FinanceDocument::STATUS_REJECTED)
|
||||
->count();
|
||||
$fullyApprovedDocs = FinanceDocument::where('status', FinanceDocument::STATUS_APPROVED_CHAIR)->count();
|
||||
$rejectedDocs = FinanceDocument::where('status', FinanceDocument::STATUS_REJECTED)->count();
|
||||
|
||||
// Documents pending user's approval
|
||||
$user = auth()->user();
|
||||
$myPendingApprovals = 0;
|
||||
if ($user->hasRole('cashier')) {
|
||||
$myPendingApprovals += FinanceDocument::where('status', FinanceDocument::STATUS_PENDING)->count();
|
||||
}
|
||||
if ($user->hasRole('accountant')) {
|
||||
$myPendingApprovals += FinanceDocument::where('status', FinanceDocument::STATUS_APPROVED_CASHIER)->count();
|
||||
}
|
||||
if ($user->hasRole('chair')) {
|
||||
$myPendingApprovals += FinanceDocument::where('status', FinanceDocument::STATUS_APPROVED_ACCOUNTANT)->count();
|
||||
}
|
||||
|
||||
return view('admin.dashboard.index', compact(
|
||||
'totalMembers',
|
||||
'activeMembers',
|
||||
'expiredMembers',
|
||||
'expiringSoon',
|
||||
'totalPayments',
|
||||
'totalRevenue',
|
||||
'recentPayments',
|
||||
'paymentsThisMonth',
|
||||
'revenueThisMonth',
|
||||
'pendingApprovals',
|
||||
'fullyApprovedDocs',
|
||||
'rejectedDocs',
|
||||
'myPendingApprovals'
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user