<?php ob_start();
error_reporting(0);
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");

session_start();
if (!isset($_SESSION['id_user'])) {
    die('Anda tidak diijinkan mengakses langsung');
}
$tahun = date('Y');
	 $awal = $_POST['dari'];
	 $akhir = $_POST['sampai'];
	  $dari = date('d-m-Y',strtotime($_POST['dari']));
	  $sampai = date('d-m-Y',strtotime($_POST['sampai']));
  $bulan = date('m');
  $bulane = fetch ($koneksi, 'bulan', ['bln' =>$bulan]);
  
?>

<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>

    <title>Rekap Pembayaran</title>
	
<link rel='stylesheet' href='<?= $homeurl ?>/dist/css/cetak.min.css'>
<link rel='stylesheet' href='../../dist/css/bootstrap.min.css' />
</head>
<style>
@page { margin: 60px; }
body { margin: 60px; }
</style>
<body style="font-size: 13px;">

            <table width='100%'>
                <tr>
                    <td width='80'><img src='../../<?= $setting['logo'] ?>' width='70'></td>
                    <td style="text-align:center">
                        <strong class='f12'>
                            <?= strtoupper($setting['header']) ?><br>
							  KABUPATEN / KOTA <?= strtoupper($setting['kabupaten']) ?><br>
                     <?= strtoupper($setting['sekolah']) ?><br>
					 <small>Alamat :  <?= $setting['alamat'] ?> Kec. <?= $setting['kecamatan'] ?> Kab.  <?= $setting['kabupaten'] ?> Email :  <?= $setting['email'] ?></small>
                        </strong>
                    </td>
                    
                </tr>
            </table>
			 <hr style="margin:1px">
		 <hr style="margin:2px">
   <br>
		
		<center><h3>REKAPITULASI TABUNGAN SEKOLAH<br> Tanggal <?= $dari ?> Sampai <?= $sampai ?></h3></center>
		<br>
 
   <table  width='100%' border='1'>
         
              <tr>
                    <th style="height:40px">No.</th>
                    <th width="15%">Tanggal</th>
                    <th>Nama Siswa</th>
                    <th width="25%">Menabung </th>
                    <th width="25%">Pengambilan</th>
                    <th>Saldo</th>
                </tr>
				<?php
				$no = 0;
				
                $query = mysqli_query($koneksi, "select * FROM tabungan WHERE tanggal BETWEEN '$awal' AND '$akhir'");                            
                while ($tab = mysqli_fetch_array($query)) {
						$tanggal=date('d-m-Y',strtotime($tab['tanggal']));	
                       $siswa = fetch($koneksi,'siswa',['id_siswa'=>$tab['idsiswa']]);						
                                      $no++;                         
                                        ?>
			
			 <tr>
                            <td style="text-align:center;width:15">&nbsp;<?= $no ?>.</td>
                            <td style="text-align:center">&nbsp;<?= $tanggal ?></td>
                            <td style="text-align:center">&nbsp;<?= $siswa['nama'] ?></td>
                            <td style="text-align:right">Rp<?= number_format($tab['setoran']) ?>&nbsp;</td>
                            <td style="text-align:right">Rp <?= number_format($tab['penarikan']) ?>&nbsp;</td>
                           <td style="text-align:right">Rp <?= number_format($tab['saldo']) ?>&nbsp;</td>
                        </tr>
						<?php } ?>
						<?php $tabungan = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(setoran)AS setor,SUM(penarikan)AS tarik FROM tabungan WHERE tanggal BETWEEN '$awal' AND '$akhir'")); ?>
				       <tr>
					   <td colspan="3" style="text-align:center;height:30px"> <b>TOTAL</b></td>
					   <td style="text-align:right"><b>Rp <?= number_format($tabungan['setor']) ?></b>&nbsp;</td>
					  <td style="text-align:right"><b>Rp <?= number_format($tabungan['tarik']) ?></b>&nbsp;</td>
					   <td style="text-align:right"><b>Rp <?= number_format($tabungan['setor']-$tabungan['tarik']) ?></b>&nbsp;</td>
					   </tr>
				 </table>
</body>
</html>
<?php

$html = ob_get_clean();
require_once '../../vendors/autoload.php';

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("Rekap Transaksi" . date['m'] . ".pdf", array("Attachment" => false));
exit(0);
?>