147 lines
7.4 KiB
PHP
147 lines
7.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$project_id = $_GET['id'] ?? null;
|
|
$project_name = '';
|
|
$financial_data = [];
|
|
|
|
if ($project_id) {
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Fetch project name
|
|
$stmt = $pdo->prepare("SELECT name FROM projects WHERE id = :id");
|
|
$stmt->execute([':id' => $project_id]);
|
|
$project_name = $stmt->fetchColumn();
|
|
|
|
// Fetch financial data
|
|
$stmt = $pdo->prepare("SELECT * FROM projectFinanceMonthly WHERE projectId = :pid ORDER BY month");
|
|
$stmt->execute([':pid' => $project_id]);
|
|
$financial_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (PDOException $e) {
|
|
$db_error = "Database error: " . $e->getMessage();
|
|
}
|
|
} else {
|
|
$page_title = "Project ID not provided";
|
|
}
|
|
|
|
$page_title = $project_name ? "Financial Data for " . htmlspecialchars($project_name) : "Project Not Found";
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en" data-bs-theme="dark">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo $page_title; ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
<div class="top-navbar">
|
|
Project Financials
|
|
</div>
|
|
<div class="main-wrapper">
|
|
<nav class="sidebar">
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item"><a class="nav-link" href="roster.php"><i class="bi bi-people-fill me-2"></i>Roster</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="projects.php"><i class="bi bi-briefcase-fill me-2"></i>Projects</a></li>
|
|
</ul>
|
|
</nav>
|
|
|
|
<main class="content-wrapper">
|
|
<div class="page-header">
|
|
<h1 class="h2"><?php echo $page_title; ?></h1>
|
|
<div class="header-actions">
|
|
<a href="project_details.php?id=<?php echo htmlspecialchars($project_id); ?>" class="btn btn-secondary"><i class="bi bi-arrow-left-circle-fill me-2"></i>Back to Project</a>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<?php if (isset($db_error)): ?>
|
|
<div class="alert alert-danger"><?php echo $db_error; ?></div>
|
|
<?php elseif (!$project_id || !$project_name): ?>
|
|
<div class="alert alert-warning">Project not found or no ID provided.</div>
|
|
<?php elseif (empty($financial_data)): ?>
|
|
<div class="alert alert-info">No financial data found for this project.</div>
|
|
<?php else: ?>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-hover">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<?php
|
|
// Define user-friendly headers
|
|
$header_map = [
|
|
'month' => 'Month',
|
|
'wip' => 'WIP',
|
|
'opening_balance' => 'Opening Balance',
|
|
'billing' => 'Billing',
|
|
'expenses' => 'Expenses',
|
|
'is_overridden' => 'Overridden',
|
|
'createdAt' => 'Created At',
|
|
'updatedAt' => 'Updated At',
|
|
'id' => 'ID',
|
|
];
|
|
|
|
// Get the headers from the first row, but exclude projectId
|
|
$headers = [];
|
|
if (!empty($financial_data)) {
|
|
$headers = array_keys($financial_data[0]);
|
|
// Remove projectId from headers
|
|
$headers = array_filter($headers, fn($h) => $h !== 'projectId');
|
|
}
|
|
|
|
foreach ($headers as $key) {
|
|
$display_header = isset($header_map[$key]) ? $header_map[$key] : htmlspecialchars($key);
|
|
echo "<th>" . $display_header . "</th>";
|
|
}
|
|
?>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($financial_data as $row): ?>
|
|
<tr>
|
|
<?php
|
|
foreach ($headers as $key) {
|
|
$value = $row[$key];
|
|
$formatted_value = htmlspecialchars($value);
|
|
|
|
// Simple currency/date formatting
|
|
if (in_array($key, ['opening_balance', 'payment', 'wip', 'expenses', 'cost', 'nsr', 'value'])) {
|
|
$formatted_value = '€' . number_format((float)$value, 2);
|
|
} elseif ($key === 'margin') {
|
|
$formatted_value = number_format((float)$value * 100, 2) . '%';
|
|
} elseif (in_array($key, ['is_confirmed', 'is_overridden'])) {
|
|
$formatted_value = $value ? '<i class="bi bi-check-circle-fill text-success"></i>' : '<i class="bi bi-x-circle-fill text-danger"></i>';
|
|
} elseif ($key === 'month') {
|
|
try {
|
|
$date = new DateTime($value);
|
|
$formatted_value = $date->format('F Y');
|
|
} catch (Exception $e) {
|
|
// keep original value if format fails
|
|
}
|
|
}
|
|
|
|
echo "<td>" . $formatted_value . "</td>";
|
|
}
|
|
?>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</main>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|