<?php
// Skrip berikut ini adalah skrip yang bertugas untuk meng-export data tadi ke excell
session_start();
$con=mysqli_connect('localhost','tapa8991_resto','resto@1305','tapa8991_dbrest');
include 'hari.php';


$dari=$_POST['id'];
$tahun=$_POST['tahun'];
$bulan=$_POST['bln'];
//$dari=8;
$unm=mysqli_query($con,"Select name from userinfo where userid='$dari';");
$name=mysqli_fetch_array($unm);

//$sampai=2018;
//$dariagen=strtoupper($_POST['cabang']);

//
IF ($bulan=='1') $nbln="Januari";
IF ($bulan=='2') $nbln="Februari";
IF ($bulan=='3') $nbln="Maret";
IF ($bulan=='4') $nbln="April";
IF ($bulan=='5') $nbln="Mei";
IF ($bulan=='6') $nbln="Juni";
IF ($bulan=='7') $nbln="Juli";
IF ($bulan=='8') $nbln="Agustus";
IF ($bulan=='9') $nbln="September";
IF ($bulan=='10') $nbln="Oktober";
IF ($bulan=='11') $nbln="November";
IF ($bulan=='12') $nbln="Desember";

?>
 <meta charset="utf-8" />
    <meta name="robots" content="noindex, nofollow">
	<!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> -->
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	
    
    <meta name="description" content="IBS" />
    <meta name="author" content="Suroto" />
<div align='center'>
<font color='blue' size='4' ><b>Bulan : <?php echo $nbln.'-'.$tahun ?> /  <?php echo $name['name']; ?> </b></font>
</div>
<hr>
<table align='center' cellpadding="2" border='1'>

	<tr>
		<th>No</th>
		<th>Tanggal</th>
		<th>Hari</th>
		<th>Masuk</th>
		<th>Pulang</th>
		
<?php

$dtgl=$bulan;
	$tampil = "SELECT date(checktime) as tgl,dayname(checktime) as hari from checkinout
			WHERE  MONTH(checktime)='$bulan' AND YEAR(CHECKTIME)='$tahun' GROUP BY DATE(checktime);";

	
$no=1;	
$sql0 = mysqli_query($con,$tampil);  
while($data = mysqli_fetch_assoc($sql0)) {
$hari=$data['hari'];
$hr=$data['tgl'];	
/*$new = date('l, F d, Y', strtotime($Today));*/
if ($hari=="Sunday") {
	$hariindo="Minggu";
}elseif ($hari=="Monday") {
	$hariindo="SENIN";
}elseif ($hari=="Tuesday") {
	$hariindo="SELASA";
}elseif ($hari=="Wednesday") {
	$hariindo="RABU";
}elseif ($hari=="Thursday") {
	$hariindo="KAMIS";
}elseif ($hari=="Friday") {
	$hariindo="JUMAT";
}elseif ($hari=="Saturday") {
	$hariindo="SABTU";	
}		
		echo "<tr >";
		echo "<td align='center' >".$no."</td>";	
		echo "<td align='center'  >".$data['tgl']."</td>";	
		echo "<td align='center' >".$hariindo."</td>";	
	
		$dt = "SELECT TIME_FORMAT(checktime,'%H:%i') AS a from checkinout
		where date(checktime)='$hr'   and userid='$dari' and hour(checktime)<12 group by date(checktime) order by time(checktime) limit 1;";
		$sql2 = mysqli_query($con,$dt);  
		$dt1 = mysqli_fetch_assoc($sql2);
			
		$dtp = " SELECT TIME_FORMAT(checktime,'%H:%i')  AS b from checkinout
		where date(checktime)='$hr'   and userid='$dari' and hour(checktime)>15 group by date(checktime) order by time(checktime) desc limit 1;";
		$sql21 = mysqli_query($con,$dtp);  
		$dt11 = mysqli_fetch_assoc($sql21);
		echo "<td style='text-align: center'> ".($dt1['a'])."</td>";
		echo "<td style='text-align: center'> ".($dt11['b'])."</td>";

		
		echo "</tr>";
$no++;			
}		
	?>


</table>
