<html>

<head>
  <title>Cetak - Laporan Absensi Siswa</title>
  <link rel="stylesheet" href="bootstrap/css/printer.css">
</head>

<body>
  <?php
  session_start();
  error_reporting(0);
  include "config/koneksi.php";
  include "config/fungsi_indotgl.php";


  $tgl_mulai = $_GET['tgl_mulai'];
  $tgl_akhir = $_GET['tgl_akhir'];


  $idKelas = $_GET['kelas'];
  if ($_GET['kelas'] != 'all') {
    $kls = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM kelas_siswa WHERE idKelas='$idKelas'"));
    $kelas = 'Kelas ' . $kls['nmKelas'];
  } else {
    $kelas = 'Semua Kelas';
  }
  $d = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM kelas_siswa where idKelas='$_GET[kelas]'"));
  ?>
  <div class='col-md-12'>
    <div class='box box-info'>
      <div class='box-header with-border'>
        <h3 align='center'>Rekap Data Absensi Siswa </b></h3>
      </div>
      <div class='table-responsive'>

        <div class='col-md-12'>

          <input type='hidden' name='kelas' value='$s[idKelas]'>
          <h4 class='box-title'>Nama Kelas :</th>
            <td><?php echo  $kelas; ?>
          </h4>
          <h4 class='box-title'>Dari Tanggal : <?php echo  tgl_indo($tgl_mulai); ?> Sampai <?php echo   tgl_indo($tgl_akhir); ?>

          </h4>

        </div>

        <?php
        $tgl_mulai = $_GET['tgl_mulai'];
        $tgl_akhir = $_GET['tgl_akhir'];


        $idKelas = $_GET['kelas'];


        $ta = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM tahun_ajaran WHERE idTahunAjaran='$idTahunAjaran'"));
        if ($idKelas != 'all') {
          $kls = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM kelas_siswa WHERE idKelas='$idKelas'"));
          $kelas = 'Kelas ' . $kls['nmKelas'];
        } else {
          $kelas = 'Semua Kelas';
        }


        ?>

      </div><!-- /.box-header -->
      <div class="table-responsive">
        <table id="example" class="table table-bordered table-striped">
          <thead>
            <tr>
              <th>No</th>
              <th>Kelas</th>
              <th>Nama Siswa</th>
              <th>Pertemuan</th>
              <th>Hadir</th>
              <th>Sakit</th>
              <th>Izin</th>
              <th>Alpa</th>
              <th>Terlambat</th>
              <th>
                <center>% Kehadiran</center>
              </th>
            </tr>
          </thead>
          <tbody>
            <?php

            if ($idKelas == 'all') {
              $tampil = mysqli_query($conn, "SELECT * FROM siswa  ORDER BY idSiswa");
            } else {
              $tampil = mysqli_query($conn, "SELECT * FROM siswa  where idKelas='$idKelas' ORDER BY idSiswa");
            }

            $no = 1;
            while ($r = mysqli_fetch_array($tampil)) {
              $total = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir'  GROUP BY tanggal"));
              if ($total == 'null') {
                $sw = "<center style='padding:60px; color:red'>Maaf Tidak ada data...</center>";
              } else {

                $hadir = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='H'"));
                $sakit = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND  nisn='$r[nisnSiswa]' AND kode_kehadiran='S'"));
                $izin = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='I'"));
                $alpa = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='A'"));
                $telat = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND nisn='$r[nisnSiswa]' AND kode_kehadiran='T'"));
                //hitung keseluruhan siswa
                if ($idKelas == 'all') {
                  $hadirs = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir'  AND kode_kehadiran='H'"));
                  $sakits = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND kode_kehadiran='S'"));
                  $izins = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir'  AND kode_kehadiran='I'"));
                  $alpas = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND kode_kehadiran='A'"));
                  $telats = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND kode_kehadiran='T'"));
                  $totals = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir'  "));
                } else {
                  $hadirs = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND idKelas='$_GET[kelas]' AND kode_kehadiran='H'"));
                  $sakits = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND idKelas='$_GET[kelas]' AND kode_kehadiran='S'"));
                  $izins = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND idKelas='$_GET[kelas]' AND kode_kehadiran='I'"));
                  $alpas = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND idKelas='$_GET[kelas]' AND kode_kehadiran='A'"));
                  $telats = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where  DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND idKelas='$_GET[kelas]' AND kode_kehadiran='T'"));
                  $totals = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM `rb_absensi_siswa` where DATE(tanggal) BETWEEN '$tgl_mulai' AND '$tgl_akhir' AND idKelas='$_GET[kelas]' "));
                }
                $tambah = $hadir + $telat;
                $persen = $tambah / ($total) * 100;
                echo "<tr bgcolor=$warna>
                <td>$no</td>
                <td>$r[nisnSiswa]</td>
                <td>$r[nmSiswa]</td>
                <td align=center>$total</td>
                <td align=center>$hadir</td>
                <td align=center>$sakit</td>
                <td align=center>$izin</td>
                <td align=center>$alpa</td>
                <td align=center>$telat</td>
                <td align=right>" . number_format($persen, 2) . " %</td>";
                echo " 
    </tr>
    ";
                $no++;
              }
            }
            echo "</tbody></table><tr>
<td colspan='1'><b>Keterangan</b></td>

</tr>
<table id='example' class='table table-bordered table-striped' width='40%'>
<tr>
<td colspan='1'>Siswa Hadir</td>
<td > $hadirs</td>
</tr>
<tr>
<td colspan='1'>Siswa Izin</td>
<td > $izins</td>
</tr>
<tr>
<td colspan='1'>Siswa Sakit</td>
<td > $sakits</td>
</tr>
<tr>
<td colspan='1'>Siswa Alpha</td>
<td > $alpas</td>
</tr>
<tr>
<td colspan='1'>Siswa Terlambat</td>
<td > $telats</td>
</tr>
<tr>
<td colspan='1'><b>Jumlah Total</b></td>
<td >  $totals</td>
</tr>
";
            echo " ";
            ?>

          </tbody>
        </table>
      </div><!-- /.box-body -->
      <?php

      echo $sw;

      ?>
    </div>
  </div>
  <br>
  <table width="100%">
    <tr>
      <td align="center"></td>
      <td align="center" width="400px">
        Banyuwangi, <?php echo tgl_raport(date("Y-m-d")); ?>
        <br><br><br><br><br><br>
        <b> <?php echo $_SESSION[namalengkap]; ?></b>

      </td>
    </tr>
  </table>
</body>
<script>
  window.print()
</script>

</html>