From f53cc472bc80dd08357af265891fed1675d3d4cc Mon Sep 17 00:00:00 2001 From: Kwesi Banson Jnr Date: Fri, 21 Aug 2026 07:52:20 +0000 Subject: [PATCH] added dashboard view --- app/Http/Controllers/DashboardController.php | 118 +++++++- resources/views/dashboard/index.blade.php | 300 +++++++++++-------- resources/views/dashboard/index_hr.blade.php | 206 +++++++++++++ routes/web.php | 3 +- 4 files changed, 499 insertions(+), 128 deletions(-) create mode 100644 resources/views/dashboard/index_hr.blade.php 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') - -
-

Dashboard

-
- - - + + + + +
MNO & Client Insights
+ +
+ +
+
+ +

{{ $activeClients }}

+
ACTIVE CLIENTS
+
+ {{ $clientActiveRate }}% of Total Base +
+
+
+ + +
+
+ +

{{ $activeNetworks }}

+
MOBILE NETWORKS
+
Operational Status: Healthy
+
+
+ + +
+
+ +

{{ $activeShortCodes }}

+
PROVISIONED SHORT CODES
+
USSD | SMS | Voice
+
+
+ + +
+
+ +

{{ $totalSenderIds }}

+
APPROVED SENDER IDs
+
Live traffic
+
+
+
+ + +
+ +
+ Brief Summary: We are currently servicing {{ $activeClients }} active clients sending traffic through {{ $activeShortCodes }} USSD short codes and {{ $totalSenderIds }} SMS sender IDs across {{ $activeNetworks }} network operators. +
+
+ + + + + +
Internal Administration
+
-
-
-
-
SMS Clients
-
-
-

150

-
- +1.4% - quarter over quarter +
+
+
ACTIVE STAFF
+
+

{{ $totalStaff }}

+
-
-
-
-
USSD Clients
-
-
-

50

-
- 4 new clients - recent engagement result +
+
+
PENDING LEAVES
+
+

{{ $pendingLeaves }}

+
-
-
-
-
Voice Clients
-
-
-

10

-
- Darwin System - Newly Acquired
client
+
+
+
LEAVES THIS MONTH
+
+

{{ $activeLeavesThisMonth }}

+
-
-
-
-
Airtime Clients
-
-
-

15

-
- Healthy - Average bill secons: 3.5 mins +
+
+
ARCHIVED DOCS
+
+

{{ $totalDocuments }}

+
-
+ +
+
-
-
-
-
Revenue Projections Trend
-

Demonstrating visual charts using pure responsive vector layouts

-
-
- Sales Target - Prior Year -
+
+
+
Pending Leave Approvals
+ View All
-
- - - - - - +
+ + + + + + + + + + + @forelse($recentPendingLeaves as $leave) + + + + + + + @empty + + @endforelse + +
Staff MemberTypeDurationAction
{{ $leave->staff->name ?? 'Unknown' }}
{{ $leave->leave_type }}{{ $leave->start_date->format('M d') }} - {{ $leave->end_date->format('M d') }}Review
No pending leave requests.
+
+
+ +
+
+
Recently Uploaded Documents
+ View Archive +
+
+ + + @forelse($recentDocuments as $doc) + + + + + + @empty + + @endforelse + +
{{ $doc->name }}{{ $doc->category ?? 'General' }}{{ $doc->created_at ? $doc->created_at->format('M d, Y') : 'N/A' }}
No documents archived yet.
- + +
-
-
Department Distribution
-

Ratio of active records grouped by segment

- -
-
- Finance - 1 (25%) -
-
-
-
+
+
+
Upcoming Birthdays
- -
-
- Operations - 1 (25%) -
-
-
-
-
- -
-
- Sales - 1 (25%) -
-
-
-
-
- -
-
- Marketing - 0 (0%) -
-
-
-
+
+ @forelse($upcomingBirthdays as $staff) +
+
+
{{ $staff->name }}
+

