<?php ob_start();

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');
$ids=$_GET['nis'];

$siswa = fetch($koneksi, 'siswa', ['nis' => $ids]);
$kelas = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM kelas  WHERE kelas='$siswa[kelas]'"));
$skl = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM skl  WHERE id_skl='1'"));

?>
<!DOCTYPE html>
<html>

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

    <title>Transkip_<?= $siswa['nama'] ?></title>
<link rel="stylesheet" href="../vendor/css/bootstrap.min.css">
</head>
<style>
@page { margin: 20px; }
body { margin: 20px; }
</style>
<body style="font-size: 11px;">
    
   
    <center>
        <h5><?= strtoupper($setting['sekolah']); ?><br>TRANSKRIP NILAI</h5>
    </center>
    <br>
    
    <div class="col-md-14">
	<?php if($setting['jenjang']=='SMK'): ?>
        <table style="margin-left: 20px;margin-right:10px;font-size:11px"  width="100%">
            <tr>
                <td width="18%">Nama Siswa</td>
                <td width="1%">:</td>
				<td><?= $siswa['nama'] ?></td>
				<td width="7%"></td>
				<td width="18%">Tahun Pelajaran</td>
                <td width="1%">:</td>
				<td><?= $setting['tp'] ?></td>
            </tr>
            <tr>
                <td >NIS / NISN</td>
                <td>:</td>
				<td><?= $siswa['nis'] ?> / <?= $siswa['nisn'] ?> </td>
				<td></td>
				<td>Bidang Keahlian</td>
                <td>:</td>
				<td><?= $kelas['bidang'] ?></td>
            </tr>
			<tr>
                <td>Tempat, Tanggal Lahir</td>
                <td>:</td>
				<td><?= $siswa['t_lahir'] ?>, <?= $siswa['tgl_lahir'] ?></td>
				<td></td>
				<td>Program Keahlian</td>
                <td>:</td>
				<td><?= $kelas['program'] ?></td>
            </tr>
			<tr>
                <td></td>
                <td></td>
				<td></td>
				<td></td>
				<td>Paket Keahlian</td>
                <td>:</td>
				<td><?= $kelas['paket'] ?></td>
            </tr>
        </table>
       <?php else: ?>
	    <table style="margin-left: 20px;margin-right:10px;font-size:11px"  width="100%">
            <tr>
                <td width="18%">Nama Siswa</td>
                <td width="1%">:</td>
				<td><?= $siswa['nama'] ?></td>
				<td width="7%"></td>
				<td width="18%">Tahun Pelajaran</td>
                <td width="1%">:</td>
				<td><?= $setting['tp'] ?></td>
            </tr>
            <tr>
                <td >NIS / NISN</td>
                <td>:</td>
				<td><?= $siswa['nis'] ?> / <?= $siswa['nisn'] ?> </td>
				<td></td>
				 <td>Tempat, Tanggal Lahir</td>
                <td>:</td>
				<td><?= $siswa['tempat_lahir'] ?>, <?= $siswa['tgl_lahir'] ?></td>
            </tr>
			
			
        </table>
	   
	   <?php endif; ?>
        <br>
 
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                        <th width="5%" style="text-align:center" rowspan="2">NO</th>
                        <th style="text-align:center" rowspan="2" colspan="2">MATA DIKLAT</th>
                       <th style="text-align:center" colspan="6">PEROLEHAN NILAI</th>
					     <th style="text-align:center" colspan="2">UJIAN SEKOLAH</th>
						   <th style="text-align:center;width:5%" rowspan="2">UJIAN NASIONAL</th>
						   </tr>
						   <tr>
						    <th style="text-align:center;width:5%">I</th>
						   <th style="text-align:center;width:5%">II</th>
						    <th style="text-align:center;width:5%">III</th>
							 <th style="text-align:center;width:5%">IV</th>
							  <th style="text-align:center;width:5%">V</th>
							   <th style="text-align:center;width:5%">VI</th>
							    <th style="text-align:center;width:6%">Teori</th>
								 <th style="text-align:center;width:6%">Praktek</th>
							   
                    </tr>
                </thead>
                <tbody>
			    
                    
                        <?php
                        $q1 = mysqli_query($koneksi, "SELECT * FROM mapel_ijazah  group by kelompok order by kelompok");
                        $no = 0;
                        while ($kelompok = mysqli_fetch_array($q1)) {
							
                       if($kelompok['kelompok']=='A'){
						{$gra="A. Muatan Nasional";}
						}elseif($kelompok['kelompok']=='B'){
						{$gra="B. Muatan Kewilayahan";}
						}elseif($kelompok['kelompok']=='C1'){
						{$gra="C1. Dasar Bidang Keahlian";}
						}elseif($kelompok['kelompok']=='C2'){
						{$gra="C2. Dasar Program Keahlian";}
						}elseif($kelompok['kelompok']=='C3'){
						{$gra="C3. Kompetensi Keahlian";}
						
						}
						
						 if($kelompok['kelompok']=='A'){
						{$grade="A. Umum";}
						}elseif($kelompok['kelompok']=='B'){
						{$grade="B. Umum";}
						}elseif($kelompok['kelompok']=='C1'){
						{$grade="C. Peminatan";}
						
						}
					
						 if($kelompok['kelompok']=='A'){
						{$grades="A. Umum";}
						}elseif($kelompok['kelompok']=='B'){
						{$grades="B. Muatan Lokal";}
						}
						
                        ?>
                            <tr>
                                <td colspan="12">
								<?php if($setting['jenjang']=='SMK'){ ?>
								<b>  <?= $gra ?></b>
								<?php }elseif($setting['jenjang']=='SMA'){ ?>
								<b>  <?= $grade ?></b>
								<?php }else{ ?>
								<b>  <?= $grades ?></b>
								<?php } ?>
								</td>
                            </tr>
                           
							<?php
							 $query = mysqli_query($koneksi, "SELECT * FROM mapel_ijazah where kelompok='$kelompok[kelompok]' GROUP BY kode order by urut ");
							while ($mapel = mysqli_fetch_array($query)) {
								
							$smt1P = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]' and semester='1'"));
							$smt1K = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]' and semester='1'"));
							$smt2P = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='2'"));
							$smt2K = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='2'"));
							$smt3P = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='3'"));
							$smt3K = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='3'"));
							$smt4P = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='4'"));
							$smt4K = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='4'"));
							$smt5P = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='5'"));
							$smt5K = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='5'"));
							$smt6P = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='6'"));
							$smt6K = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_skl  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]'  and semester='6'"));
							
							$us = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_ujian  WHERE nis='$siswa[nis]' and mapel='$mapel[kode]' "));
									
								
							 $no++;
		                  ?>
		                  <tr>
						  <td style="text-align:center;" rowspan="2"><?= $no ?></td>
						  <td  rowspan="2"> &nbsp;<?= $mapel['namamapel'] ?></td>
						 
						  
						  <td width="8%">&nbsp;Pengetahuan</td>
						  <td style="text-align:center;" >
						    <?php if($smt1P['nilai_p']<>0){ ?>
						  <?= number_format($smt1P['nilai_p'],2) ?> 
						  <?php } ?>
						  </td>
                           <td style="text-align:center;" >
						   <?php if($smt2P['nilai_p']<>0){ ?>
						   <?= number_format($smt2P['nilai_p'],2) ?> 
						   <?php } ?>
						   </td>
						   <td style="text-align:center;" >
						     <?php if($smt3P['nilai_p']<>0){ ?>
						   <?= number_format($smt3P['nilai_p'],2) ?> 
						   <?php } ?>
						   </td>
						   <td style="text-align:center;" >
						     <?php if($smt4P['nilai_p']<>0){ ?>
						   <?= number_format($smt4P['nilai_p'],2) ?> 
						   <?php } ?>
						   </td>
						   <td style="text-align:center;" >
						     <?php if($smt5P['nilai_p']<>0){ ?>
						   <?= number_format($smt5P['nilai_p'],2) ?>
						   <?php } ?>
						   </td>
						   <td style="text-align:center;" > 
						     <?php if($smt6P['nilai_p']<>0){ ?>
						   <?= number_format($smt6P['nilai_p'],2) ?>
						   <?php } ?>
						   </td>
						   
						   <td rowspan="2" style="text-align:center;" > 
						    <?php if($us['teori']<>0){ ?>
						   <?= number_format($us['teori'],2) ?>
						    <?php } ?>
						   </td>
						   <td rowspan="2" style="text-align:center;" >
						    <?php if($us['praktek']<>0){ ?>
						   <?= number_format($us['praktek'],2) ?>
						    <?php } ?>
						   </td>
						   <td rowspan="2" style="text-align:center;" > </td>
						  </tr>
						  
						  <tr>
						  <td>&nbsp;Keterampilan</td>
						  <td style="text-align:center;" >
						   <?php if($smt1K['nilai_k']<>0){ ?>
						  <?= number_format($smt1K['nilai_k'],2) ?>
						   <?php } ?>
						  </td>
						   <td style="text-align:center;" >
						    <?php if($smt2K['nilai_k']<>0){ ?>
						   <?= number_format($smt2K['nilai_k'],2) ?> 
							<?php } ?>
						   </td>
						   <td style="text-align:center;" > 
						    <?php if($smt3K['nilai_k']<>0){ ?>
						   <?= number_format($smt3K['nilai_k'],2) ?>
						   <?php } ?>
						   </td>
						   <td style="text-align:center;" >
						    <?php if($smt4K['nilai_k']<>0){ ?>
						   <?= number_format($smt4K['nilai_k'],2) ?> 
						   <?php } ?>
						   </td>
						   <td style="text-align:center;" >
						    <?php if($smt5K['nilai_k']<>0){ ?>
						   <?= number_format($smt5K['nilai_k'],2) ?> 
						   <?php } ?>
						   </td>
						   <td style="text-align:center;" >
						    <?php if($smt6K['nilai_k']<>0){ ?>
						   <?= number_format($smt6K['nilai_k'],2) ?> 
						   <?php } ?>
						   </td>
						    
				              </tr>
							  
						<?php }} ?>
                        
               <tr><td colspan="12" height="2px"></td></tr>
			   
			    <?php 
				$jm11 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='1'"));
				$jm12 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='1'")); 
				$rt11 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='1'"));
				$rt12 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='1'")); 
				$jumlah1 = $jm11['jumlah'] + $jm12['jumlah'];
				$rata1 = ($rt11['jumlah'] + $rt12['jumlah'])/2;
				?>
				<?php 
				$jm21 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='2'"));
				$jm22 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='2'")); 
				$rt21 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='2'"));
				$rt22 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='2'")); 
				$jumlah2 = $jm21['jumlah'] + $jm22['jumlah'];
				$rata2 = ($rt21['jumlah'] + $rt22['jumlah'])/2;
				?>
				<?php 
				$jm31 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='3'"));
				$jm32 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='3'")); 
				$rt31 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='3'"));
				$rt32 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='3'")); 
				$jumlah3 = $jm31['jumlah'] + $jm32['jumlah'];
				$rata3 = ($rt31['jumlah'] + $rt32['jumlah'])/2;
				?>
				<?php 
				$jm41 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='4'"));
				$jm42 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='4'")); 
				$rt41 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='4'"));
				$rt42 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='4'")); 
				$jumlah4 = $jm41['jumlah'] + $jm42['jumlah'];
				$rata4 = ($rt41['jumlah'] + $rt42['jumlah'])/2;
				?>
				<?php 
				$jm51 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='5'"));
				$jm52 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='5'")); 
				$rt51 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='5'"));
				$rt52 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='5'")); 
				$jumlah5 = $jm51['jumlah'] + $jm52['jumlah'];
				$rata5 = ($rt51['jumlah'] + $rt52['jumlah'])/2;
				?>
				<?php 
				$jm61 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='6'"));
				$jm62 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='6'")); 
				$rt61 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_p) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='6'"));
				$rt62 = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai_k) AS jumlah FROM nilai_skl  WHERE nis='$ids' AND semester='6'")); 
				$jumlah6 = $jm61['jumlah'] + $jm62['jumlah'];
				$rata6 = ($rt61['jumlah'] + $rt62['jumlah'])/2;
				?>
				
				<?php $praktek = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(praktek) AS jumlah FROM nilai_ujian  WHERE nis='$ids'")); ?>
				<?php $teori = mysqli_fetch_array(mysqli_query($koneksi, "SELECT SUM(teori) AS jumlah FROM nilai_ujian  WHERE nis='$ids'")); ?>
				
				<?php $praktekUS = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(praktek) AS rata FROM nilai_ujian  WHERE nis='$ids'")); ?>
				<?php $teoriUS = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(teori) AS rata FROM nilai_ujian  WHERE nis='$ids'")); ?>
							
					 							
                        <tr>
						<th style="text-align:center;" colspan="3" > Jumlah Nilai </th>
						  <th style="text-align:center;width:5%"><?= number_format($jumlah1) ?></th>
						    <th style="text-align:center;width:5%"><?= number_format($jumlah2) ?></th>
							  <th style="text-align:center;width:5%"><?= number_format($jumlah3) ?></th>
							    <th style="text-align:center;width:5%"><?= number_format($jumlah4) ?></th>
								  <th style="text-align:center;width:5%"><?= number_format($jumlah5) ?></th>
								    <th style="text-align:center;width:5%"><?= number_format($jumlah6) ?></th>
									 <th style="text-align:center;width:6%"><?= number_format($teori['jumlah'],2) ?></th>
									  <th style="text-align:center;width:6%"><?= number_format($praktek['jumlah'],2) ?></th>
									   <th style="text-align:center;"></th>
						      </tr>
                    <tr>
						<th style="text-align:center;" colspan="3" > Rata-rata Nilai </th>
						  <th style="text-align:center;width:5%"><?= number_format($rata1,2) ?></th>
						    <th style="text-align:center;width:5%"><?= number_format($rata2,2) ?></th>
							  <th style="text-align:center;width:5%"><?= number_format($rata3,2) ?></th>
							    <th style="text-align:center;width:5%"><?= number_format($rata4,2) ?></th>
								  <th style="text-align:center;width:5%"><?= number_format($rata5,2) ?></th>
								    <th style="text-align:center;width:5%"><?= number_format($rata6,2) ?></th>
									 <th style="text-align:center;width:6%"><?= number_format($teoriUS['rata'],2) ?></th>
									  <th style="text-align:center;width:6%"><?= number_format($praktekUS['rata'],2) ?></th>
									   <th style="text-align:center;"></th>
						     
							 </tr>
			   </tbody>
            </table>
           <br>
		   <?php if($setting['jenjang']=='SMK'): ?>
		  <center> <b>PRAKTEK KERJA LAPANGAN</b></center>
			  <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                        <th width="5%" style="text-align:center">NO</th>
                        <th style="text-align:center">NAMA MITRA DU / DI</th>
                       <th style="text-align:center;width:20%">LOKASI </th>
					     <th style="text-align:center;width:10%">LAMA</th>
						   <th style="text-align:center;">KETERANGAN</th>
						   </tr>
						  
                </thead>
                <tbody>
				<?php
				$no=0;
				$queryQ = mysqli_query($koneksi, "SELECT * FROM pkl WHERE nis='$ids' ");
				while ($pkl = mysqli_fetch_array($queryQ)) {
					$no++;
					?>
					<tr>
					 <td style="text-align:center;width:5%" ><?= $no ?> </td>
						 <td style="text-align:center;" ><?= $pkl['mitra'] ?> </td>
						  <td style="text-align:center;" ><?= $pkl['lokasi'] ?> </td>
						   <td style="text-align:center;" ><?= $pkl['lama'] ?> </td>
						   <td style="text-align:center;" ><?= $pkl['ket'] ?> </td>
					</tr>
				<?php } ?>
				<tr>
					 <td style="text-align:center;width:5%" >2 </td>
						 <td style="text-align:center;" > </td>
						  <td style="text-align:center;" > </td>
						   <td style="text-align:center;" > </td>
						   <td style="text-align:center;" > </td>
					</tr>
			     </tbody>
            </table> 
			<?php endif; ?>
			 <br><br>
			 <table style="margin-left: 80px;" width="90%">
		<tr>
               <td style="text-align: center" width="33.3%"></td>
                 <td style="text-align: center" width="33.3%"></td>
                <td width="33.3%"><?= $setting['kecamatan'] ?>, <?= $skl['tgl_surat'] ?></td>
            </tr>
			</table>
			<table style="margin-left: 80px;" width="90%">
            <tr>
                <td></td>
			<td></td>
				 <td>
				<?php if($setting['jenis']=='REGULER'): ?>
                    <p>Kepala Sekolah,</p>
					<?php else: ?>
					<p>Kepala PKBM,</p>
					<?php endif; ?>
				 
				<br><br><br>
				 <b><u><?= $setting['kepsek'] ?></u> </b>
				 <p>NIP. <?= $setting['nip'] ?></p>
				 </td>
            </tr>
			
		<tr>
               <td width="33.3%"></td>
                 <td  width="33.3%"> </td>
                <td  width="33.3%"></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', 'portrait');
$dompdf->render();
$dompdf->stream("Transkip_" . $siswa['nama'] . ".pdf", array("Attachment" => false));
exit(0);
?>