177 lines
9.0 KiB
PHP
177 lines
9.0 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Filtering logic
|
|
$where_clauses = [];
|
|
$params = [];
|
|
|
|
if (!empty($_GET['service_type'])) {
|
|
$where_clauses[] = 'service_type = :service_type';
|
|
$params[':service_type'] = $_GET['service_type'];
|
|
}
|
|
if (!empty($_GET['urgency_level'])) {
|
|
$where_clauses[] = 'urgency_level = :urgency_level';
|
|
$params[':urgency_level'] = $_GET['urgency_level'];
|
|
}
|
|
if (!empty($_GET['status'])) {
|
|
$where_clauses[] = 'status = :status';
|
|
$params[':status'] = $_GET['status'];
|
|
}
|
|
|
|
$sql = 'SELECT * FROM bookings';
|
|
if (!empty($where_clauses)) {
|
|
$sql .= ' WHERE ' . implode(' AND ', $where_clauses);
|
|
}
|
|
$sql .= ' ORDER BY appointment_date DESC';
|
|
|
|
$stmt_bookings = $pdo->prepare($sql);
|
|
$stmt_bookings->execute($params);
|
|
$bookings = $stmt_bookings->fetchAll();
|
|
|
|
// Fetch distinct values for filters
|
|
$stmt_service_types = $pdo->query('SELECT DISTINCT service_type FROM bookings');
|
|
$service_types = $stmt_service_types->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
$stmt_urgency_levels = $pdo->query('SELECT DISTINCT urgency_level FROM bookings');
|
|
$urgency_levels = $stmt_urgency_levels->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
$stmt_statuses = $pdo->query('SELECT DISTINCT status FROM bookings');
|
|
$statuses = $stmt_statuses->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
$error = "Database error: " . $e->getMessage();
|
|
}
|
|
|
|
$project_name = "HVAC Command Center";
|
|
$page_title = "Bookings";
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title><?= htmlspecialchars($page_title) ?> | <?= htmlspecialchars($project_name) ?></title>
|
|
|
|
<!-- Styles -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
|
|
<!-- Fonts -->
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@700&family=Roboto:wght@400;500&display=swap" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="sidebar">
|
|
<div class="sidebar-header">
|
|
<h2 class="h5"><i class="fas fa-tachometer-alt me-2"></i><?= htmlspecialchars($project_name) ?></h2>
|
|
</div>
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item"><a class="nav-link" href="index.php"><i class="fas fa-home"></i>Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="customers.php"><i class="fas fa-users"></i>Customers</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="bookings.php"><i class="fas fa-calendar-check"></i>Bookings</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="ai-call-logs.php"><i class="fas fa-robot"></i>AI Call Logs</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="chat-logs.php"><i class="fas fa-comments"></i>Chat Logs</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="call-tracking.php"><i class="fas fa-phone-alt"></i>Call Tracking</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="reviews.php"><i class="fas fa-star"></i>Reviews</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="calendar.php"><i class="fas fa-calendar-alt"></i>Calendar</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1><?= htmlspecialchars($page_title) ?></h1>
|
|
</header>
|
|
|
|
<?php if (isset($error)): ?>
|
|
<div class="alert alert-danger">
|
|
<i class="fas fa-exclamation-triangle me-2"></i> <?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="m-0"><i class="fas fa-calendar-check me-2"></i>All Bookings</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="GET" action="" class="row g-3 mb-4">
|
|
<div class="col-md-3">
|
|
<select name="service_type" class="form-select bg-dark text-white">
|
|
<option value="">All Services</option>
|
|
<?php foreach ($service_types as $type): ?>
|
|
<option value="<?= htmlspecialchars($type) ?>" <?= (isset($_GET['service_type']) && $_GET['service_type'] == $type) ? 'selected' : '' ?>><?= htmlspecialchars(ucfirst($type)) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<select name="urgency_level" class="form-select bg-dark text-white">
|
|
<option value="">All Urgencies</option>
|
|
<?php foreach ($urgency_levels as $level): ?>
|
|
<option value="<?= htmlspecialchars($level) ?>" <?= (isset($_GET['urgency_level']) && $_GET['urgency_level'] == $level) ? 'selected' : '' ?>><?= htmlspecialchars(ucfirst($level)) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<select name="status" class="form-select bg-dark text-white">
|
|
<option value="">All Statuses</option>
|
|
<?php foreach ($statuses as $status): ?>
|
|
<option value="<?= htmlspecialchars($status) ?>" <?= (isset($_GET['status']) && $_GET['status'] == $status) ? 'selected' : '' ?>><?= htmlspecialchars(ucfirst($status)) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<button type="submit" class="btn btn-primary">Filter</button>
|
|
<a href="bookings.php" class="btn btn-secondary">Reset</a>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Customer</th>
|
|
<th>Service</th>
|
|
<th>Urgency</th>
|
|
<th>Status</th>
|
|
<th class="text-end">Est. Revenue</th>
|
|
<th class="text-end">Actual Revenue</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($bookings as $booking): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars(date("M d, Y", strtotime($booking['appointment_date']))) ?></td>
|
|
<td><?= htmlspecialchars($booking['customer_name']) ?></td>
|
|
<td><?= htmlspecialchars($booking['service_type']) ?></td>
|
|
<td><span class="badge bg-<?= strtolower(htmlspecialchars($booking['urgency_level'])) == 'emergency' ? 'danger' : (strtolower(htmlspecialchars($booking['urgency_level'])) == 'urgent' ? 'warning' : 'secondary') ?>"><?= htmlspecialchars(ucfirst($booking['urgency_level'])) ?></span></td>
|
|
<td><span class="badge bg-light text-dark border"><?= htmlspecialchars(ucfirst($booking['status'])) ?></span></td>
|
|
<td class="text-end fw-bold">$<?= number_format($booking['estimated_revenue'], 2) ?></td>
|
|
<td class="text-end fw-bold">$<?= number_format($booking['actual_revenue'], 2) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($bookings)): ?>
|
|
<tr>
|
|
<td colspan="7" class="text-center text-muted">No bookings found.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|