112 lines
4.2 KiB
PHP
112 lines
4.2 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id']) || !in_array($_SESSION['role'], ['Admin', 'HR'])) {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
require_once 'db/config.php';
|
|
include 'sidebar.php';
|
|
|
|
// Fetch attendance data
|
|
$search_date = isset($_GET['search_date']) ? $_GET['search_date'] : '';
|
|
$search_name = isset($_GET['search_name']) ? $_GET['search_name'] : '';
|
|
|
|
$sql = "
|
|
SELECT a.id, e.name, a.status, a.date, a.check_in_time, a.check_out_time
|
|
FROM attendance a
|
|
JOIN employees e ON a.employee_id = e.id
|
|
";
|
|
|
|
$where_clauses = [];
|
|
$params = [];
|
|
|
|
if (!empty($search_date)) {
|
|
$where_clauses[] = "a.date = :date";
|
|
$params['date'] = $search_date;
|
|
}
|
|
|
|
if (!empty($search_name)) {
|
|
$where_clauses[] = "e.name LIKE :name";
|
|
$params['name'] = '%' . $search_name . '%';
|
|
}
|
|
|
|
if (!empty($where_clauses)) {
|
|
$sql .= " WHERE " . implode(' AND ', $where_clauses);
|
|
}
|
|
|
|
$stmt = db()->prepare($sql);
|
|
$stmt->execute($params);
|
|
$attendance_records = $stmt->fetchAll();
|
|
?>
|
|
|
|
<div class="container-fluid">
|
|
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
|
<h1 class="h3 mb-0 text-gray-800">This is the Attendance Report Page</h1>
|
|
</div>
|
|
|
|
<div class="card shadow mb-4">
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">Filter by Date</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="get" action="attendance_report.php">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-group">
|
|
<label for="search_date">Select Date</label>
|
|
<input type="date" class="form-control" id="search_date" name="search_date" value="<?= htmlspecialchars($search_date) ?>">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-group">
|
|
<label for="search_name">Employee Name</label>
|
|
<input type="text" class="form-control" id="search_name" name="search_name" placeholder="Enter employee name..." value="<?= isset($_GET['search_name']) ? htmlspecialchars($_GET['search_name']) : '' ?>">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Search</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow mb-4">
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">Attendance Records</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
|
|
<thead>
|
|
<tr>
|
|
<th>Employee Name</th>
|
|
<th>Status</th>
|
|
<th>Date</th>
|
|
<th>Check-in Time</th>
|
|
<th>Check-out Time</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($attendance_records)): ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center">No records found for this date.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($attendance_records as $record): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($record['name']) ?></td>
|
|
<td><?= htmlspecialchars($record['status']) ?></td>
|
|
<td><?= htmlspecialchars($record['date']) ?></td>
|
|
<td><?= htmlspecialchars($record['check_in_time']) ?></td>
|
|
<td><?= htmlspecialchars($record['check_out_time']) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|