<?php
include '../../includes/header.php';
require_once __DIR__ . '/_module.php';

payrollRequireAdmin($auth);

$payroll = new Payroll($conn);
$employees = $payroll->getAllEmployees();

payrollModuleStyles();
?>

<div class="container-fluid px-4">
    <?php payrollModuleNav('remunerations'); ?>

    <div class="payroll-page-head">
        <div>
            <h1>Remunerations</h1>
            <p>Employee salary and allowance register for payroll review.</p>
        </div>
        <div class="no-print">
            <a href="../dashboard/admin.php" class="btn btn-outline-secondary"><i class="fas fa-arrow-left"></i> Admin Dashboard</a>
            <button type="button" class="btn btn-outline-secondary" onclick="window.print()"><i class="fas fa-print"></i> Print</button>
        </div>
    </div>

    <div class="payroll-panel">
        <div class="table-responsive">
            <table class="table table-bordered payroll-table">
                <thead>
                    <tr>
                        <th>Employee</th>
                        <th>Branch</th>
                        <th>Position</th>
                        <th>Payment Frequency</th>
                        <th>Basic Salary</th>
                        <th>Bank Details</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($employees)): ?>
                        <?php foreach ($employees as $employee): ?>
                            <tr>
                                <td><?php echo payrollText($employee['employee_fullname'] ?? ''); ?></td>
                                <td><?php echo payrollText($employee['branch'] ?? ''); ?></td>
                                <td><?php echo payrollText($employee['employee_position'] ?? ''); ?></td>
                                <td><?php echo payrollText($employee['payment_frequency'] ?? ''); ?></td>
                                <td><?php echo payrollMoney($employee['basic_salary'] ?? 0); ?></td>
                                <td><?php echo payrollText($employee['bank_details'] ?? ''); ?></td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <tr><td colspan="6" class="text-center">No remuneration records found.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

    <?php payrollModuleEnd(); ?>
</div>

<?php include '../../includes/footer.php'; ?>
