<?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");
}

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

header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Laporan Transaksi Pengeluaran.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 Pengeluaran</h1>
      <table>
        <tr>
          <td width="50%">Periode tanggal</td>
          <td>:</td>
          <td><?php echo $dari." sampai ".$sampai; ?></td>
        </tr>
      </table>
      <br>
      <div class="data-tables">
        <table id="dataTable2" class="text-center" border="1">
          <thead class="bg-light text-capitalize">
            <tr>
              <th width="5%">No</th>
              <th width="15%">No. Kwitansi</th>
              <th width="15%">No. Akun</th>
              <th width="10%">Tanggal</th>
              <th width="20%">Penerima</th>
              <th width="25%">Keterangan</th>
              <th width="10%">Banyak</th>
            </tr>
          </thead>
          <tbody>
            <?php
            $query = "SELECT * FROM pengeluaran WHERE tanggal BETWEEN '$dari' AND '$sampai'";
            $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 $qtabel['no_kwitansi']; ?></td>
                <td align="center"><?php echo $qtabel['no_akun']; ?></td>
                <td align="center"><?php echo IndonesiaTgl($qtabel['tanggal']); ?></td>
                <td align="left"><?php echo $qtabel['penerima']; ?></td>
                <td align="left"><?php echo $qtabel['keterangan']; ?></td>
                <td align="right"><?php echo $qtabel['banyak']; ?></td>
              </tr>
              <?php } ?>
              <tr>
                <th colspan="6">Total Pemasukan</th>
                <th><?php echo format_angka($total); ?></th>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
  <?php ob_end_flush(); ?>