<?php 
ob_start();
session_start();
// if($_SESSION['status']!="login"){
// cek apakah yang mengakses halaman ini sudah login
if($_SESSION['level']==""){
  header("location:../index.php?pesan=belum_login");
}

$kelas=$_GET['kelas'];
$dari=$_GET['dari'];
$sampai=$_GET['sampai'];

header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Laporan SPMP Per Kelas.xls");
include_once "../../library/inc.sesadmin.php";
include_once "../../library/inc.library.php";
include_once "../../library/inc.connection.php";
?>

<div class="col-12 mt-4">
  <div class="card">
    <div class="card-body">
      <h1 class="header-title">Rekap Transaksi Pembayaran SPMP Per Kelas</h1>
      <table>
        <tr>
          <td width="50%">Periode tanggal</td>
          <td>:</td>
          <td><?php echo $dari." sampai ".$sampai; ?></td>
        </tr>
        <tr>
          <td>Kelas</td>
          <td>:</td>
          <td><?php echo $kelas; ?></td>
        </tr>
      </table>
      <br>
      <div class="data-tables">
        <table id="dataTable2" class="text-center" border="1">
          <thead class="bg-light text-capitalize">
            <tr>
              <th>No</th>
              <th>Tanggal Transaksi</th>
              <th>NIS</th>
              <th>Nama Siswa</th>
              <th>Keterangan</th>
              <th>Jumlah</th>
            </tr>
          </thead>
          <tbody>
            <?php
            $query = "SELECT transaksi.*, transaksi_item.*, kelas.*, siswa.*, bulan.* FROM transaksi INNER JOIN transaksi_item ON transaksi.no_transaksi=transaksi_item.no_transaksi INNER JOIN kelas_siswa ON transaksi_item.nis=kelas_siswa.nis INNER JOIN kelas ON kelas_siswa.kdkelas=kelas.kdkelas INNER JOIN siswa ON kelas_siswa.nis=siswa.nis INNER JOIN bulan ON transaksi_item.kode_bayar=bulan.kode WHERE kelas.namakelas='$kelas' AND transaksi.tgl_transaksi BETWEEN '$dari' AND '$sampai' AND bulan.keterangan LIKE '%SPMP%'";
            $hasil = mysql_query($query);
  // echo mysql_num_rows($hasil);
            $nomor = 0;
            $total = 0;
            while ($qtabel = mysql_fetch_array($hasil))
            { 
              $nomor++;
              $total = $total + intval($qtabel['banyak']);
              ?>
              <tr>
                <td align="center"><b><?php echo $nomor; ?></b></td>
                <td align="center"><?php echo IndonesiaTgl($qtabel['tgl_transaksi']); ?></td>
                <td align="center"><?php echo $qtabel['nis']; ?></td>
                <td><?php echo $qtabel['nama_siswa']; ?></td>
                <td><?php echo $qtabel['keterangan']; ?></td>
                <td align="center"><?php echo $qtabel['banyak']; ?></td>
              </tr>
              <?php } ?>
              <tr>
                <th colspan="5">Total Pemasukan</th>
                <th><?php echo format_angka($total); ?></th>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
  <?php ob_end_flush(); ?>
