<?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['tgl'];
//$dari=8;


$hari = date('l', strtotime($dari));
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";
}

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

//
IF ($dari=='1') $nbln="Januari";
IF ($dari=='2') $nbln="Februari";
IF ($dari=='3') $nbln="Maret";
IF ($dari=='4') $nbln="April";
IF ($dari=='5') $nbln="Mei";
IF ($dari=='6') $nbln="Juni";
IF ($dari=='7') $nbln="Juli";
IF ($dari=='8') $nbln="Agustus";
IF ($dari=='9') $nbln="September";
IF ($dari=='10') $nbln="Oktober";
IF ($dari=='11') $nbln="November";
IF ($dari=='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'>
<b>Hari/Tanggal : <?php echo $hariindo.' / '.$dari; ?></b>
</div>
<hr>
<table align='center' cellpadding="2">

	<tr>
		<th>No</th>
		<th>Kode</th>
		<th>Keterangan</th>
		<th>Masuk</th>
		<th>Pulang</th>
		
<?php

$dtgl=$dari;



//$total ="SELECT sum(jumlah) as total FROM transaksi WHERE (Tgl BETWEEN '$dari' AND '$sampai') and agen='$dariagen';";

//$sql1 = mysql_query($total);  
//$jtotal= mysql_fetch_array($sql1);
// $pjtotal= number_format($jtotal[total]);

$subcb=mysqli_query($con,"select deptid,deptname from departments where deptid<>'1';");
while($dcb = mysqli_fetch_assoc($subcb)) {
			echo "<tr>";
			echo "<td><font color='blue'><u>".$dcb['deptid']."</u></font></td>";
			echo "<td><font color='blue'><u>".$dcb['deptname']."</u><font></td>";
			echo "</tr>";
			
			

	$tampil = " SELECT a.userid,b.name,(day(checktime)) as mtgl,date_format(checktime,'%H:%m:%s') as nil,date_format(checktime,'%d-%m-%Y') as tgl from checkinout a 
			left join userinfo b on a.userid=b.userid
			where date(a.checktime)='$dtgl' and  b.DEFAULTDEPTID='$dcb[deptid]' group by a.userid order by a.userid ;";
	
$no=1;	
$sql0 = mysqli_query($con,$tampil);  
while($data = mysqli_fetch_assoc($sql0)) {
	
		$hr=$data['mtgl'];	
		echo "<tr >";
		echo "<td align='center'>".$no."</td>";	
		echo "<td align='center'>".$data['userid']."</td>";	
		echo "<td align='left'>".$data['name']."</td>";	
	
	
	
			$dt = " SELECT TIME_FORMAT(checktime,'%H:%i') AS a from checkinout
			where checktime>='$dtgl'   and userid='$data[userid]' and hour(checktime)<12 group by userid order by 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 checktime>='$dtgl'   and userid='$data[userid]' and hour(checktime)>15 group by userid order by checktime desc limit 1;";
			$sql21 = mysqli_query($con,$dtp);  
			$dt11 = mysqli_fetch_assoc($sql21);
			echo "<td style='text-align: left'> ".($dt1['a'])."</td>";
			echo "<td style='text-align: right'> ".($dt11['b'])."</td>";
		echo "</tr>";
		
$no++;		
	
}				
}		
	?>


</table>
