34660-vm/submit_expense.php
Flatlogic Bot ca7e02146d v01.1
2025-10-04 17:27:26 +00:00

134 lines
4.7 KiB
PHP

<?php
require_once 'db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$agent_name = trim($_POST['agent_name'] ?? '');
$amount = trim($_POST['amount'] ?? '');
$description = trim($_POST['description'] ?? '');
if (empty($agent_name) || !is_numeric($amount) || $amount <= 0 || empty($description)) {
$error_message = 'Please fill in all fields with valid data. Amount must be a positive number.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare(
'INSERT INTO expense_reports (agent_name, amount, description, status) VALUES (?, ?, ?, ?)'
);
$stmt->execute([$agent_name, $amount, $description, 'Pending']);
$success_message = 'Expense report submitted successfully!';
} catch (PDOException $e) {
// In a real app, you would log this error, not show it to the user.
$error_message = 'Database error: Could not submit the report.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Submit Expense Report</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Georgia:wght@700&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #F3F4F6;
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Georgia', serif;
}
.form-container {
max-width: 600px;
margin: 4rem auto;
padding: 2rem;
background-color: #FFFFFF;
border-radius: 0.5rem;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
.form-input {
width: 100%;
padding: 0.75rem;
border: 1px solid #D1D5DB;
border-radius: 0.375rem;
transition: border-color 0.2s;
}
.form-input:focus {
outline: none;
border-color: #4F46E5;
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}
.btn-primary {
background-color: #4F46E5;
color: white;
padding: 0.75rem 1.5rem;
border-radius: 0.375rem;
font-weight: 600;
transition: background-color 0.2s;
}
.btn-primary:hover {
background-color: #4338CA;
}
.alert {
padding: 1rem;
border-radius: 0.375rem;
margin-bottom: 1.5rem;
}
.alert-success {
background-color: #D1FAE5;
color: #065F46;
}
.alert-error {
background-color: #FEE2E2;
color: #991B1B;
}
</style>
</head>
<body>
<div class="form-container">
<h1 class="text-2xl font-bold text-gray-800 mb-6">Submit New Expense Report</h1>
<?php if ($success_message): ?>
<div class="alert alert-success">
<?php echo htmlspecialchars($success_message); ?>
<div class="mt-4">
<a href="dashboard.php" class="font-semibold text-indigo-600 hover:text-indigo-500">Return to Dashboard</a>
</div>
</div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-error">
<?php echo htmlspecialchars($error_message); ?>
</div>
<?php endif; ?>
<?php if (!$success_message): ?>
<form action="submit_expense.php" method="POST">
<div class="space-y-6">
<div>
<label for="agent_name" class="block text-sm font-medium text-gray-700 mb-1">Agent Name</label>
<input type="text" id="agent_name" name="agent_name" class="form-input" required>
</div>
<div>
<label for="amount" class="block text-sm font-medium text-gray-700 mb-1">Amount ($)</label>
<input type="number" id="amount" name="amount" step="0.01" min="0.01" class="form-input" required>
</div>
<div>
<label for="description" class="block text-sm font-medium text-gray-700 mb-1">Description</label>
<textarea id="description" name="description" rows="4" class="form-input" required></textarea>
</div>
</div>
<div class="mt-8 border-t pt-6 flex justify-end">
<button type="submit" class="btn-primary">Submit Report</button>
</div>
</form>
<?php endif; ?>
</div>
</body>
</html>