<?php
include "koneksi.php";
if (!isset($_SESSION["UserID"])) {
	header("location:login.php?p=3");
}


?>
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="style.css">
<html>

<head>
	<title> PT. MULTI HIDRACHROME BALIKPAPAN </title>
	<?php
				include "part/menu2.php";
				?>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<?php
	include "part/jss.php";
	?>

</head>

<body>

	<div style="width:1280px; height:220px" class="container" >

		
			<div class="alert alert-info" style='background-color:#F8F8FF' href="#">
            <div style="display: block; margin-left: auto; margin-right: auto; width: 1000px;  height:100px;"><img style="width: 1000px;  height:180px;" src="images/hd.jpg"></div>
            <div>
                <center>
                    <h1>PT. MULTI HIDRACHROM BALIKPAPAN</h1>
					
                </center>
            </div>
            <div>
                <center>
                    <h4 >PROFESIONAL INFORMATION SYSTEM</h4>
                </center>
            </div>
        </div>


			<div class="alert alert-info" align='center' >
				<h3>Detail Keterlambatan</h3>
				<h5>"menampilkan detail keterlambatan setiap karyawan per bulan ini"</h5>
			 
				
				<?php
				//echo date('yy-m-d');
				?>
				<?php
				if (isset($_GET["p"])) {
					$p = $_GET["p"];
					if ($p == "1") {
				?>
						<div class="alert alert-primary">
							Data Karyawan berhasil ditambah!
						</div>
					<?php
					} else if ($p == "2") {
					?>
						<div class="alert alert-primary">
							Data Karyawan berhasil diupdate!
						</div>
					<?php
					} else if ($p == "3") {
					?>
						<div class="alert alert-primary">
							Data Karyawan berhasil dipecat!
						</div>
				<?php
					}
				}
				?>
				<table class="table table-bordered">
					<thead>
						<tr>
						    <th>
								NO 
							</th>
							<th>
								NIK 
							</th>
							<th>
								NAMA  
							</th>
							<th>
								DEPARTEMEN
							</th>
							<th>
							    JAM TELAT
							</th>
							<th>
							    TANGGAL TELAT
							</th>
						</tr>
					</thead>
					<tbody>
						<?php
						//$q = "SELECT * 
						
						//FROM absensi.att_log
						//INNER JOIN data_karyawan_mhb.data_karyawan ON
						//absensi.att_log.pin =
						//data_karyawan_mhb.data_karyawan.nik
						//";
						
						
						$tanggalhariini = date('2020-08-27');
						//$date=date("Y-m-d H:i:s");
						////$d = date_parse_from_format("Y-m-d", $date);
						//echo "bulan= " . $d["month"];
						//echo "tahun= " . $d["year"];
						//echo "aaaa".$tanggalhariini;
						$pin = $_GET['pin'];
						
						$d = '08';
						$s = '2020';
						//$q = "SELECT pin, TIME(scan_date) AS jam_masuk, scan_date AS scan FROM att_log WHERE MONTH(scan_date) =". $d['month'] . " AND YEAR(scan_date) =". $d['year'] . "  AND pin=$pin";
						$q = "SELECT pin, TIME(scan_date) AS jam_masuk, scan_date AS scan FROM att_log WHERE MONTH(scan_date) =". $d. " AND YEAR(scan_date) =". $s . "  AND pin=$pin";
						
						echo "aaaa".$q;
						
						
						
						$res = mysqli_query($conn2, $q);
						$z=1;
						
						

						
						
						while ($row = mysqli_fetch_assoc($res)) 
						{
							$datetime = $row['scan'];
							$time=strtotime($datetime);
							//echo "jam= ". date("H:i:s",$time); 
							
							if(date("H:i:s",$time) > "07:31:00" && date("H:i:s",$time) < "16:30:00")
							{
								//echo " telat"."</br>";
								//echo "</br>";
								?>
							<tr>
							    <td>
									<?php
									echo $z;
									$z = $z + 1;
									?>
								</td>
								<td>
									<?php
									echo $row["pin"];
									?>
								</td>
								<td>
									<?php
									//echo $row["nama_karyawan"];
									?>
									<?php
									$s = "SELECT * FROM data_karyawan WHERE nik=" .$row['pin'];
									//echo "pin karyawan" . $s;
                                    $resi = mysqli_query($conn,$s);
                                    $rowi = mysqli_fetch_array($resi);
									echo $rowi["nama_karyawan"];
									?>
								</td>
								<td>
									<?php
									$s = "SELECT * FROM data_karyawan WHERE nik=" .$row['pin'];
									//echo "pin karyawan" . $s;
                                    $resi = mysqli_query($conn,$s);
                                    $rowi = mysqli_fetch_array($resi);
									echo $rowi["departement"];
									?>
									
								</td>
								<td>
									<?php
									echo $row["jam_masuk"];
									
									
									?>
									
									
								</td>
								<td>
									<?php
									echo $row["scan"];
									?>
								</td>
							</tr>
								<?php
								
							}
							else
							{
								if(date("H:i:s",$time) < "07:31:00" && date("H:i:s",$time) > "00:00:00")
								{
									//echo "tidak telat"."</br>";
									//echo "</br>";
								}
								else
								{
									//echo "pulang"."</br>";
								//echo "</br>";
								}
								
								
							}
							//echo "jam = ".$jam;
							//if(time('07:31:00') > )
							//{
								//echo "telat";
							//}//
							 //$jammasuk=$row["jam_masuk"];
							 //if($jammasuk>='07:31:00')
							 //{
							 	//$insertTerlambat = "INSERT INTO data_terlambat (id_data_karyawan, id_att_log, terlambat) VALUES (" . $row['pin'];  "," . $row['id']; ", Tidak Terlambat)";
							 	//echo $insertTerlambat;
							 	//echo "jam masuk terlambat :" . $jammasuk . "</br>";
							 	//echo "belum terlambat";
							 //}
							 //else
							 //{
								
							 	//echo "jam masuk tidak terlambat:" . $jammasuk . "</br>";
							 	//echo "terlambat";
							 //}
							//while ($row2 = mysqli_fetch_assoc($res2))
							//{
								?>
							
						
						<?php
						}
						//}
						?>
					</tbody>
				</table>

			</div>

    <script>
    $(document).ready(function()
	{
		 $('.table-bordered').DataTable();
	});
    </script>
	<center><h5 class="form-signin">Copyright &copy; <a href="#" data-toggle="modal" data-target="#contact">SatrioPringgondani</a></h5></center>  
</body>

</html>