<?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');
}
$ambilbln=date('m');
$ambilthn=date('Y');

    $bulane = fetch ($koneksi, 'bulan', ['bln' =>$ambilbln]);
?>
<!DOCTYPE html>
<html>

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

    <title>Data Peminjam Buku</title>
<link rel="stylesheet" href="../../plugins/bootstrap/dist/css/bootstrap.min.css">
</head>
<style>
@page { margin: 20px; }
body { margin: 20px; }
</style>
<body style="font-size: 11px;">
    
   
    <center>
        <h6>DATA PEMINJAMAN BUKU PERPUSTAKAAN<br>BULAN <?= strtoupper($bulane['ket']) ?> TAHUN <?= date('Y') ?></h6>
    </center>
    <br>
       <table width="100%" border="1" style="font-size:10px">
          <tr>
         <th style="text-align:center;height:30px;width:5%">No</th>
		 <th style="text-align:center;">Nama Siswa</th>
		 <th style="text-align:center;height:30px;width:10%">Kelas</th>
		 <th style="text-align:center;">Judul Buku</th>
		 <th style="text-align:center;width:10%">Tgl Pinjam</th>
         <th style="text-align:center;width:10%">Tgl Kembali</th>
         <th style="text-align:center;width:5%">Jml</th>
         <th style="text-align:center;width:5%">Lama</th>			 
		</tr>
		<?php
		$no = 0;
		$query = mysqli_query($koneksi, "select * from buku_pinjam WHERE  substr(tgl_pinjam,1,7)='$ambilthn-$ambilbln'");
        while ($tjn = mysqli_fetch_array($query)) {
		$buku = fetch($koneksi,'buku',['id_buku'=>$tjn['idbuku']]);
		$siswa = fetch($koneksi,'siswa',['id_siswa'=>$tjn['idsiswa']]);
		 $tp=date('d',strtotime($tjn['tgl_pinjam']));
								 $tk = date('d');
								$lamapinjam = $tk-$tp;
                   $no++;
                   ?>
		 <tr>
          <td style="text-align:center;"><?= $no; ?></td>
		<td>&nbsp;<?= $siswa['nama'] ?></td>
		<td style="text-align:center;"><?= $tjn['kelas'] ?></td>
		<td>&nbsp;<?= $buku['judul'] ?></td>
		<td style="text-align:center;"><?= $tjn['tgl_pinjam'] ?></td>
		<td style="text-align:center;"><?= $tjn['tgl_kembali'] ?></td>
		<td style="text-align:center;"><?= $tjn['jumlah'] ?></td>
		<td style="text-align:center;">
		<?php if($tjn['tgl_kembali']<>''){ ?>
		<?= $lamapinjam ?> hari
		<?php } ?>
		</td>
		</tr>
		<?php } ?>							
    </table>
		<br>
		<table width='100%'>
					<tr>
					<td></td>
					<td></td>
						<td>
							Mengetahui, <br/>
							Kepala Sekolah <br/>
							<br/>
							<br/>
							<br/>
							
							<u><?= $setting['kepsek'] ?></u><br/>
							NIP. <?= $setting['nip'] ?>
						</td>
						<td width='40%'></td>
						<td width="5%"></td>
						<td>
							<?= $setting['kecamatan'] ?>, <?php echo date("t",time());; ?> <?= $bulane['ket'] ?> <?= date('Y') ?><br/>
							Pengurus Perpustakaan<br/>
							<br/>
							<br/>
							<br/>
							
							<u>___________________________</u><br/>
							NIP. 
						</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("Raport_" . $siswa['nama'] . ".pdf", array("Attachment" => false));
exit(0);
?>