<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>قسيمة راتب<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div style="max-width:800px;margin:0 auto;">
    <div style="text-align:left;margin-bottom:12px;"><button onclick="window.print();" class="btn btn-primary" style="display:inline-flex;align-items:center;gap:6px;"><i data-lucide="printer" style="width:16px;height:16px;"></i> طباعة</button></div>
    <div id="slip" style="background:#fff;border:2px solid #333;padding:24px;font-family:Arial,sans-serif;">
        <div style="text-align:center;margin-bottom:20px;border-bottom:2px solid #333;padding-bottom:16px;">
            <h2 style="margin:0;">قسيمة راتب</h2>
            <p style="margin:4px 0;">الفترة: <?= e($month_name) ?> <?= e($year) ?></p>
        </div>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:20px;font-size:14px;">
            <div><strong>الموظف:</strong> <?= e($profile['first_name_ar'] . ' ' . $profile['last_name_ar']) ?></div>
            <div><strong>الرقم الوظيفي:</strong> <?= e($profile['employee_number']) ?></div>
            <div><strong>القسم:</strong> <?= e($department) ?></div>
            <div><strong>المسمى الوظيفي:</strong> <?= e($job_title) ?></div>
        </div>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
            <div>
                <h4 style="border-bottom:1px solid #666;padding-bottom:4px;color:#059669;">الاستحقاقات</h4>
                <table style="width:100%;font-size:13px;">
                    <?php $totalEarnings = '0.00'; foreach ($earnings as $e): ?>
                    <tr><td style="padding:4px 0;"><?= e($e['component_name']) ?></td><td style="text-align:left;padding:4px 0;"><?= number_format((float) $e['amount'], 2) ?></td></tr>
                    <?php $totalEarnings = bcadd($totalEarnings, $e['amount'], 2); endforeach; ?>
                    <tr style="border-top:1px solid #333;font-weight:700;"><td style="padding:6px 0;">الإجمالي</td><td style="text-align:left;padding:6px 0;"><?= number_format((float) $totalEarnings, 2) ?></td></tr>
                </table>
            </div>
            <div>
                <h4 style="border-bottom:1px solid #666;padding-bottom:4px;color:#DC2626;">الخصومات</h4>
                <table style="width:100%;font-size:13px;">
                    <?php $totalDeductions = '0.00'; foreach ($deductions as $d): ?>
                    <tr><td style="padding:4px 0;"><?= e($d['component_name']) ?></td><td style="text-align:left;padding:4px 0;"><?= number_format((float) $d['amount'], 2) ?></td></tr>
                    <?php $totalDeductions = bcadd($totalDeductions, $d['amount'], 2); endforeach; ?>
                    <tr style="border-top:1px solid #333;font-weight:700;"><td style="padding:6px 0;">الإجمالي</td><td style="text-align:left;padding:6px 0;"><?= number_format((float) $totalDeductions, 2) ?></td></tr>
                </table>
            </div>
        </div>
        <div style="border-top:2px solid #333;padding-top:12px;text-align:center;">
            <span style="font-size:20px;font-weight:700;">صافي الراتب: <?= number_format((float) $run['net_salary'], 2) ?> ج.م</span>
        </div>
    </div>
</div>
<style>@media print{body *{visibility:hidden;}#slip,#slip *{visibility:visible;}#slip{position:absolute;left:0;top:0;width:100%;}}</style>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
