<?php

require '../config.php';
session_start();
session_write_close();

$res=$conn->query("

SELECT

s.*,
e.name

FROM salary_advances s

LEFT JOIN employees e
ON e.id=s.employee_id

ORDER BY s.id DESC

");

?>

<!DOCTYPE html>
<html>
<head>

<title>Salary Advance History</title>

<script src="https://cdn.tailwindcss.com"></script>

</head>

<body class="flex bg-gray-100">

<?php include '../sidebar.php'; ?>

<div class="flex-1 p-8" id="main-content">

<h1 class="text-3xl font-bold mb-6">

Salary Advance History

</h1>

<div class="bg-white rounded-xl shadow overflow-hidden">

<table class="w-full">

<thead class="bg-gray-100">

<tr>

<th class="p-4 text-left">
Employee
</th>

<th class="p-4">
Amount
</th>

<th class="p-4">
Manager
</th>

<th class="p-4">
HR
</th>

<th class="p-4">
Payroll
</th>

<th class="p-4">
Date
</th>

</tr>

</thead>

<tbody>

<?php while($row=$res->fetch_assoc()): ?>

<tr class="border-b hover:bg-gray-50">

<td class="p-4">

<?= htmlspecialchars($row['name']) ?>

</td>

<td class="p-4 text-center">

₦<?= number_format($row['amount'],2) ?>

</td>

<td class="p-4 text-center">

<?php if($row['manager_status']=='Approved'): ?>

<span class="bg-green-100 text-green-700 px-3 py-1 rounded-full">

Approved

</span>

<?php elseif($row['manager_status']=='Rejected'): ?>

<span class="bg-red-100 text-red-700 px-3 py-1 rounded-full">

Rejected

</span>

<?php else: ?>

<span class="bg-yellow-100 text-yellow-700 px-3 py-1 rounded-full">

Pending

</span>

<?php endif; ?>

</td>

<td class="p-4 text-center">

<?php if($row['hr_status']=='Approved'): ?>

<span class="bg-green-100 text-green-700 px-3 py-1 rounded-full">

Approved

</span>

<?php elseif($row['hr_status']=='Rejected'): ?>

<span class="bg-red-100 text-red-700 px-3 py-1 rounded-full">

Rejected

</span>

<?php else: ?>

<span class="bg-yellow-100 text-yellow-700 px-3 py-1 rounded-full">

Pending

</span>

<?php endif; ?>

</td>

<td class="p-4 text-center">

<?php if($row['payroll_deducted']): ?>

<span class="bg-blue-100 text-blue-700 px-3 py-1 rounded-full">

Deducted

</span>

<?php else: ?>

<span class="bg-gray-100 text-gray-700 px-3 py-1 rounded-full">

Waiting

</span>

<?php endif; ?>

</td>

<td class="p-4 text-center">

<?= $row['request_date'] ?>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</body>
</html>