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

payrollRequireAdmin($auth);

$payroll = new Payroll($conn);
$checks = $payroll->getComplianceStatus();

payrollModuleStyles();
?>

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

    <div class="payroll-page-head">
        <div>
            <h1>HR Compliance</h1>
            <p>Monitor payroll readiness, statutory identifiers, employment records, and audit controls.</p>
        </div>
        <a href="setup.php" class="btn btn-outline-primary no-print"><i class="fas fa-screwdriver-wrench"></i> Setup</a>
    </div>

    <div class="payroll-panel">
        <div class="payroll-panel-title"><h2>Employee Record Completeness</h2></div>
        <div class="table-responsive">
            <table class="table table-bordered payroll-table">
                <thead>
                    <tr>
                        <th>Requirement</th>
                        <th>Complete</th>
                        <th>Total</th>
                        <th>Completion</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($checks as $check): ?>
                        <?php $percent = $check['total'] > 0 ? round(($check['complete'] / $check['total']) * 100) : 0; ?>
                        <tr>
                            <td><?php echo payrollText($check['label']); ?></td>
                            <td><?php echo number_format($check['complete']); ?></td>
                            <td><?php echo number_format($check['total']); ?></td>
                            <td>
                                <div class="progress" style="height: 20px;">
                                    <div class="progress-bar <?php echo $percent >= 90 ? 'bg-success' : ($percent >= 60 ? 'bg-warning' : 'bg-danger'); ?>" style="width: <?php echo $percent; ?>%;">
                                        <?php echo $percent; ?>%
                                    </div>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>

    <div class="payroll-panel mt-3">
        <div class="payroll-panel-title"><h2>International Payroll Controls</h2></div>
        <div class="row g-3">
            <div class="col-md-6"><strong>Identity and right-to-work evidence</strong><br>National ID/passport, legal name, date of birth, and employee code.</div>
            <div class="col-md-6"><strong>Employment contract</strong><br>Start date, employment type, status, probation, contract end, job title, and work location.</div>
            <div class="col-md-6"><strong>Payroll tax and pension</strong><br>Tax ID, social security/pension ID, pension rates, deductions, and audit trail.</div>
            <div class="col-md-6"><strong>Payment controls</strong><br>Bank account verification, pay-run approval, payslip archive, and segregation of duties.</div>
            <div class="col-md-6"><strong>Leave and attendance</strong><br>Approved leave, attendance history, overtime, unpaid absence, and payroll deductions.</div>
            <div class="col-md-6"><strong>Data protection</strong><br>Restricted HR access, minimal sensitive data exposure, retention policy, and audit logs.</div>
        </div>
    </div>

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

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