<?php
session_start();
require_once '../koneksi.php';
$id_guru = $_SESSION['id_guru'] ?? ''; // Sesuaikan jika perlu
?>
<html>
<head>
    <title>Cetak Rekap Absensi</title>
    <style>
        body { font-family: Arial; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th, td { border: 1px solid #000; padding: 8px; text-align: center; }
        th { background: #f2f2f2; }
        @media print { .no-print { display: none; } }
    </style>
</head>
<body onload="window.print()">
    <h3 style="text-align:center;">LAPORAN REKAP ABSENSI SISWA<br>BULAN <?= strtoupper(date('F Y')) ?></h3>
    <table>
        <tr><th>No</th><th>Nama Siswa</th><th>Sakit</th><th>Izin</th><th>Alfa</th></tr>
        <?php
        $no = 1;
        $res = mysqli_query($koneksi, "SELECT s.nama, 
                SUM(IF(a.keterangan='S',1,0)) as s, 
                SUM(IF(a.keterangan='I',1,0)) as i, 
                SUM(IF(a.keterangan='A',1,0)) as a 
                FROM master_siswa s 
                JOIN anggota_rombel ar ON s.id_siswa = ar.id_siswa
                JOIN rombel r ON ar.id_rombel = r.id_rombel
                LEFT JOIN absensi a ON s.id_siswa = a.id_siswa 
                WHERE MONTH(a.tanggal) = MONTH(CURRENT_DATE())
                GROUP BY s.id_siswa");
        while($r = mysqli_fetch_array($res)) {
            echo "<tr><td>{$no}</td><td>{$r['nama']}</td><td>{$r['s']}</td><td>{$r['i']}</td><td>{$r['a']}</td></tr>";
            $no++;
        }
        ?>
    </table>
    <div style="margin-top: 50px; display: flex; justify-content: space-between;">
        <div>Mengetahui,<br>Orang Tua</div>
        <div>Tangerang Selatan, <?= date('d F Y') ?><br>Wali Kelas,<br><br><br><b>( ....................... )</b></div>
    </div>
</body>
</html>