37762-vm/dashboard.php
2026-01-23 20:42:30 +00:00

83 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/auth.php';
requireLogin();
$pageTitle = "Dashboard";
$user = getCurrentUser();
$companyId = $user['company_id'];
// Fetch jobs for this company
$stmt = db()->prepare("
SELECT j.*, c.name as client_name, s.name as status_name
FROM jobs j
JOIN clients c ON j.client_id = c.id
JOIN job_statuses s ON j.status_id = s.id
WHERE j.company_id = ?
ORDER BY j.created_at DESC
");
$stmt->execute([$companyId]);
$jobs = $stmt->fetchAll();
require_once __DIR__ . '/includes/header.php';
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold m-0">Jobs Overview</h2>
<a href="create-job.php" class="btn btn-primary">
<i class="bi bi-plus-lg"></i> Create New Job
</a>
</div>
<?php if (empty($jobs)): ?>
<div class="card p-5 text-center">
<div class="mb-3">
<i class="bi bi-clipboard2-plus text-secondary display-1"></i>
</div>
<h4>No jobs found</h4>
<p class="text-secondary">Get started by creating your first repair job.</p>
<div class="mt-3">
<a href="create-job.php" class="btn btn-primary">Create First Job</a>
</div>
</div>
<?php else: ?>
<div class="card shadow-sm overflow-hidden">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th>Job ID</th>
<th>Client</th>
<th>Address</th>
<th>Status</th>
<th>UPRN</th>
<th>Created</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($jobs as $job): ?>
<tr>
<td>#<?= $job['id'] ?></td>
<td><?= htmlspecialchars($job['client_name']) ?></td>
<td><?= htmlspecialchars($job['address']) ?></td>
<td>
<span class="badge bg-secondary"><?= htmlspecialchars($job['status_name']) ?></span>
</td>
<td><?= htmlspecialchars($job['uprn'] ?? 'N/A') ?></td>
<td><?= date('d M Y', strtotime($job['created_at'])) ?></td>
<td class="text-end">
<a href="view-job.php?id=<?= $job['id'] ?>" class="btn btn-sm btn-outline-primary">View Details</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<?php require_once __DIR__ . '/includes/footer.php'; ?>