34660-vm/dashboard.php
Flatlogic Bot 8bd25eba00 v01.3
2025-10-04 17:29:49 +00:00

145 lines
6.5 KiB
PHP

<?php
require_once 'db/config.php';
// --- Database Setup ---
try {
$pdo = db();
// 1. Create table
$migrationSql = file_get_contents('db/migrations/001_create_expense_reports_table.sql');
if ($migrationSql) {
$pdo->exec($migrationSql);
}
// 2. Seed data if table is empty
$stmt = $pdo->query("SELECT COUNT(*) FROM expense_reports");
$count = $stmt->fetchColumn();
if ($count == 0) {
$seedData = [
['agent_name' => 'John Doe', 'amount' => 150.75, 'description' => 'Client Dinner', 'status' => 'Approved'],
['agent_name' => 'Jane Smith', 'amount' => 89.99, 'description' => 'Office Supplies', 'status' => 'Pending'],
['agent_name' => 'Peter Jones', 'amount' => 1200.00, 'description' => 'Flight to Conference', 'status' => 'Pending'],
['agent_name' => 'John Doe', 'amount' => 45.50, 'description' => 'Taxi Fare', 'status' => 'Rejected'],
['agent_name' => 'Susan Williams', 'amount' => 320.00, 'description' => 'Hotel Stay', 'status' => 'Approved'],
];
$insertSql = "INSERT INTO expense_reports (agent_name, amount, description, status) VALUES (?, ?, ?, ?)";
$stmt = $pdo->prepare($insertSql);
foreach ($seedData as $row) {
$stmt->execute([$row['agent_name'], $row['amount'], $row['description'], $row['status']]);
}
}
// 3. Fetch all reports
$reports = $pdo->query("SELECT * FROM expense_reports ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// In a real app, log this error. For now, we'll just show a message.
die("Database error: " . $e->getMessage());
}
function getStatusBadgeClass($status) {
switch ($status) {
case 'Approved': return 'badge-approved';
case 'Rejected': return 'badge-rejected';
case 'Pending':
default:
return 'badge-pending';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manager Dashboard - ExpenseTracker</title>
<meta name="description" content="Review and manage all agent expense reports from one central dashboard.">
<meta name="keywords" content="expense dashboard, manage expenses, approve reports, expense overview, financial dashboard, agent spending">
<meta name="robots" content="noindex, nofollow"> <!-- This is an internal tool page -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=Georgia:wght@700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container">
<a class="navbar-brand" href="/">ExpenseTracker</a>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link active" href="dashboard.php">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="submit_expense.php">Submit Report</a>
</li>
</ul>
</div>
</nav>
<div class="container mt-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Expense Reports</h1>
<a href="submit_expense.php" class="btn btn-primary">Submit New Expense</a>
</div>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table align-middle">
<thead>
<tr>
<th>Agent Name</th>
<th>Amount</th>
<th>Date</th>
<th>Status</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($reports)): ?>
<tr>
<td colspan="6" class="text-center text-muted pt-4 pb-4">No expense reports submitted yet.</td>
</tr>
<?php else: ?>
<?php foreach ($reports as $report): ?>
<tr>
<td>
<a href="my_reports.php?agent=<?php echo urlencode($report['agent_name']); ?>" class="text-decoration-none">
<?php echo htmlspecialchars($report['agent_name']); ?>
</a>
</td>
<td>$<?php echo number_format($report['amount'], 2); ?></td>
<td><?php echo date('M d, Y', strtotime($report['created_at'])); ?></td>
<td>
<span class="badge-status <?php echo getStatusBadgeClass($report['status']); ?>">
<?php echo htmlspecialchars($report['status']); ?>
</span>
</td>
<td><?php echo htmlspecialchars($report['description']); ?></td>
<td>
<a href="#" class="btn btn-sm btn-outline-secondary disabled" aria-disabled="true">View</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<footer class="text-center p-4 mt-5">
<p>&copy; <?php echo date("Y"); ?> ExpenseTracker. All rights reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>