160 lines
7.5 KiB
PHP
160 lines
7.5 KiB
PHP
<?php
|
|
require_once 'includes/helpers.php';
|
|
$user = getCurrentUser();
|
|
$company_id = $user['company_id'];
|
|
$job_id = $_GET['id'] ?? null;
|
|
|
|
if (!$job_id) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
// Fetch Job
|
|
$stmt = db()->prepare("SELECT j.*, s.name as status_name, c.name as client_name
|
|
FROM jobs j
|
|
LEFT JOIN job_statuses s ON j.status_id = s.id
|
|
LEFT JOIN clients c ON j.client_id = c.id
|
|
WHERE j.id = ? AND j.company_id = ?");
|
|
$stmt->execute([$job_id, $company_id]);
|
|
$job = $stmt->fetch();
|
|
|
|
if (!$job) {
|
|
die("Job not found.");
|
|
}
|
|
|
|
// Handle Updates
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['action']) && $_POST['action'] === 'toggle_approved') {
|
|
$new_val = $job['works_approved'] ? 0 : 1;
|
|
$stmt = db()->prepare("UPDATE jobs SET works_approved = ? WHERE id = ?");
|
|
$stmt->execute([$new_val, $job_id]);
|
|
|
|
logActivity($job_id, 'works_approved_toggle', 'works_approved', $job['works_approved'] ? 'True' : 'False', $new_val ? 'True' : 'False');
|
|
|
|
header("Location: job_detail.php?id=" . $job_id);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Fetch Logs
|
|
$logStmt = db()->prepare("SELECT * FROM activity_logs WHERE job_id = ? ORDER BY created_at DESC");
|
|
$logStmt->execute([$job_id]);
|
|
$logs = $logStmt->fetchAll();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Job Detail - <?php echo htmlspecialchars($job['job_ref']); ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg py-3">
|
|
<div class="container">
|
|
<a class="navbar-brand fw-bold" href="index.php">Repairs Pro</a>
|
|
<div class="d-flex align-items-center">
|
|
<a href="index.php" class="btn btn-light btn-sm me-2">Back to Dashboard</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container py-5">
|
|
<div class="row">
|
|
<div class="col-lg-8">
|
|
<div class="card p-4 mb-4">
|
|
<div class="d-flex justify-content-between align-items-start mb-4">
|
|
<div>
|
|
<span class="text-secondary text-uppercase small fw-bold">Job Reference</span>
|
|
<h1 class="h3 fw-bold"><?php echo htmlspecialchars($job['job_ref']); ?></h1>
|
|
</div>
|
|
<div class="text-end">
|
|
<span class="badge bg-light text-dark border p-2 px-3"><?php echo htmlspecialchars($job['status_name']); ?></span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-4">
|
|
<div class="col-md-6">
|
|
<label class="text-secondary small">Client</label>
|
|
<div class="fw-medium"><?php echo htmlspecialchars($job['client_name']); ?></div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="text-secondary small">Created At</label>
|
|
<div class="fw-medium"><?php echo date('d M Y, H:i', strtotime($job['created_at'])); ?></div>
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="text-secondary small">Address</label>
|
|
<div class="fw-medium"><?php echo htmlspecialchars($job['address_1'] ?: 'N/A'); ?></div>
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="text-secondary small">Description</label>
|
|
<div class="p-3 bg-light border-start border-primary border-4 rounded-1">
|
|
<?php echo nl2br(htmlspecialchars($job['description'] ?: 'No description provided.')); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<hr class="my-4">
|
|
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h5 class="m-0 fw-bold">Works Approved</h5>
|
|
<p class="text-secondary small m-0">Toggle this when the scope of work is confirmed.</p>
|
|
</div>
|
|
<form method="POST">
|
|
<input type="hidden" name="action" value="toggle_approved">
|
|
<button type="submit" class="btn <?php echo $job['works_approved'] ? 'btn-success' : 'btn-outline-secondary'; ?>">
|
|
<?php echo $job['works_approved'] ? 'Approved' : 'Mark as Approved'; ?>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-4">
|
|
<div class="card">
|
|
<div class="card-header bg-white py-3">
|
|
<h5 class="m-0 fw-bold">Activity Log</h5>
|
|
</div>
|
|
<div class="activity-log">
|
|
<?php foreach ($logs as $log): ?>
|
|
<div class="log-entry">
|
|
<div class="d-flex justify-content-between mb-1">
|
|
<span class="fw-bold"><?php echo htmlspecialchars($log['user_name']); ?></span>
|
|
<span class="text-secondary x-small"><?php echo date('H:i', strtotime($log['created_at'])); ?></span>
|
|
</div>
|
|
<div class="text-primary small mb-1">
|
|
<?php
|
|
switch($log['event_type']) {
|
|
case 'job_created': echo "Created the job"; break;
|
|
case 'works_approved_toggle': echo "Updated 'Works Approved' status"; break;
|
|
default: echo htmlspecialchars($log['event_type']);
|
|
}
|
|
?>
|
|
</div>
|
|
<?php if ($log['field_name']): ?>
|
|
<div class="text-secondary" style="font-size: 0.75rem;">
|
|
<span class="text-decoration-line-through"><?php echo htmlspecialchars($log['old_value']); ?></span>
|
|
→
|
|
<span class="fw-medium"><?php echo htmlspecialchars($log['new_value']); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="text-muted mt-1" style="font-size: 0.7rem;">
|
|
<?php echo date('d M Y', strtotime($log['created_at'])); ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; if (empty($logs)): ?>
|
|
<div class="p-4 text-center text-secondary">No activity yet.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|