34660-vm/my_reports.php
Flatlogic Bot 758f3e1226 v01.5
2025-10-04 17:40:17 +00:00

89 lines
3.4 KiB
PHP

<?php
require_once 'db/config.php';
// Simulate getting the logged-in agent's name from a query parameter
$agent_name = $_GET['agent'] ?? '';
if (empty($agent_name)) {
// In a real app, you'd redirect to a login page or show an error.
// For now, we'll just show a message.
$page_title = 'My Reports';
$reports = [];
} else {
$page_title = "Reports for " . htmlspecialchars($agent_name);
try {
$pdo = db();
// Fetch reports only for the specified agent
$stmt = $pdo->prepare("SELECT id, agent_name, amount, description, status, created_at FROM expense_reports WHERE agent_name = ? ORDER BY created_at DESC");
$stmt->execute([$agent_name]);
$reports = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// For a real app, log this error instead of displaying it
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';
}
}
require_once 'includes/header.php';
?>
<h1 class="mb-4"><?php echo $page_title; ?></h1>
<?php if (empty($agent_name)):
<div class="alert alert-warning text-center">
<h2 class="h4">No Agent Selected</h2>
<p>Please go to the <a href="dashboard.php" class="alert-link">main dashboard</a> and click on an agent's name to see their reports.</p>
</div>
<?php elseif (empty($reports)):
<div class="alert alert-info text-center">
<h2 class="h4">No Reports Found</h2>
<p>This agent has not submitted any expense reports yet.</p>
<a href="submit_expense.php" class="btn btn-primary mt-3">Submit First Report</a>
</div>
<?php else:
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table align-middle">
<thead>
<tr>
<th>Agent</th>
<th>Date</th>
<th class="text-end">Amount</th>
<th>Description</th>
<th class="text-center">Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($reports as $report): ?>
<tr>
<td><?php echo htmlspecialchars($report['agent_name']); ?></td>
<td><?php echo date("M d, Y", strtotime($report['created_at'])); ?></td>
<td class="text-end">$<?php echo number_format($report['amount'], 2); ?></td>
<td><?php echo htmlspecialchars($report['description']); ?></td>
<td class="text-center">
<span class="badge-status <?php echo getStatusBadgeClass($report['status']); ?>">
<?php echo htmlspecialchars($report['status']); ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
<?php
require_once 'includes/footer.php';
?>