<?php $__template->layout('Layout.main'); ?>
<?php $mn = [1=>'يناير',2=>'فبراير',3=>'مارس',4=>'أبريل',5=>'مايو',6=>'يونيو',7=>'يوليو',8=>'أغسطس',9=>'سبتمبر',10=>'أكتوبر',11=>'نوفمبر',12=>'ديسمبر']; ?>
<?php $__template->section('title'); ?>التأمينات الاجتماعية <?= $year ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/hr/insurance/form1?year=<?= $year ?>" class="btn btn-secondary">استمارة 1</a>
<a href="/hr/insurance/form6?year=<?= $year ?>" class="btn btn-secondary">استمارة 6</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;">
    <form method="GET" action="/hr/insurance" style="display:flex;gap:10px;align-items:end;padding:16px;">
        <div><label style="display:block;margin-bottom:4px;font-size:13px;">السنة</label><input type="number" name="year" value="<?= $year ?>" class="form-control" style="max-width:100px;"></div>
        <button type="submit" class="btn btn-secondary">عرض</button>
    </form>
</div>
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead><tr><th>الشهر</th><th>الموظفين</th><th>حصة الموظف</th><th>حصة صاحب العمل</th><th>الإجمالي</th><th>إجراءات</th></tr></thead>
            <tbody>
                <?php $yearTotal = ['emp' => 0, 'emr' => 0]; ?>
                <?php foreach ($periods as $p): ?>
                <?php $yearTotal['emp'] += (float) ($p['total_employee_share'] ?? 0); $yearTotal['emr'] += (float) ($p['total_employer_share'] ?? 0); ?>
                <tr>
                    <td><?= e($mn[(int) $p['month']] ?? '') ?></td>
                    <td><?= (int) $p['record_count'] ?></td>
                    <td><?= number_format((float) ($p['total_employee_share'] ?? 0), 2) ?></td>
                    <td><?= number_format((float) ($p['total_employer_share'] ?? 0), 2) ?></td>
                    <td style="font-weight:600;"><?= number_format(((float) ($p['total_employee_share'] ?? 0)) + ((float) ($p['total_employer_share'] ?? 0)), 2) ?></td>
                    <td><a href="/hr/insurance/period/<?= (int) $p['id'] ?>" style="color:#2563EB;">التفاصيل</a></td>
                </tr>
                <?php endforeach; ?>
                <tr style="font-weight:700;border-top:2px solid #333;">
                    <td>الإجمالي السنوي</td><td></td>
                    <td><?= number_format($yearTotal['emp'], 2) ?></td>
                    <td><?= number_format($yearTotal['emr'], 2) ?></td>
                    <td><?= number_format($yearTotal['emp'] + $yearTotal['emr'], 2) ?></td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
