160 lines
7.3 KiB
PHP
160 lines
7.3 KiB
PHP
|
|
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
|
header('location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
$pdo = db();
|
|
$today = date('Y-m-d');
|
|
|
|
// Fetch total employees
|
|
$stmt_total = $pdo->query('SELECT COUNT(*) FROM users');
|
|
$total_employees = $stmt_total->fetchColumn();
|
|
|
|
// Fetch attendance stats for today
|
|
$stmt_attendance = $pdo->prepare("SELECT status, COUNT(*) as count FROM attendance WHERE attendance_date = ? GROUP BY status");
|
|
$stmt_attendance->execute([$today]);
|
|
$attendance_stats = $stmt_attendance->fetchAll(PDO::FETCH_KEY_PAIR);
|
|
|
|
$on_time_today = $attendance_stats['Present'] ?? 0;
|
|
$late_today = $attendance_stats['Late'] ?? 0;
|
|
$absent_today = $attendance_stats['Absent'] ?? 0;
|
|
|
|
// Fetch pending leave requests for Admin/HR
|
|
$pending_leave_requests = 0;
|
|
if (in_array($_SESSION['role'], ['Admin', 'HR'])) {
|
|
$stmt_leave = $pdo->query("SELECT COUNT(*) FROM leave_requests WHERE status = 'pending'");
|
|
$pending_leave_requests = $stmt_leave->fetchColumn();
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Dashboard - Employee Attendance System</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
</head>
|
|
|
|
|
|
<div class="d-flex">
|
|
<?php include 'sidebar.php'; ?>
|
|
|
|
<div class="main-content flex-grow-1 p-4">
|
|
<div class="container-fluid">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
|
|
<p class="lead mb-0">Welcome, <strong><?php echo htmlspecialchars($_SESSION['username']); ?>!</strong></p>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<!-- Total Employees Card -->
|
|
<div class="col-xl-3 col-md-6 mb-4">
|
|
<div class="card border-left-primary shadow h-100 py-2">
|
|
<div class="card-body">
|
|
<div class="row no-gutters align-items-center">
|
|
<div class="col mr-2">
|
|
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total Employees</div>
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $total_employees; ?></div>
|
|
</div>
|
|
<div class="col-auto">
|
|
<i class="bi bi-people-fill h2 text-gray-300"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- On Time Today Card -->
|
|
<div class="col-xl-3 col-md-6 mb-4">
|
|
<div class="card border-left-success shadow h-100 py-2">
|
|
<div class="card-body">
|
|
<div class="row no-gutters align-items-center">
|
|
<div class="col mr-2">
|
|
<div class="text-xs font-weight-bold text-success text-uppercase mb-1">On Time Today</div>
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $on_time_today; ?></div>
|
|
</div>
|
|
<div class="col-auto">
|
|
<i class="bi bi-check-circle-fill h2 text-gray-300"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Late Today Card -->
|
|
<div class="col-xl-3 col-md-6 mb-4">
|
|
<div class="card border-left-warning shadow h-100 py-2">
|
|
<div class="card-body">
|
|
<div class="row no-gutters align-items-center">
|
|
<div class="col mr-2">
|
|
<div class="text-xs font-weight-bold text-warning text-uppercase mb-1">Late Today</div>
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $late_today; ?></div>
|
|
</div>
|
|
<div class="col-auto">
|
|
<i class="bi bi-exclamation-triangle-fill h2 text-gray-300"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Absent Today Card -->
|
|
<div class="col-xl-3 col-md-6 mb-4">
|
|
<div class="card border-left-danger shadow h-100 py-2">
|
|
<div class="card-body">
|
|
<div class="row no-gutters align-items-center">
|
|
<div class="col mr-2">
|
|
<div class="text-xs font-weight-bold text-danger text-uppercase mb-1">Absent Today</div>
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $absent_today; ?></div>
|
|
</div>
|
|
<div class="col-auto">
|
|
<i class="bi bi-x-circle-fill h2 text-gray-300"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php if (in_array($_SESSION['role'], ['Admin', 'HR'])): ?>
|
|
<div class="row">
|
|
<div class="col-xl-3 col-md-6 mb-4">
|
|
<div class="card border-left-info shadow h-100 py-2">
|
|
<a href="leave_requests.php" class="text-decoration-none">
|
|
<div class="card-body">
|
|
<div class="row no-gutters align-items-center">
|
|
<div class="col mr-2">
|
|
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">Pending Leave Requests</div>
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $pending_leave_requests; ?></div>
|
|
</div>
|
|
<div class="col-auto">
|
|
<i class="bi bi-calendar-plus-fill h2 text-gray-300"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<p>From here you can manage employees, track attendance, and generate reports.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|