This commit is contained in:
Flatlogic Bot 2025-11-26 17:09:25 +00:00
parent c80560ad92
commit c76337f9a8
3 changed files with 161 additions and 3 deletions

View File

@ -62,8 +62,12 @@ document.addEventListener('DOMContentLoaded', function () {
function makeEditable(metric, month) {
const cell = document.getElementById(`${metric.toLowerCase().replace(/\s/g, '-')}-${month}`);
if (cell) {
const value = cell.textContent.replace(/€/g, '').replace(/,/g, '');
cell.innerHTML = `<input type="number" id="${metric.toLowerCase().replace(/\s/g, '-')}-${month}-input" class="form-control" value="${value}">`;
let value = cell.textContent.replace(/€/g, '').replace(/,/g, '');
let numericValue = parseFloat(value);
if (isNaN(numericValue)) {
numericValue = 0;
}
cell.innerHTML = `<input type="number" id="${metric.toLowerCase().replace(/\s/g, '-')}-${month}-input" class="form-control" value="${numericValue.toFixed(2)}">`;
}
}

View File

@ -218,7 +218,8 @@ if (!$project) {
<div class="header-actions">
<a href="billing.php?id=<?php echo $project['id']; ?>" class="btn btn-primary"><i class="bi bi-credit-card-fill me-2"></i>Billing</a>
<a href="expenses.php?id=<?php echo $project['id']; ?>" class="btn btn-danger me-2"><i class="bi bi-wallet-fill me-2"></i>Expenses</a>
<a href="forecasting.php?projectId=<?php echo $project['id']; ?>" class="btn btn-success"><i class="bi bi-bar-chart-line-fill me-2"></i>Forecasting</a>
<a href="forecasting.php?projectId=<?php echo $project['id']; ?>" class="btn btn-success"><i class="bi bi-bar-chart-line-fill me-2"></i>Forecasting</a>
<a href="project_finance_details.php?id=<?php echo $project['id']; ?>" class="btn btn-info"><i class="bi bi-eye-fill me-2"></i>View Data</a>
</div>
</div>

153
project_finance_details.php Normal file
View File

@ -0,0 +1,153 @@
<?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");
$stmt->execute();
$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>
<div class="alert alert-warning"><strong>Debug Mode:</strong> Showing all data from <code>projectFinanceMonthly</code> table.</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 = [
'metricName' => 'Metric',
'month' => 'Month',
'opening_balance' => 'Opening Balance',
'payment' => 'Payment',
'wip' => 'WIP',
'expenses' => 'Expenses',
'cost' => 'Cost',
'nsr' => 'NSR',
'margin' => 'Margin',
'is_confirmed' => 'Confirmed',
'createdAt' => 'Created At',
'updatedAt' => 'Updated At',
'value' => 'Value',
'is_overridden' => 'Overridden',
'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>