added dashboard view
This commit is contained in:
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user