<?php
require_once __DIR__.'/../includes/db.php';
require_once __DIR__.'/../includes/auth.php';
include __DIR__.'/../includes/header.php';

$data = $mysqli->query("
  SELECT p.*, i.nama_lengkap
  FROM pengajuan_penghasilan_ortu p
  JOIN infografis i ON p.warga_id=i.id
  ORDER BY p.status='pending' DESC, p.tanggal_pengajuan DESC
");
?>

<h2>📥 Pengajuan Surat Penghasilan Orang Tua</h2>

<table class="table">
<thead>
<tr>
  <th>Nama Anak</th>
  <th>Pekerjaan Ortu</th>
  <th>Penghasilan</th>
  <th>Status</th>
  <th>Aksi</th>
</tr>
</thead>
<tbody>
<?php while($r=$data->fetch_assoc()): ?>
<tr>
  <td><?= esc($r['nama_lengkap']) ?></td>
  <td><?= esc($r['pekerjaan_ortu']) ?></td>
  <td>Rp <?= number_format($r['penghasilan'],0,',','.') ?></td>
  <td><?= strtoupper($r['status']) ?></td>
  <td>
    <?php if($r['status']=='pending'): ?>
      <a class="btn small primary"
         href="pengajuan_penghasilan_ortu_acc.php?id=<?= $r['id'] ?>">
         ACC
      </a>
    <?php else: ?>
      <a class="btn small"
         target="_blank"
         href="surat_penghasilan_ortu.php">
         🖨 Lihat Data
      </a>
    <?php endif; ?>
  </td>
</tr>
<?php endwhile ?>
</tbody>
</table>

<?php include __DIR__.'/../includes/footer.php'; ?>
