38438-vm/employee_detail.php
2026-02-15 02:14:10 +00:00

122 lines
5.2 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$id = $_GET['id'] ?? null;
if (!$id) {
header('Location: employees.php');
exit;
}
$db = db();
$employee = $db->prepare("SELECT * FROM employees WHERE id = ?");
$employee->execute([$id]);
$employee = $employee->fetch();
if (!$employee) {
die("Employee not found.");
}
$pageTitle = "Employee Detail: " . htmlspecialchars($employee['name']);
include __DIR__ . '/includes/header.php';
// Fetch recent labour entries
$stmt = $db->prepare("
SELECT l.*, p.name as project_name, lt.name as labour_type
FROM labour_entries l
JOIN projects p ON l.project_id = p.id
JOIN labour_types lt ON l.labour_type_id = lt.id
WHERE l.employee_id = ?
ORDER BY l.entry_date DESC
LIMIT 20
");
$stmt->execute([$id]);
$entries = $stmt->fetchAll();
// Fetch summary stats
$stats = $db->prepare("SELECT SUM(hours) as total_hours, COUNT(*) as entry_count FROM labour_entries WHERE employee_id = ?");
$stats->execute([$id]);
$stats = $stats->fetch();
?>
<div class="container-fluid py-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-1">
<li class="breadcrumb-item"><a href="employees.php text-decoration-none">Employees</a></li>
<li class="breadcrumb-item active" aria-current="page"><?= htmlspecialchars($employee['name']) ?></li>
</ol>
</nav>
<h1 class="h3 mb-0"><?= htmlspecialchars($employee['name']) ?></h1>
<p class="text-muted"><?= htmlspecialchars($employee['position'] ?? 'Staff') ?></p>
</div>
<div class="d-flex gap-2">
<button class="btn btn-outline-primary btn-sm"><i class="bi bi-pencil me-1"></i> Edit Employee</button>
</div>
</div>
<div class="row g-4">
<div class="col-md-3">
<div class="card h-100">
<div class="card-header">Information</div>
<div class="card-body">
<div class="mb-3">
<label class="small text-muted d-block">Email</label>
<span><?= htmlspecialchars($employee['email'] ?? 'N/A') ?></span>
</div>
<div class="mb-3">
<label class="small text-muted d-block">Start Date</label>
<span><?= $employee['start_date'] ? date('M j, Y', strtotime($employee['start_date'])) : 'N/A' ?></span>
</div>
<div class="mb-0">
<label class="small text-muted d-block">Total Hours Logged</label>
<span class="fs-4 fw-bold text-primary"><?= number_format($stats['total_hours'] ?? 0, 1) ?></span>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<span>Recent Labour Entries</span>
<a href="labour.php?employee_id=<?= $id ?>" class="btn btn-sm btn-link text-decoration-none">View All</a>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Date</th>
<th>Project</th>
<th>Type</th>
<th>Hours</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php if (empty($entries)): ?>
<tr>
<td colspan="5" class="text-center py-4 text-muted">No entries found for this employee.</td>
</tr>
<?php else: ?>
<?php foreach ($entries as $e): ?>
<tr>
<td><?= date('Y-m-d', strtotime($e['entry_date'])) ?></td>
<td><a href="project_detail.php?id=<?= $e['project_id'] ?>" class="text-decoration-none"><?= htmlspecialchars($e['project_name']) ?></a></td>
<td><?= htmlspecialchars($e['labour_type']) ?></td>
<td class="fw-bold text-primary"><?= number_format($e['hours'], 1) ?></td>
<td class="text-muted small"><?= htmlspecialchars(substr($e['notes'], 0, 50)) ?><?= strlen($e['notes']) > 50 ? '...' : '' ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>