|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/emp.outerorbittech.in/admin/ | |
|
Path: /home2/outerorb/emp.outerorbittech.in/admin/report-attendance.php
Size: 10.54 KB
Permissions: 0666
<?php
require __DIR__ . '/../includes/helpers.php';
require_admin();
ensure_employees_table();
ensure_notifications_table();
$admin = current_admin();
$startDate = isset($_GET['start_date']) ? sanitize_text($_GET['start_date']) : date('Y-m-01');
$endDate = isset($_GET['end_date']) ? sanitize_text($_GET['end_date']) : date('Y-m-t');
$departmentFilter = isset($_GET['department']) ? sanitize_text($_GET['department']) : '';
$export = isset($_GET['export']) && $_GET['export'] === '1';
$departments = list_departments();
$attendanceData = get_attendance_report($startDate, $endDate, $departmentFilter ?: null);
if ($export) {
$csvHeaders = ['Employee Name', 'Email', 'Phone', 'Department', 'Days Present', 'Days on Leave', 'Total Days'];
$csvRows = [];
foreach ($attendanceData as $row) {
$csvRows[] = [
'employee_name' => $row['employee_name'],
'email' => $row['email'],
'phone' => $row['phone'],
'department' => $row['department'],
'days_present' => $row['days_present'],
'days_on_leave' => $row['days_on_leave'],
'total_days' => $row['total_days']
];
}
export_to_csv($csvHeaders, $csvRows, 'attendance_report');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Attendance Report - HRMS</title>
<link rel="stylesheet" href="../assets/css/style.css" />
<link rel="stylesheet" href="../assets/css/polish.css">
<script src="../assets/js/app.js"></script>
</head>
<body class="dashboard-layout">
<div class="app-wrapper">
<!-- SIDEBAR -->
<aside class="sidebar-wrapper" id="sidebar">
<div class="sidebar-header">
<div class="sidebar-logo">HR</div>
<div class="sidebar-company">
<div class="sidebar-company-name">Attendance<br/>Report</div>
<div class="sidebar-company-role">Admin</div>
</div>
</div>
<nav class="sidebar-menu">
<div class="sidebar-section">
<div class="sidebar-section-title">๐ Reports</div>
<div class="sidebar-item">
<a href="reports.php" class="sidebar-link">๐ Overview</a>
</div>
<div class="sidebar-item">
<a href="report-attendance.php" class="sidebar-link active">โ๏ธ Attendance</a>
</div>
<div class="sidebar-item">
<a href="report-payroll.php" class="sidebar-link">๐ฐ Payroll</a>
</div>
<div class="sidebar-item">
<a href="report-leave.php" class="sidebar-link">๐ด Leave</a>
</div>
</div>
</nav>
</aside>
<!-- MAIN CONTENT -->
<div class="main-content">
<!-- Top Bar -->
<div class="top-bar">
<div class="top-bar-left">
<button class="sidebar-toggle" id="sidebarToggle" aria-label="Toggle sidebar">รขหยฐ</button>
<div>
<h1 class="page-title">Attendance Report</h1>
<div class="breadcrumb-nav">
<span>Reports</span> / <span>Attendance</span>
</div>
</div>
</div>
<div class="top-bar-right">
<button class="notification-bell" title="Notifications">
<i class="fas fa-bell"></i>
<?php
$unreadCount = get_unread_notification_count($admin['id']);
if ($unreadCount > 0):
?>
<span class="notification-badge"><?php echo $unreadCount; ?></span>
<?php endif; ?>
</button>
<a href="logout.php" style="color: #cbd5e1; text-decoration: none; padding: 8px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;">รขโ ย Logout</a>
</div>
</div>
<!-- Main Content -->
<div class="dashboard-container">
<!-- Filters -->
<div class="chart-card" style="margin-bottom: 20px;">
<form method="get" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;">
<div>
<label style="font-size: 12px; color: #9ca3af; display: block; margin-bottom: 4px;">Start Date</label>
<input type="date" name="start_date" value="<?php echo htmlspecialchars($startDate, ENT_QUOTES, 'UTF-8'); ?>" style="width: 100%; padding: 8px; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; background: rgba(255,255,255,0.05); color: #e5e7eb;">
</div>
<div>
<label style="font-size: 12px; color: #9ca3af; display: block; margin-bottom: 4px;">End Date</label>
<input type="date" name="end_date" value="<?php echo htmlspecialchars($endDate, ENT_QUOTES, 'UTF-8'); ?>" style="width: 100%; padding: 8px; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; background: rgba(255,255,255,0.05); color: #e5e7eb;">
</div>
<div>
<label style="font-size: 12px; color: #9ca3af; display: block; margin-bottom: 4px;">Department</label>
<select name="department" style="width: 100%; padding: 8px; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; background: rgba(255,255,255,0.05); color: #e5e7eb;">
<option value="">All Departments</option>
<?php foreach ($departments as $dept): ?>
<option value="<?php echo htmlspecialchars($dept, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $departmentFilter === $dept ? 'selected' : ''; ?>><?php echo htmlspecialchars($dept, ENT_QUOTES, 'UTF-8'); ?></option>
<?php endforeach; ?>
</select>
</div>
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; align-items: flex-end;">
<button type="submit" style="background: #2563eb; color: white; padding: 8px 12px; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 13px;">Apply Filters</button>
<a href="report-export.php?report=attendance&type=excel&from_date=<?php echo $startDate; ?>&to_date=<?php echo $endDate; ?>" target="_blank" style="background: #059669; color: white; padding: 8px 12px; border-radius: 6px; text-decoration: none; text-align: center; font-weight: 600; font-size: 13px; display: block;">๐ Excel</a>
<a href="report-export.php?report=attendance&type=pdf&from_date=<?php echo $startDate; ?>&to_date=<?php echo $endDate; ?>" target="_blank" style="background: #dc2626; color: white; padding: 8px 12px; border-radius: 6px; text-decoration: none; text-align: center; font-weight: 600; font-size: 13px; display: block;">๐ PDF</a>
<a href="report-export.php?report=attendance&type=csv&from_date=<?php echo $startDate; ?>&to_date=<?php echo $endDate; ?>" target="_blank" style="background: #7c3aed; color: white; padding: 8px 12px; border-radius: 6px; text-decoration: none; text-align: center; font-weight: 600; font-size: 13px; display: block;">๐ CSV</a>
</div>
</form>
</div>
<!-- Report Table -->
<div class="chart-card">
<div class="chart-header">Attendance Data (<?php echo $startDate; ?> to <?php echo $endDate; ?>)</div>
<div class="table-wrapper">
<table class="table">
<thead>
<tr>
<th>Employee Name</th>
<th>Email</th>
<th>Department</th>
<th class="cell-nowrap">Days Present</th>
<th class="cell-nowrap">Days on Leave</th>
<th class="cell-nowrap">Total Days</th>
<th class="cell-nowrap">Attendance %</th>
</tr>
</thead>
<tbody>
<?php if (empty($attendanceData)): ?>
<tr><td colspan="7" style="text-align: center; color: #9ca3af; padding: 32px;">No records found.</td></tr>
<?php else: foreach ($attendanceData as $emp):
$attendancePct = $emp['total_days'] > 0 ? round(($emp['days_present'] / $emp['total_days']) * 100, 1) : 0;
$statusColor = $attendancePct >= 80 ? '#10b981' : ($attendancePct >= 70 ? '#f59e0b' : '#ef4444');
?>
<tr>
<td><?php echo htmlspecialchars($emp['employee_name'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($emp['email'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlspecialchars($emp['department'] ?? 'N/A', ENT_QUOTES, 'UTF-8'); ?></td>
<td class="cell-nowrap"><?php echo (int)$emp['days_present']; ?></td>
<td class="cell-nowrap"><?php echo (int)$emp['days_on_leave']; ?></td>
<td class="cell-nowrap"><?php echo (int)$emp['total_days']; ?></td>
<td class="cell-nowrap" style="color: <?php echo $statusColor; ?>; font-weight: 600;"><?php echo $attendancePct; ?>%</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
const sidebar = document.getElementById('sidebar');
const sidebarToggle = document.getElementById('sidebarToggle');
sidebarToggle?.addEventListener('click', () => {
sidebar.classList.toggle('open');
});
document.addEventListener('click', (e) => {
if (!sidebar.contains(e.target) && !sidebarToggle.contains(e.target)) {
sidebar.classList.remove('open');
}
});
</script>
</body>
</html>