<?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/reports" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;">
    <form method="GET" action="/hr/reports/payroll-summary" 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><th>تأمين موظف</th><th>تأمين صاحب عمل</th><th>الضريبة</th><th>الصافي</th></tr></thead>
            <tbody>
                <?php if (empty($monthlySummary)): ?>
                <tr><td colspan="10" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد بيانات لهذه السنة</td></tr>
                <?php else: ?>
                <?php $tGross = $tDed = $tNet = $tOT = $tInsE = $tInsR = $tTax = 0; ?>
                <?php foreach ($monthlySummary as $m): ?>
                <?php $tGross += (float) ($m['total_gross'] ?? 0); $tDed += (float) ($m['total_deductions'] ?? 0); $tNet += (float) ($m['total_net'] ?? 0); $tOT += (float) ($m['total_overtime'] ?? 0); $tInsE += (float) ($m['total_insurance_employee'] ?? 0); $tInsR += (float) ($m['total_insurance_employer'] ?? 0); $tTax += (float) ($m['total_tax'] ?? 0); ?>
                <?php $psl = ['open'=>'مفتوح','calculated'=>'محسوب','approved'=>'معتمد','paid'=>'مصروف','closed'=>'مغلق']; ?>
                <tr>
                    <td style="font-weight:600;"><?= e($mn[(int) $m['month']] ?? '') ?></td>
                    <td><span style="font-size:12px;"><?= e($psl[$m['period_status']] ?? $m['period_status']) ?></span></td>
                    <td><?= (int) ($m['employee_count'] ?? 0) ?></td>
                    <td><?= number_format((float) ($m['total_gross'] ?? 0), 2) ?></td>
                    <td style="color:#DC2626;"><?= number_format((float) ($m['total_deductions'] ?? 0), 2) ?></td>
                    <td><?= number_format((float) ($m['total_overtime'] ?? 0), 2) ?></td>
                    <td><?= number_format((float) ($m['total_insurance_employee'] ?? 0), 2) ?></td>
                    <td><?= number_format((float) ($m['total_insurance_employer'] ?? 0), 2) ?></td>
                    <td><?= number_format((float) ($m['total_tax'] ?? 0), 2) ?></td>
                    <td style="font-weight:700;"><?= number_format((float) ($m['total_net'] ?? 0), 2) ?></td>
                </tr>
                <?php endforeach; ?>
                <tr style="background:#F3F4F6;font-weight:700;">
                    <td>الإجمالي</td><td></td><td></td>
                    <td><?= number_format($tGross, 2) ?></td>
                    <td style="color:#DC2626;"><?= number_format($tDed, 2) ?></td>
                    <td><?= number_format($tOT, 2) ?></td>
                    <td><?= number_format($tInsE, 2) ?></td>
                    <td><?= number_format($tInsR, 2) ?></td>
                    <td><?= number_format($tTax, 2) ?></td>
                    <td><?= number_format($tNet, 2) ?></td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
