Autosave: 20260223-175112
This commit is contained in:
parent
5914657321
commit
3f3fe5a7d5
@ -8,36 +8,61 @@ if (function_exists('require_permission')) {
|
||||
|
||||
$pdo = db();
|
||||
$tab = $_GET['tab'] ?? 'staff';
|
||||
$start_date = $_GET['start_date'] ?? '';
|
||||
$end_date = $_GET['end_date'] ?? '';
|
||||
|
||||
$where_staff = "";
|
||||
$where_service = "";
|
||||
$params = [];
|
||||
|
||||
if ($start_date) {
|
||||
$where_staff .= " AND r.created_at >= :start_date";
|
||||
$where_service .= " AND created_at >= :start_date";
|
||||
$params[':start_date'] = $start_date . ' 00:00:00';
|
||||
}
|
||||
if ($end_date) {
|
||||
$where_staff .= " AND r.created_at <= :end_date";
|
||||
$where_service .= " AND created_at <= :end_date";
|
||||
$params[':end_date'] = $end_date . ' 23:59:59';
|
||||
}
|
||||
|
||||
// Fetch Staff summary stats
|
||||
$summaryStmt = $pdo->query("
|
||||
$summaryQuery = "
|
||||
SELECT u.id, u.full_name, u.username, u.profile_pic,
|
||||
AVG(r.rating) as avg_rating, COUNT(r.id) as total_ratings
|
||||
FROM users u
|
||||
JOIN staff_ratings r ON u.id = r.user_id
|
||||
WHERE 1=1 $where_staff
|
||||
GROUP BY u.id
|
||||
ORDER BY avg_rating DESC
|
||||
");
|
||||
";
|
||||
$summaryStmt = $pdo->prepare($summaryQuery);
|
||||
$summaryStmt->execute($params);
|
||||
$summaries = $summaryStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Fetch Service summary stats
|
||||
$serviceSummaryStmt = $pdo->query("
|
||||
SELECT AVG(rating) as avg_rating, COUNT(id) as total_ratings FROM service_ratings
|
||||
");
|
||||
$serviceSummaryQuery = "
|
||||
SELECT AVG(rating) as avg_rating, COUNT(id) as total_ratings
|
||||
FROM service_ratings
|
||||
WHERE 1=1 $where_service
|
||||
";
|
||||
$serviceSummaryStmt = $pdo->prepare($serviceSummaryQuery);
|
||||
$serviceSummaryStmt->execute($params);
|
||||
$serviceSummary = $serviceSummaryStmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($tab === 'service') {
|
||||
$query = "SELECT * FROM service_ratings ORDER BY created_at DESC";
|
||||
$query = "SELECT * FROM service_ratings WHERE 1=1 $where_service ORDER BY created_at DESC";
|
||||
} else {
|
||||
$query = "
|
||||
SELECT r.*, u.full_name, u.username, u.profile_pic
|
||||
FROM staff_ratings r
|
||||
JOIN users u ON r.user_id = u.id
|
||||
WHERE 1=1 $where_staff
|
||||
ORDER BY r.created_at DESC
|
||||
";
|
||||
}
|
||||
|
||||
$pagination = paginate_query($pdo, $query);
|
||||
$pagination = paginate_query($pdo, $query, $params);
|
||||
$ratings = $pagination['data'];
|
||||
?>
|
||||
|
||||
@ -53,14 +78,41 @@ $ratings = $pagination['data'];
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filters Card -->
|
||||
<div class="card border-0 shadow-sm rounded-4 mb-4">
|
||||
<div class="card-body">
|
||||
<form method="GET" class="row g-3 align-items-end">
|
||||
<input type="hidden" name="tab" value="<?= htmlspecialchars($tab) ?>">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small fw-bold text-muted">Start Date</label>
|
||||
<input type="date" name="start_date" class="form-control" value="<?= htmlspecialchars($start_date) ?>">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small fw-bold text-muted">End Date</label>
|
||||
<input type="date" name="end_date" class="form-control" value="<?= htmlspecialchars($end_date) ?>">
|
||||
</div>
|
||||
<div class="col-md-4 d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary w-100 rounded-pill">
|
||||
<i class="bi bi-filter me-1"></i> Apply Filter
|
||||
</button>
|
||||
<?php if ($start_date || $end_date): ?>
|
||||
<a href="?tab=<?= $tab ?>" class="btn btn-light rounded-pill px-3">
|
||||
<i class="bi bi-x-circle"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-pills mb-4 bg-white p-2 rounded-4 shadow-sm d-inline-flex">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link rounded-pill <?= $tab === 'staff' ? 'active' : '' ?>" href="?tab=staff">
|
||||
<a class="nav-link rounded-pill <?= $tab === 'staff' ? 'active' : '' ?>" href="?tab=staff&start_date=<?= $start_date ?>&end_date=<?= $end_date ?>">
|
||||
<i class="bi bi-people me-1"></i> Staff Performance
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link rounded-pill <?= $tab === 'service' ? 'active' : '' ?>" href="?tab=service">
|
||||
<a class="nav-link rounded-pill <?= $tab === 'service' ? 'active' : '' ?>" href="?tab=service&start_date=<?= $start_date ?>&end_date=<?= $end_date ?>">
|
||||
<i class="bi bi-shop me-1"></i> Restaurant Service
|
||||
</a>
|
||||
</li>
|
||||
@ -71,7 +123,7 @@ $ratings = $pagination['data'];
|
||||
<?php if (empty($summaries)): ?>
|
||||
<div class="alert alert-info border-0 shadow-sm rounded-4 text-center py-4 mb-5">
|
||||
<i class="bi bi-info-circle fs-2 mb-2"></i>
|
||||
<p class="mb-0">No staff members have been rated yet.</p>
|
||||
<p class="mb-0">No staff members have been rated yet within this period.</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="row g-4 mb-5">
|
||||
@ -147,7 +199,7 @@ $ratings = $pagination['data'];
|
||||
<tbody>
|
||||
<?php if (empty($ratings)): ?>
|
||||
<tr>
|
||||
<td colspan="<?= $tab === 'staff' ? 4 : 3 ?>" class="text-center py-4 text-muted">No ratings found yet.</td>
|
||||
<td colspan="<?= $tab === 'staff' ? 4 : 3 ?>" class="text-center py-4 text-muted">No ratings found within this period.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($ratings as $rating): ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user