188 lines
7.8 KiB
PHP
188 lines
7.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$id = $_GET['id'] ?? null;
|
|
if (!$id) {
|
|
header('Location: projects.php');
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
$project = $db->prepare("SELECT * FROM projects WHERE id = ?");
|
|
$project->execute([$id]);
|
|
$project = $project->fetch();
|
|
|
|
if (!$project) {
|
|
die("Project not found.");
|
|
}
|
|
|
|
$pageTitle = "Project Detail: " . htmlspecialchars($project['name']);
|
|
include __DIR__ . '/includes/header.php';
|
|
|
|
// Fetch recent labour
|
|
$labourStmt = $db->prepare("
|
|
SELECT l.*, e.name as employee_name, lt.name as labour_type
|
|
FROM labour_entries l
|
|
JOIN employees e ON l.employee_id = e.id
|
|
JOIN labour_types lt ON l.labour_type_id = lt.id
|
|
WHERE l.project_id = ?
|
|
ORDER BY l.entry_date DESC
|
|
LIMIT 10
|
|
");
|
|
$labourStmt->execute([$id]);
|
|
$labourEntries = $labourStmt->fetchAll();
|
|
|
|
// Fetch recent expenses
|
|
$expenseStmt = $db->prepare("
|
|
SELECT ex.*, et.name as expense_type, s.name as supplier_name
|
|
FROM expenses ex
|
|
JOIN expense_types et ON ex.expense_type_id = et.id
|
|
LEFT JOIN suppliers s ON ex.supplier_id = s.id
|
|
WHERE ex.project_id = ?
|
|
ORDER BY ex.entry_date DESC
|
|
LIMIT 10
|
|
");
|
|
$expenseStmt->execute([$id]);
|
|
$expenseEntries = $expenseStmt->fetchAll();
|
|
|
|
// Stats
|
|
$statsStmt = $db->prepare("
|
|
SELECT
|
|
(SELECT SUM(hours) FROM labour_entries WHERE project_id = ?) as total_hours,
|
|
(SELECT SUM(amount) FROM expenses WHERE project_id = ?) as total_expenses
|
|
");
|
|
$statsStmt->execute([$id, $id]);
|
|
$stats = $statsStmt->fetch();
|
|
|
|
?>
|
|
|
|
<div class="container-fluid py-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<div>
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb mb-1">
|
|
<li class="breadcrumb-item"><a href="projects.php" class="text-decoration-none">Projects</a></li>
|
|
<li class="breadcrumb-item active" aria-current="page"><?= htmlspecialchars($project['name']) ?></li>
|
|
</ol>
|
|
</nav>
|
|
<h1 class="h3 mb-0"><?= htmlspecialchars($project['name']) ?> (<?= htmlspecialchars($project['code']) ?>)</h1>
|
|
<span class="badge status-<?= $project['status'] ?>"><?= ucfirst($project['status']) ?></span>
|
|
<?php if ($project['is_archived']): ?>
|
|
<span class="badge bg-secondary">Archived</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div>
|
|
<?php if ($project['is_archived']): ?>
|
|
<a href="projects.php?unarchive=<?= $id ?>" class="btn btn-outline-success btn-sm me-2" onclick="return confirm('Unarchive this project?')"><i class="bi bi-arrow-up-circle me-1"></i> Unarchive</a>
|
|
<?php else: ?>
|
|
<a href="projects.php?archive=<?= $id ?>" class="btn btn-outline-danger btn-sm me-2" onclick="return confirm('Archive this project?')"><i class="bi bi-archive me-1"></i> Archive Project</a>
|
|
<?php endif; ?>
|
|
<button class="btn btn-outline-primary btn-sm me-2"><i class="bi bi-pencil me-1"></i> Edit Project</button>
|
|
<?php if (!$project['is_archived']): ?>
|
|
<a href="labour.php?project_id=<?= $id ?>" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i> Add Labour</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-4 mb-4">
|
|
<div class="col-md-3">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<h6 class="text-muted mb-2">Total Hours</h6>
|
|
<h3 class="mb-0 text-primary"><?= number_format($stats['total_hours'] ?? 0, 1) ?></h3>
|
|
<small class="text-muted">Budget: <?= number_format($project['estimated_hours'] ?? 0) ?></small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<h6 class="text-muted mb-2">Total Expenses</h6>
|
|
<h3 class="mb-0 text-success">$<?= number_format($stats['total_expenses'] ?? 0, 2) ?></h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<h6 class="text-muted mb-2">Type</h6>
|
|
<h3 class="mb-0 text-dark"><?= $project['type'] ?></h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<h6 class="text-muted mb-2">Start Date</h6>
|
|
<h3 class="mb-0 text-dark"><?= date('M j, Y', strtotime($project['start_date'])) ?></h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-4">
|
|
<div class="col-md-6">
|
|
<div class="card h-100">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span>Recent Labour</span>
|
|
<a href="labour.php?project_id=<?= $id ?>" class="small text-decoration-none">View All</a>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-sm table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Employee</th>
|
|
<th>Hours</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($labourEntries as $le): ?>
|
|
<tr>
|
|
<td><?= date('Y-m-d', strtotime($le['entry_date'])) ?></td>
|
|
<td><?= htmlspecialchars($le['employee_name']) ?></td>
|
|
<td class="fw-bold text-primary"><?= number_format($le['hours'], 1) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="card h-100">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span>Recent Expenses</span>
|
|
<a href="expenses.php?project_id=<?= $id ?>" class="small text-decoration-none">View All</a>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-sm table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Type</th>
|
|
<th>Amount</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($expenseEntries as $ee): ?>
|
|
<tr>
|
|
<td><?= date('Y-m-d', strtotime($ee['entry_date'])) ?></td>
|
|
<td><?= htmlspecialchars($ee['expense_type']) ?></td>
|
|
<td class="fw-bold text-success">$<?= number_format($ee['amount'], 2) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|