<?php 

include '../koneksi.php';
session_start();
date_default_timezone_set('Asia/Jakarta');

//$waktu 	= 	date('Y-m-d H:i:s'); 
$kd_pegawai  	= 	$_POST['kd'];
$date			=	$_POST['periode'];
$nama 			=	$_POST['nama'];


$tahun = date("Y", strtotime($date)); //Mengambil tahun dari form
$bulan = date("m", strtotime($date)); //Mengambil tbulan dari form

$tanggal = cal_days_in_month(CAL_GREGORIAN, $bulan, $tahun);

									
									
									
?>
<!DOCTYPE html>
<html>
<head>
</head>
<!-- Setting CSS bagian header/ kop -->
<style type="text/css">
  table.page_header {width: 1020px; border: none; background-color: #DDDDFF; border-bottom: solid 1mm #AAAADD; padding: 2mm }
  table.page_footer {width: 1020px; border: none; background-color: #DDDDFF; border-top: solid 1mm #AAAADD; padding: 2mm}
</style>

<!-- Setting Margin header/ kop -->
<!-- Setting CSS Tabel data yang akan ditampilkan -->
<style type="text/css">
 .tabel2 {
  border-collapse: collapse;
  margin-left: 20px;    
}
.tabel2 th, .tabel2 td {
  padding: 5px 5px;
  border: 1px solid #000000;
}
.tabelatas{

  margin-left: 20px;
}

div.kanan {
 width:300px;
 float:right;
 margin-left:250px;
 margin-top:141px;
}

div.kiri {
  width:300px;
  float:left;
  margin-left:20px;
  display:inline;
}

</style>
<body>
	<table>
		<tr>
			<th rowspan="3"><img src="../gambar/depan/pnselayar.png" style="width:90px;height:100px" /></th>
				<td align="center" style="width: 520px;"><font style="font-size: 18px"><b>MAHKAMAH AGUNG REPUBLIK INDONESIA <br> PENGADILAN NEGERI SELAYAR </b></font>
					<br>Jl. KELAPA NO. 8 BENTENG KAB. KEPULAUAN SELAYAR 92812 <br> TELP. 0414-21030 FAX 0414-21778 </td>
		</tr>
	</table>
  
	<hr>
	<p align="center" style="font-weight: bold; font-size: 18px;"><u>LAPORAN DETAIL PRESENSI</u></p>

	<div class="isi" style="margin: 0 auto;">

  
	
    <table class="tabelatas">
      <tr>
        <td style="text-align: left; width=80px;  "><b>Periode </b></td>  
        <td style="text-align: left; "><b>: </b> <?php echo $tahun." - ".$bulan ; ?></td>           
      </tr>
      <tr>
        <td style="text-align: left; width=80px;  "><b>Nama </b></td>   
        <td style="text-align: left; "><b>: </b> <?php echo $nama ?> </td>       
      </tr>

    </table>
    
	<br>
    <table class="tabel2">      
      <thead>
        <tr>
          <td style="text-align: center; "><b>No.</b></td>        
          <td style="text-align: center; "><b>Tanggal</b></td>
          <td style="text-align: center; "><b>Jam Masuk</b></td>
          <td style="text-align: center; "><b>Jam Pulang</b></td>
		  <td style="text-align: center; "><b>Keterangan</b></td>
                                              
        </tr>
      </thead>
	  
      <tbody>
									<?php 
									function tglind($x){
										$ref=array('','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
										$aref=array('Minggu','Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu');
										$bongkar=explode("-",$x);
										$angka=intval($bongkar[1]);
										$bulanind=$ref[$angka];
										$hari=date_format(date_create($x),"w");
										return "$aref[$hari], $bongkar[2] $bulanind $bongkar[0]";
									}
									
									$a = date("$tahun-$bulan-01") ;
									
									for ($i=1; $i < $tanggal+1; $i++) {
										if($i<10){
										$tgl="0".$i;
										}else{
										$tgl=$i;
									}
									?>									
          <tr>
            <td style="text-align: center; width=10px; "><?php echo $i;?></td> 
			<td style="text-align: left; width=150px; font-size: 12px;"><?php echo tglind($a++);?></td>			
            <td style="text-align: left; width=150px; font-size: 12px;"><?php 
											
											$absen = mysqli_query($koneksi,"SELECT * FROM absensi WHERE kd_pegawai ='$kd_pegawai' and tanggal='$tahun-$bulan-$tgl'");
											$lap_absen = mysqli_num_rows($absen);
											$lap_absen_isi = mysqli_fetch_array ($absen);
												
											if (empty ($lap_absen)) {
													echo '-';
												} else {
													echo $lap_absen_isi['masuk'];
												}
											
											?></td>
            <td style="text-align: left; width=150px; font-size: 12px;"> <?php 
											$absen = mysqli_query($koneksi,"SELECT * FROM absensi WHERE kd_pegawai ='$kd_pegawai' and tanggal='$tahun-$bulan-$tgl'");
											$lap_absen = mysqli_num_rows($absen);
											$lap_absen_isi = mysqli_fetch_array ($absen);
												
											if (empty ($lap_absen)) {
													echo '-';
												} else {
													echo $lap_absen_isi['pulang'];
												}
												?>
												</td>
            <td style="text-align: center; width=150px; font-size: 12px;"> </td>            
          </tr>
       
		
		 <?php }?>
      </tbody>
  </table>
  
 <div class="kanan">
  <p> </p>
  <p>Mengetahui :<br>Petugas Kepegawaian</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <b><p><u>__________________________</u><br>NIP:</p></b>
  <br>
  <br>
  <br>
</div>

<script>
		window.print();
</script>
</body>
</html>
<!-- Memanggil fungsi bawaan HTML2PDF -->

