<?php
// api/endpoints/tagihan_siswa_get.php
$nis = $_GET['nis'] ?? '';
if (empty($nis)) {
    respond(['status' => 'error', 'message' => 'NIS wajib diisi'], 400);
}
$stmt = $pdo->prepare("
    SELECT t.id, t.siswa_id, t.bulan, t.tahun, t.nominal, t.status,
           s.nama AS nama_siswa, s.nis AS nis_siswa, s.kelas, s.jurusan,
           ELT(t.bulan,
               'Januari','Februari','Maret','April','Mei','Juni',
               'Juli','Agustus','September','Oktober','November','Desember'
           ) AS bulan_nama
    FROM tagihan_spp t
    JOIN siswa s ON t.siswa_id = s.id
    WHERE s.nis = ?
    ORDER BY t.tahun DESC, t.bulan DESC
");
$stmt->execute([$nis]);
$rows = $stmt->fetchAll();
foreach ($rows as &$r) {
    $r['nominal']        = (int)$r['nominal'];
    $r['jumlah_dibayar'] = 0;
    $r['bulan']          = (int)$r['bulan'];
    $r['tahun']          = (int)$r['tahun'];
}
respond(['status' => 'success', 'data' => $rows]);