<?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');
	  $bulan = $_POST['bulan'];
	  $kode = $_POST['kode'];
  $bulane = fetch ($koneksi, 'bulan', ['bln' =>$bulan]);
  $master = fetch ($koneksi, 'm_bayar', ['kode' =>$kode]);
  $jml = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM trx WHERE bulan='$bulan' AND kode='$kode' AND tahun='$tahun'"));
  $total= $jml*$master['besar'];
?>

<!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 PEMBAYARAN <?= strtoupper($master['nama_pembayaran']) ?><br> BULAN <?= strtoupper($bulane['ket']) ?> <?= date('Y') ?></h3></center>
		<br>
 
   <table  width='100%' border='1'>
         
              <tr>
                    <th style="height:40px">No.</th>
                    <th width="15%">NIS</th>
                    <th width="15%">NISN</th>
                    <th>Nama Siswa </th>
                    <th width="25%">Jumlah</th>
                    <th width="10%">Catatan</th>
                </tr>
				<?php
				$no = 0;
				
                $query = mysqli_query($koneksi, "select * from trx WHERE bulan='$bulan' AND kode='$kode' AND tahun='$tahun'");                            
                while ($bayar = mysqli_fetch_array($query)) {
							    $siswa = fetch($koneksi,'siswa',['id_siswa'=>$bayar['idsiswa']]); 
							      		
                                      $no++;                         
                                        ?>
			
			 <tr>
                            <td style="text-align:center;width:15">&nbsp;<?= $no ?>.</td>
                            <td style="text-align:center">&nbsp;<?= $siswa['nis'] ?></td>
                            <td style="text-align:center">&nbsp;<?= $siswa['nisn'] ?></td>
                            <td>&nbsp;<?= $siswa['nama'] ?></td>
                            <td style="text-align:right">Rp <?= number_format($master['besar']) ?>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
						<?php } ?>
				       <tr>
					   <td colspan="4" style="text-align:center;height:30px"> <b>TOTAL</b></td>
					   <td style="text-align:right"><b>Rp <?= number_format($total) ?></b>&nbsp;</td>
					   <td></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);
?>