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"; ?> <?php echo $page_title; ?>
Project Financials
Project not found or no ID provided.
No financial data found for this project.
'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 ""; } ?> ' : ''; } elseif ($key === 'month') { try { $date = new DateTime($value); $formatted_value = $date->format('F Y'); } catch (Exception $e) { // keep original value if format fails } } echo ""; } ?>
" . $display_header . "
" . $formatted_value . "