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

125 lines
6.9 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 getStatusClass($status) {
switch ($status) {
case 'Approved':
return 'bg-green-100 text-green-800';
case 'Rejected':
return 'bg-red-100 text-red-800';
case 'Pending':
default:
return 'bg-yellow-100 text-yellow-800';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $page_title; ?> - Expense Tracker</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="assets/css/custom.css">
<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;500;600;700&family=Georgia:wght@400;700&display=swap" rel="stylesheet">
</head>
<body class="bg-gray-50 font-sans">
<header class="bg-white shadow-sm">
<nav class="container mx-auto px-4 lg:px-8 py-4 flex justify-between items-center">
<a href="index.php" class="text-2xl font-bold font-serif text-indigo-600">ExpenseApp</a>
<div class="flex items-center space-x-4">
<a href="dashboard.php" class="text-gray-600 hover:text-indigo-600">Dashboard</a>
<a href="submit_expense.php" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-lg transition duration-300">Submit Report</a>
</div>
</nav>
</header>
<main class="container mx-auto px-4 lg:px-8 py-8">
<div class="flex justify-between items-center mb-6">
<h1 class="text-3xl font-bold font-serif text-gray-800"><?php echo $page_title; ?></h1>
</div>
<?php if (empty($agent_name)): ?>
<div class="bg-white p-8 rounded-lg shadow-md text-center">
<h2 class="text-xl font-semibold text-gray-700">No Agent Selected</h2>
<p class="text-gray-500 mt-2">Please go to the <a href="dashboard.php" class="text-indigo-600 hover:underline">main dashboard</a> and click on an agent's name to see their reports.</p>
</div>
<?php elseif (empty($reports)): ?>
<div class="bg-white p-8 rounded-lg shadow-md text-center">
<h2 class="text-xl font-semibold text-gray-700">No Reports Found</h2>
<p class="text-gray-500 mt-2">This agent has not submitted any expense reports yet.</p>
<a href="submit_expense.php" class="mt-4 inline-block bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-lg transition duration-300">Submit First Report</a>
</div>
<?php else: ?>
<div class="bg-white shadow-md rounded-lg overflow-hidden">
<table class="min-w-full leading-normal">
<thead>
<tr>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Agent</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Date</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-right text-xs font-semibold text-gray-600 uppercase tracking-wider">Amount</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Description</th>
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-center text-xs font-semibold text-gray-600 uppercase tracking-wider">Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($reports as $report): ?>
<tr>
<td class="px-5 py-4 border-b border-gray-200 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap"><?php echo htmlspecialchars($report['agent_name']); ?></p>
</td>
<td class="px-5 py-4 border-b border-gray-200 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap"><?php echo date("M d, Y", strtotime($report['created_at'])); ?></p>
</td>
<td class="px-5 py-4 border-b border-gray-200 bg-white text-sm text-right">
<p class="text-gray-900 whitespace-no-wrap">$<?php echo number_format($report['amount'], 2); ?></p>
</td>
<td class="px-5 py-4 border-b border-gray-200 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap"><?php echo htmlspecialchars($report['description']); ?></p>
</td>
<td class="px-5 py-4 border-b border-gray-200 bg-white text-sm text-center">
<span class="relative inline-block px-3 py-1 font-semibold leading-tight <?php echo getStatusClass($report['status']); ?> rounded-full">
<span aria-hidden class="absolute inset-0 opacity-50 rounded-full"></span>
<span class="relative"><?php echo htmlspecialchars($report['status']); ?></span>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</main>
<footer class="bg-white mt-12">
<div class="container mx-auto px-4 lg:px-8 py-6 text-center text-gray-500">
<p>&copy; <?php echo date("Y"); ?> ExpenseApp. All Rights Reserved.</p>
</div>
</footer>
</body>
</html>