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