{{ $staff->designation ?? 'Staff' }}

+
+
+ + {{ $staff->dob ? date('M d', strtotime('2024-' . $staff->dob)) : '' }} + +
+
+ @empty +
+ + No upcoming birthdays. +
+ @endforelse
- - @endsection \ No newline at end of file diff --git a/resources/views/dashboard/index_hr.blade.php b/resources/views/dashboard/index_hr.blade.php new file mode 100644 index 0000000..d6fdc1d --- /dev/null +++ b/resources/views/dashboard/index_hr.blade.php @@ -0,0 +1,206 @@ +@extends('layouts.masterbeta') + +@section('title', 'Click ERP - Dashboard') + +@section('breadcrumbs') + Dashboard Overview +@endsection + +@section('content') +
+

Welcome back, {{ auth()->user()->name ?? 'Administrator' }}!

+

Here is a summary of operational activity across your organization.

+
+ + + + +
Internal Administration
+ +
+
+
+
ACTIVE STAFF
+
+

{{ $totalStaff }}

+ +
+
+
+
+
+
PENDING LEAVES
+
+

{{ $pendingLeaves }}

+ +
+
+
+
+
+
LEAVES THIS MONTH
+
+

{{ $activeLeavesThisMonth }}

+ +
+
+
+
+
+
ARCHIVED DOCS
+
+

{{ $totalDocuments }}

+ +
+
+
+
+ +
+
+
+
+
Pending Leave Approvals
+ View All +
+
+ + + + + + + + + + + @forelse($recentPendingLeaves as $leave) + + + + + + + @empty + + @endforelse + +
Staff MemberTypeDurationAction
+
{{ $leave->staff->name ?? 'Unknown' }}
+
{{ $leave->leave_type }}{{ $leave->start_date->format('M d') }} - {{ $leave->end_date->format('M d') }} + Review +
No pending leave requests.
+
+
+
+
+
+
+
Upcoming Birthdays
+
+
+ @forelse($upcomingBirthdays as $staff) +
+
+
{{ $staff->name }}
+

{{ $staff->designation ?? 'Staff' }}

+
+
+ + {{ $staff->dob ? date('M d', strtotime('2024-' . $staff->dob)) : '' }} + +
+
+ @empty +
No upcoming birthdays.
+ @endforelse +
+
+
+
+ + + + +
Telecom & Client Operations
+ +
+ +
+
+
+
Active Clients & Networks
+ {{ $totalClients }} Clients +
+
+
+
INTEGRATED NETWORKS
+
+ @forelse($activeNetworks as $network) + {{ $network->name }} + @empty + No networks configured. + @endforelse +
+
+ +
+
RECENT CLIENTS
+
    + @forelse($recentClients as $client) +
  • + {{ $client->name }} + {{ $client->status ?? 'Active' }} +
  • + @empty +
  • No clients found.
  • + @endforelse +
+
+
+
+
+ + +
+
+
+
Provisioning Overview
+
+
+ +
+
+
ACTIVE SHORT CODES
+
+
+ @forelse($activeShortCodes as $code) + + *{{ $code->shortcode }}# + + @empty + No active short codes. + @endforelse +
+
+ + +
+
+
REGISTERED SENDER IDs
+
+
+ @forelse($activeSenderIds as $sender) + + {{ $sender->senderid }} + + @empty + No sender IDs configured. + @endforelse +
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index c44b3dc..5f9758e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,7 +13,8 @@ Auth::routes(); Route::middleware(['auth'])->group(function () { - Route::get('/', [App\Http\Controllers\DashboardController::class, 'index'])->name('home'); + + Route::get('/', [App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard'); Route::get('home', [App\Http\Controllers\DashboardController::class, 'index'])->name('home'); #Clients Route::get('/clients/data', [App\Http\Controllers\ClientsController::class, 'fetchData'])->name('clients.data');