labour overhaul
This commit is contained in:
parent
33ad9419e5
commit
cb637ac2fc
45
api/search.php
Normal file
45
api/search.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
$q = $_GET['q'] ?? '';
|
||||
|
||||
if (strlen($q) < 2) {
|
||||
echo json_encode([]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
try {
|
||||
$db = db();
|
||||
|
||||
// Search Projects
|
||||
$stmt = $db->prepare("SELECT id, name, code FROM projects WHERE name LIKE ? OR code LIKE ? LIMIT 5");
|
||||
$stmt->execute(['%' . $q . '%', '%' . $q . '%']);
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$results[] = [
|
||||
'type' => 'Project',
|
||||
'id' => $row['id'],
|
||||
'label' => $row['name'] . ' (' . $row['code'] . ')',
|
||||
'url' => 'project_detail.php?id=' . $row['id']
|
||||
];
|
||||
}
|
||||
|
||||
// Search Employees
|
||||
$stmt = $db->prepare("SELECT id, name, position FROM employees WHERE name LIKE ? OR first_name LIKE ? OR last_name LIKE ? LIMIT 5");
|
||||
$stmt->execute(['%' . $q . '%', '%' . $q . '%', '%' . $q . '%']);
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$results[] = [
|
||||
'type' => 'Employee',
|
||||
'id' => $row['id'],
|
||||
'label' => $row['name'] . ' - ' . ($row['position'] ?? 'Staff'),
|
||||
'url' => 'employee_detail.php?id=' . $row['id']
|
||||
];
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
// Silence error for now
|
||||
}
|
||||
|
||||
echo json_encode($results);
|
||||
BIN
assets/pasted-20260215-020503-9ea6b62b.png
Normal file
BIN
assets/pasted-20260215-020503-9ea6b62b.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
121
employee_detail.php
Normal file
121
employee_detail.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?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'; ?>
|
||||
@ -75,10 +75,67 @@ $currentPage = basename($_SERVER['PHP_SELF']);
|
||||
<a class="nav-link <?= $currentPage === 'settings.php' ? 'active' : '' ?>" href="settings.php">Settings</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="d-flex align-items-center text-muted small">
|
||||
<span class="me-3">Tenant: <strong>Acme Research</strong></span>
|
||||
<span class="badge bg-light text-dark border">Global Admin</span>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="position-relative me-3" style="width: 250px;">
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text bg-white border-end-0"><i class="bi bi-search"></i></span>
|
||||
<input type="text" id="globalSearch" class="form-control border-start-0 ps-0" placeholder="Search projects or employees..." autocomplete="off">
|
||||
</div>
|
||||
<div id="searchResults" class="dropdown-menu w-100 mt-1 shadow-sm" style="display: none; max-height: 300px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center text-muted small">
|
||||
<span class="me-3">Tenant: <strong>Acme Research</strong></span>
|
||||
<span class="badge bg-light text-dark border">Global Admin</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchInput = document.getElementById('globalSearch');
|
||||
const searchResults = document.getElementById('searchResults');
|
||||
let debounceTimer;
|
||||
|
||||
searchInput.addEventListener('input', function() {
|
||||
clearTimeout(debounceTimer);
|
||||
const query = this.value.trim();
|
||||
|
||||
if (query.length < 2) {
|
||||
searchResults.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
debounceTimer = setTimeout(() => {
|
||||
fetch(`api/search.php?q=${encodeURIComponent(query)}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
searchResults.innerHTML = '';
|
||||
if (data.length > 0) {
|
||||
data.forEach(item => {
|
||||
const div = document.createElement('a');
|
||||
div.href = item.url;
|
||||
div.className = 'dropdown-item d-flex justify-content-between align-items-center';
|
||||
div.innerHTML = `
|
||||
<span>${item.label}</span>
|
||||
<span class="badge bg-light text-muted extra-small">${item.type}</span>
|
||||
`;
|
||||
searchResults.appendChild(div);
|
||||
});
|
||||
searchResults.style.display = 'block';
|
||||
} else {
|
||||
searchResults.innerHTML = '<div class="dropdown-item text-muted small">No results found</div>';
|
||||
searchResults.style.display = 'block';
|
||||
}
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
|
||||
document.addEventListener('click', function(e) {
|
||||
if (!searchInput.contains(e.target) && !searchResults.contains(e.target)) {
|
||||
searchResults.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
BIN
uploads/69912b6e657db.pdf
Normal file
BIN
uploads/69912b6e657db.pdf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user