<?php $__template->layout('Layout.main'); ?>

<?php $__template->section('title'); ?>تقرير الدائنين<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<!-- Aging Summary -->
<div style="display:grid;grid-template-columns:repeat(6,1fr);gap:10px;margin-bottom:20px;">
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">جاري</div>
        <div style="font-size:18px;font-weight:700;color:#059669;"><?= money($aging['current_amount'] ?? '0.00') ?></div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">30 يوم</div>
        <div style="font-size:18px;font-weight:700;color:#F59E0B;"><?= money($aging['days_30'] ?? '0.00') ?></div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">60 يوم</div>
        <div style="font-size:18px;font-weight:700;color:#F97316;"><?= money($aging['days_60'] ?? '0.00') ?></div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">90 يوم</div>
        <div style="font-size:18px;font-weight:700;color:#DC2626;"><?= money($aging['days_90'] ?? '0.00') ?></div>
    </div>
    <div class="card" style="padding:15px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">+90 يوم</div>
        <div style="font-size:18px;font-weight:700;color:#991B1B;"><?= money($aging['over_90'] ?? '0.00') ?></div>
    </div>
    <div class="card" style="padding:15px;text-align:center;background:#FEF2F2;">
        <div style="font-size:12px;color:#6B7280;">الإجمالي</div>
        <div style="font-size:18px;font-weight:700;color:#DC2626;"><?= money($aging['total'] ?? '0.00') ?></div>
    </div>
</div>

<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;">الدائنون المستحقة</h3>
    </div>
    <div class="table-responsive">
        <table class="data-table" style="width:100%;">
            <thead>
                <tr>
                    <th>المورد</th>
                    <th>رقم الفاتورة</th>
                    <th>تاريخ الاستحقاق</th>
                    <th>المبلغ</th>
                    <th>المدفوع</th>
                    <th>الرصيد</th>
                    <th>الحالة</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($outstanding as $ap): ?>
                    <?php $isOverdue = strtotime($ap['due_date']) < time(); ?>
                    <tr>
                        <td><?= e($ap['supplier_name'] ?? '—') ?></td>
                        <td style="direction:ltr;text-align:right;"><?= e($ap['invoice_number']) ?></td>
                        <td style="<?= $isOverdue ? 'color:#DC2626;font-weight:600;' : '' ?>"><?= e($ap['due_date']) ?></td>
                        <td style="direction:ltr;text-align:right;"><?= money($ap['total_amount']) ?></td>
                        <td style="direction:ltr;text-align:right;"><?= money($ap['paid_amount']) ?></td>
                        <td style="direction:ltr;text-align:right;font-weight:600;"><?= money($ap['balance']) ?></td>
                        <td style="font-size:12px;color:<?= $isOverdue ? '#DC2626' : '#F59E0B' ?>;"><?= $isOverdue ? 'متأخر' : 'مستحق' ?></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($outstanding)): ?>
                    <tr><td colspan="7" style="text-align:center;color:#6B7280;padding:30px;">لا توجد التزامات مستحقة</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
