Revert to version 5914657
This commit is contained in:
parent
c20fbe80f7
commit
8cc026eb96
@ -8,61 +8,36 @@ if (function_exists('require_permission')) {
|
|||||||
|
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
$tab = $_GET['tab'] ?? 'staff';
|
$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
|
// Fetch Staff summary stats
|
||||||
$summaryQuery = "
|
$summaryStmt = $pdo->query("
|
||||||
SELECT u.id, u.full_name, u.username, u.profile_pic,
|
SELECT u.id, u.full_name, u.username, u.profile_pic,
|
||||||
AVG(r.rating) as avg_rating, COUNT(r.id) as total_ratings
|
AVG(r.rating) as avg_rating, COUNT(r.id) as total_ratings
|
||||||
FROM users u
|
FROM users u
|
||||||
JOIN staff_ratings r ON u.id = r.user_id
|
JOIN staff_ratings r ON u.id = r.user_id
|
||||||
WHERE 1=1 $where_staff
|
|
||||||
GROUP BY u.id
|
GROUP BY u.id
|
||||||
ORDER BY avg_rating DESC
|
ORDER BY avg_rating DESC
|
||||||
";
|
");
|
||||||
$summaryStmt = $pdo->prepare($summaryQuery);
|
|
||||||
$summaryStmt->execute($params);
|
|
||||||
$summaries = $summaryStmt->fetchAll(PDO::FETCH_ASSOC);
|
$summaries = $summaryStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
// Fetch Service summary stats
|
// Fetch Service summary stats
|
||||||
$serviceSummaryQuery = "
|
$serviceSummaryStmt = $pdo->query("
|
||||||
SELECT AVG(rating) as avg_rating, COUNT(id) as total_ratings
|
SELECT AVG(rating) as avg_rating, COUNT(id) as total_ratings FROM service_ratings
|
||||||
FROM service_ratings
|
");
|
||||||
WHERE 1=1 $where_service
|
|
||||||
";
|
|
||||||
$serviceSummaryStmt = $pdo->prepare($serviceSummaryQuery);
|
|
||||||
$serviceSummaryStmt->execute($params);
|
|
||||||
$serviceSummary = $serviceSummaryStmt->fetch(PDO::FETCH_ASSOC);
|
$serviceSummary = $serviceSummaryStmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($tab === 'service') {
|
if ($tab === 'service') {
|
||||||
$query = "SELECT * FROM service_ratings WHERE 1=1 $where_service ORDER BY created_at DESC";
|
$query = "SELECT * FROM service_ratings ORDER BY created_at DESC";
|
||||||
} else {
|
} else {
|
||||||
$query = "
|
$query = "
|
||||||
SELECT r.*, u.full_name, u.username, u.profile_pic
|
SELECT r.*, u.full_name, u.username, u.profile_pic
|
||||||
FROM staff_ratings r
|
FROM staff_ratings r
|
||||||
JOIN users u ON r.user_id = u.id
|
JOIN users u ON r.user_id = u.id
|
||||||
WHERE 1=1 $where_staff
|
|
||||||
ORDER BY r.created_at DESC
|
ORDER BY r.created_at DESC
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
$pagination = paginate_query($pdo, $query, $params);
|
$pagination = paginate_query($pdo, $query);
|
||||||
$ratings = $pagination['data'];
|
$ratings = $pagination['data'];
|
||||||
?>
|
?>
|
||||||
|
|
||||||
@ -78,41 +53,14 @@ $ratings = $pagination['data'];
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<ul class="nav nav-pills mb-4 bg-white p-2 rounded-4 shadow-sm d-inline-flex">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link rounded-pill <?= $tab === 'staff' ? 'active' : '' ?>" href="?tab=staff&start_date=<?= $start_date ?>&end_date=<?= $end_date ?>">
|
<a class="nav-link rounded-pill <?= $tab === 'staff' ? 'active' : '' ?>" href="?tab=staff">
|
||||||
<i class="bi bi-people me-1"></i> Staff Performance
|
<i class="bi bi-people me-1"></i> Staff Performance
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link rounded-pill <?= $tab === 'service' ? 'active' : '' ?>" href="?tab=service&start_date=<?= $start_date ?>&end_date=<?= $end_date ?>">
|
<a class="nav-link rounded-pill <?= $tab === 'service' ? 'active' : '' ?>" href="?tab=service">
|
||||||
<i class="bi bi-shop me-1"></i> Restaurant Service
|
<i class="bi bi-shop me-1"></i> Restaurant Service
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@ -123,7 +71,7 @@ $ratings = $pagination['data'];
|
|||||||
<?php if (empty($summaries)): ?>
|
<?php if (empty($summaries)): ?>
|
||||||
<div class="alert alert-info border-0 shadow-sm rounded-4 text-center py-4 mb-5">
|
<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>
|
<i class="bi bi-info-circle fs-2 mb-2"></i>
|
||||||
<p class="mb-0">No staff members have been rated yet within this period.</p>
|
<p class="mb-0">No staff members have been rated yet.</p>
|
||||||
</div>
|
</div>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<div class="row g-4 mb-5">
|
<div class="row g-4 mb-5">
|
||||||
@ -199,7 +147,7 @@ $ratings = $pagination['data'];
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php if (empty($ratings)): ?>
|
<?php if (empty($ratings)): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="<?= $tab === 'staff' ? 4 : 3 ?>" class="text-center py-4 text-muted">No ratings found within this period.</td>
|
<td colspan="<?= $tab === 'staff' ? 4 : 3 ?>" class="text-center py-4 text-muted">No ratings found yet.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php foreach ($ratings as $rating): ?>
|
<?php foreach ($ratings as $rating): ?>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user