<div class="d-flex flex-wrap gap-2 mb-3">
  <a class="btn btn-sm btn-light" href="<?= url('/kualitas-data') ?>"><i class="bi bi-arrow-left me-1"></i>Kembali</a>
  <?php if (can('kualitas_data','export')): ?>
    <a class="btn btn-sm btn-outline-primary" href="<?= url('/kualitas-data/ekspor',['pemeriksaan'=>$key,'format'=>'xlsx']) ?>"><i class="bi bi-file-earmark-excel me-1"></i>Ekspor Excel</a>
  <?php endif; ?>
</div>
<div class="alert alert-<?= ['kritis'=>'danger','tinggi'=>'warning','sedang'=>'info','rendah'=>'secondary'][$pemeriksaan['tingkat']] ?? 'info' ?>">
  <strong><?= e($pemeriksaan['label']) ?></strong><br>
  <span class="small">Saran tindak lanjut: <?= e($pemeriksaan['saran']) ?></span>
</div>
<div class="card">
  <div class="card-header"><i class="bi bi-list-ul me-1"></i>Invoice Terdampak (<?= nf($p['total']) ?>)</div>
  <div class="table-wrap"><table class="table table-hover table-sticky mb-0">
    <thead><tr><th>No. Invoice</th><th>Faktur Pajak</th><th class="ctr">Tgl Invoice</th><th class="ctr">Tgl Kirim</th><th class="ctr">Jatuh Tempo</th>
      <th>Customer</th><th class="num">Nominal</th><th class="num">PPh 23</th><th class="num">Tarif</th><th class="num">Tagihan</th>
      <th class="num">Dibayar</th><th class="num">Saldo</th><th class="ctr">Status</th><th class="ctr">Dokumen</th></tr></thead>
    <tbody>
    <?php if (!$p['data']): ?><tr><td colspan="14"><div class="empty-state"><i class="bi bi-check-circle"></i>Tidak ada invoice bermasalah.</div></td></tr><?php endif; ?>
    <?php foreach ($p['data'] as $r): ?>
      <tr>
        <td><a class="fw-semibold text-decoration-none" href="<?= url('/invoice/'.(int)$r['id']) ?>"><?= e($r['invoice_no']) ?></a></td>
        <td class="small font-monospace"><?= e($r['tax_invoice_no'] ?: '-') ?></td>
        <td class="ctr"><?= tgl($r['invoice_date']) ?></td>
        <td class="ctr"><?= tgl($r['sent_date']) ?></td>
        <td class="ctr"><?= tgl($r['due_date']) ?></td>
        <td><?= e(truncate($r['customer_name'],26)) ?></td>
        <td class="num"><?= rph($r['gross_amount']) ?></td>
        <td class="num"><?= rph($r['pph23_amount']) ?></td>
        <td class="num"><?= (float)$r['pph23_rate'] > 0 ? nf($r['pph23_rate'],2).'%' : '-' ?></td>
        <td class="num"><?= rph($r['net_amount']) ?></td>
        <td class="num"><?= rph($r['paid_amount']) ?></td>
        <td class="num cell-strong"><?= rph($r['outstanding_amount']) ?></td>
        <td class="ctr"><?= statusBadge($r['payment_status_code']) ?></td>
        <td class="ctr"><?= docStatusBadge($r['doc_status']) ?></td>
      </tr>
    <?php endforeach; ?>
    </tbody></table></div>
  <?= \App\Core\View::partial('partials/pagination', ['p' => $p]) ?>
</div>
