<?php ob_start();

require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");
	(isset($_SESSION['id_user'])) ? $id_user = $_SESSION['id_user'] : $id_user = 0;
	($id_user==0) ? header('location:login.php'):null;
	
	$bulan= $_POST['bulan'];
    $bulane = fetch ($koneksi, 'bulan', ['bln' =>$bulan]);
	?>

<!DOCTYPE html>
<html>

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

    <title>Rekap Honor GTT</title>

<link rel='stylesheet' href='../../vendor/css/cetak.min.css'>
<link rel='stylesheet' href='../../vendor/css/bootstrap.min.css' />
</head>
<style>
@page { margin: 80px; }
body { margin: 20px; }
</style>
<body style="font-size: 13px;">	


<div style='background:#fff; width:97%; margin:0 auto; height:90%;'>
            <table width='100%'>
                <tr>
                    <td width='100'><img src='../../images/<?= $setting['logo'] ?>' width='70'></td>
                    <td style="text-align:center">
                        <strong class='f12'>
                        <?= strtoupper($setting['header']) ?><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><h4>REKAPITULASI HONOR GTT</h4></center>
		<br>
 
    <table width="100%">
	
            <tr>
			<td width="10%"></td>
                 <td width='100px'>Sekolah</td>
                <td width='10px'>:</td>
                <td><?= $setting['sekolah'] ?></td>
				<td width="70%"></td>
				<td width='100px'>Bulan</td>
                <td width='10px'>:</td>
                <td><?= $bulane['ket'] ?> <?= date('Y') ?></td>
            </tr>
			
                <tr>
				<td width="10%"></td>
                <td width='100px'>NPSN</td>
                <td width='10px'>:</td>
                <td><?= $setting['npsn'] ?></td>
				<td ></td>
				 <td width='100px'>Smt - TP</td>
                <td width='10px'>:</td>
                <td><?= $setting['semester'] ?> - <?= $setting['tp'] ?></td>
				</tr>
				
			
    </table>

     <br>
	 
		 <table class='it-grid it-cetak' width='100%'>       
              <tr>
                <th width="2%">NO</th>
               
                <th width="35%" class="text-center">NAMA GURU</th>													                                                  
                <th width="5%" class="text-center">HADIR</th>
	            <th width="5%" class="text-center">JJM</th>
				 <th width="10%" class="text-center">HONOR PER JAM</th>
			    <th class="text-center">TOTAL DITERIMA</th>
				 <th class="text-center">PARAF</th>
            </tr>
              <?php
			  $tahun = date('Y');
				$query = mysqli_query($koneksi, "SELECT * FROM absensi WHERE level='pegawai' and ket='H' and bulan='$bulan' and tahun='$tahun' GROUP BY idpeg"); 											
	           while ($data = mysqli_fetch_array($query)) :	
				$hadir = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM absensi WHERE bulan='$bulan' AND tahun='$tahun' AND ket='H' AND idpeg='$data[idpeg]'"));
				$jjm = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(jjm)AS jjjm,bulan,idpeg FROM absensi WHERE bulan='$bulan' AND tahun='$tahun' AND idpeg='$data[idpeg]'"));
										
			$peg = fetch($koneksi,'users',['id_user'=>$data['idpeg']]);
			$no++;
			?>
			
		<tr>
                 <td class="text-center"><?= $no; ?></td>
                 <td><?= $peg['nama'] ?></td>
                  <td class="text-center"><?= $hadir ?> X</td>
				<td class="text-center"><?= $jjm['jjjm'] ?></td>
				<td class="text-right">Rp. <?= number_format($data['honor']); ?>&nbsp;</td>
				<td class="text-right"><b>Rp. <?= number_format($jjm['jjjm']*$data['honor']); ?></b>&nbsp;</td>
				<td></td>
                  </tr>
			  <?php endwhile; ?>
                    
								
            </table>
			
    <br>
	
	<table width='100%'>
					<tr>
					<td width="5%"></td>
					<td width='50px'></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>
							<?= ucwords(strtolower($setting['kecamatan'])); ?>, <?php echo date("t",time()); ?> <?= $bulane['ket'] ?> <?= date('Y') ?><br/>
							Bendahara Sekolah<br/>
							<br/>
							<br/>
							<br/>
							
							<u>.......................................</u><br/>
							NIP. .
						</td>
					</tr>
				</table>
</div>
</body>

</html>
<?php

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

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'Potrait');
$dompdf->render();
$dompdf->stream("Rekap Honor GTT Bulan ". $bulan . ".pdf", array("Attachment" => false));
exit(0);
?>