diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 3cfc5ed..fb7fef8 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -8,17 +8,23 @@ use Illuminate\View\View; use Illuminate\Support\Facades\DB; use Carbon\Carbon; -// Explicitly import models for better readability and IDE support + use App\Models\Client; use App\Models\UserActivity; use App\Models\StaffMember; use App\Models\NationalHoliday; use App\Models\DailyQuote; -use App\Models\NetworkOps; +use App\Models\LeaveRequest; +use App\Models\GeneralDocument; + +use App\Models\NetworkOperator; +use App\Models\ShortCode; +use App\Models\SenderId; + class DashboardController extends Controller { - public function index(): View + public function indexOld(): View { // Grouped OR clauses inside a closure to prevent query bleeding $ussd_clients = Client::where(function ($query) { @@ -77,7 +83,113 @@ class DashboardController extends Controller 'upcoming_hodidays' => $upcoming_hodidays ]); } + public function index() + { + // --- 1. TELECOM & CLIENT INSIGHTS (Top Section) --- + $totalClients = Client::count(); + $activeClients = Client::where('status', 'Live')->count(); // Assuming you have a status column + $activeNetworks = NetworkOperator::where('connection_status', 'ACTIVE')->count(); + $activeShortCodes = ShortCode::where('status', 'LIVE')->count(); + $totalSenderIds = SenderId::where('status', 'LIKE', 'APPROVED%')->count(); + // Calculate a quick insight (e.g., percentage of active clients) + $clientActiveRate = $totalClients > 0 ? round(($activeClients / $totalClients) * 100) : 0; + + // --- 2. HR & INTERNAL METRICS (Bottom Section) --- + $totalStaff = StaffMember::where('status', 'ACTIVE')->count(); + $pendingLeaves = LeaveRequest::where('status', 'PENDING')->count(); + $totalDocuments = GeneralDocument::count(); + $activeLeavesThisMonth = LeaveRequest::where('status', 'APPROVED') + ->whereMonth('start_date', Carbon::now()->month) + ->count(); + + $recentPendingLeaves = LeaveRequest::with('staff')->where('status', 'PENDING')->orderBy('created_at', 'desc')->take(5)->get(); + $recentDocuments = GeneralDocument::with('uploader')->orderBy('created_at', 'desc')->take(5)->get(); + + // Upcoming Birthdays + $currentMonthDay = Carbon::now()->format('m-d'); + $futureMonthDay = Carbon::now()->addDays(30)->format('m-d'); + $upcomingBirthdays = StaffMember::where(function($query) use ($currentMonthDay, $futureMonthDay) { + if ($currentMonthDay <= $futureMonthDay) { + $query->whereBetween('dob', [$currentMonthDay, $futureMonthDay]); + } else { + $query->where('dob', '>=', $currentMonthDay)->orWhere('dob', '<=', $futureMonthDay); + } + })->orderBy('dob', 'asc')->take(5)->get(); + + return view('dashboard.index', compact( + 'totalClients', 'activeClients', 'activeNetworks', 'activeShortCodes', 'totalSenderIds', 'clientActiveRate', + 'totalStaff', 'pendingLeaves', 'totalDocuments', 'activeLeavesThisMonth', + 'recentPendingLeaves', 'recentDocuments', 'upcomingBirthdays' + )); + } + public function indexHr() + { + // 1. Key Metrics + $totalStaff = StaffMember::where('status', 'ACTIVE')->count(); + $pendingLeaves = LeaveRequest::where('status', 'PENDING')->count(); + $totalDocuments = GeneralDocument::count(); + + // Approved leaves happening this month + $activeLeavesThisMonth = LeaveRequest::where('status', 'APPROVED') + ->whereMonth('start_date', Carbon::now()->month) + ->count(); + + // 2. Pending Leave Requests for HR Action + $recentPendingLeaves = LeaveRequest::with('staff') + ->where('status', 'PENDING') + ->orderBy('created_at', 'desc') + ->take(5) + ->get(); + + // 3. Recently Uploaded Documents + $recentDocuments = GeneralDocument::with('uploader') + ->orderBy('created_at', 'desc') + ->take(5) + ->get(); + + // 4. Upcoming Birthdays (Using our MM-DD string format logic) + $currentMonthDay = Carbon::now()->format('m-d'); + $futureMonthDay = Carbon::now()->addDays(30)->format('m-d'); + + if ($currentMonthDay <= $futureMonthDay) { + $upcomingBirthdays = StaffMember::whereBetween('dob', [$currentMonthDay, $futureMonthDay]) + ->orderBy('dob', 'asc') + ->take(5) + ->get(); + } else { + $upcomingBirthdays = StaffMember::where(function($query) use ($currentMonthDay, $futureMonthDay) { + $query->where('dob', '>=', $currentMonthDay) + ->orWhere('dob', '<=', $futureMonthDay); + }) + ->orderBy('dob', 'asc') + ->take(5) + ->get(); + } + + $totalClients = Client::count(); // Or where('status', 'ACTIVE') + $totalNetworks = NetworkOperator::count(); + + $recentClients = Client::orderBy('created_at', 'desc')->take(5)->get(); + $activeNetworks = NetworkOperator::where('connection_status', 'ACTIVE')->get(); + $activeShortCodes = ShortCode::where('status', 'ACTIVE')->get(); + $activeSenderIds = SenderId::where('status', 'ACTIVE')->get(); + return view('dashboard.index', compact( + 'totalStaff', 'pendingLeaves', 'totalDocuments', 'activeLeavesThisMonth', + 'recentPendingLeaves', 'recentDocuments', 'upcomingBirthdays', + 'totalClients', 'totalNetworks', 'recentClients', 'activeNetworks', 'activeShortCodes', 'activeSenderIds' + )); + + return view('dashboard.index', compact( + 'totalStaff', + 'pendingLeaves', + 'totalDocuments', + 'activeLeavesThisMonth', + 'recentPendingLeaves', + 'recentDocuments', + 'upcomingBirthdays' + )); + } public function getEvents(): JsonResponse { $event_arr = [ diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 3391f41..c2ef073 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -1,157 +1,209 @@ -@extends('layouts.master') +@extends('layouts.masterbeta') -@section('title', 'Dashboard') +@section('title', 'Click ERP - Dashboard') + +@section('breadcrumbs') + Main Dashboard +@endsection @section('content') - -
- - - + + + + +Demonstrating visual charts using pure responsive vector layouts
-| Staff Member | +Type | +Duration | +Action | +
|---|---|---|---|
{{ $leave->staff->name ?? 'Unknown' }} |
+ {{ $leave->leave_type }} | +{{ $leave->start_date->format('M d') }} - {{ $leave->end_date->format('M d') }} | +Review | +
| No pending leave requests. | |||
| {{ $doc->name }} | +{{ $doc->category ?? 'General' }} | +{{ $doc->created_at ? $doc->created_at->format('M d, Y') : 'N/A' }} | +
| No documents archived yet. | ||
Ratio of active records grouped by segment
- -{{ $staff->designation ?? 'Staff' }}
+Here is a summary of operational activity across your organization.
+| Staff Member | +Type | +Duration | +Action | +
|---|---|---|---|
|
+ {{ $leave->staff->name ?? 'Unknown' }}
+ |
+ {{ $leave->leave_type }} | +{{ $leave->start_date->format('M d') }} - {{ $leave->end_date->format('M d') }} | ++ Review + | +
| No pending leave requests. | |||
{{ $staff->designation ?? 'Staff' }}
+