<?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>
	<link rel="icon" type="image/png" href="images/mhb.jpeg">
			<?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>Data Absensi Karyawan</h3>
				<h5>"menampilkan absensi setiap karyawan per hari ini, dan dapat mengizinkan sesuai kondisi"</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 MASUK 
							</th>
							<th>
								TERLAMBAT
							</th>
							<th>
								IZIN 
							</th>
							<th>
								TIDAK MASUK 
							</th>
							<th>
								PILIHAN 
							</th>
						</tr>
					</thead>
					<tbody>

						<?php
						$total += $jumlah;
						
						//$q = "SELECT * 
						
						//FROM absensi.att_log
						//INNER JOIN data_karyawan_mhb.data_karyawan ON
						//absensi.att_log.pin =
						//data_karyawan_mhb.data_karyawan.nik
						//";
						
						//$q = "SELECT * FROM data_karyawan";
						$tanggalhariini = date('2020-08-27');
						//echo "aaaa".$tanggalhariini;
						
						//$q = "SELECT * FROM att_log WHERE DATE(scan_date) = '$tanggalhariini'";
						// $d = "SELECT TIME(scan_date) AS jam_masuk, pin FROM att_log";
						$q = "SELECT pin, TIME(scan_date) AS jam_masuk, scan_date AS scan FROM att_log WHERE DATE(scan_date) = '$tanggalhariini'";
						//echo "aaaa".$q;
						$res = mysqli_query($conn2, $q);
						$z=1;
						
						

						
						
						while ($row = mysqli_fetch_assoc($res)) 
						{
							$ini = '0';
							 //$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))
							//{
								?>
							<tr>
							    <td>
									<?php
									echo $z;
									$z = $z + 1;
									?>
								</td>
								<td>
									<?php
									echo $row["pin"];
									$pins = $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"];
									$namas = $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"];
									$departemens = $rowi["departement"];
									?>
									
								</td>
								<td>
									<?php
									echo $row["jam_masuk"];
									$tanggals = $row['scan'];
									
									?>
									
									
								</td>
								<td>
									<?php
									////echo $row["lama_bekerja"];
									//$tanggalmasuk = $row["tanggal_masuk"];
									
									//date_default_timezone_set('Asia/Jakarta');
                                    //$awal = date_create($tanggalmasuk);
                                    //$akhir = date_create('');
                                    //$diff = date_diff($akhir,$awal);

                                    //echo '('.$diff->y . ' tahun-';
                                    //echo $diff->m . ' bulan-';
                                    //echo $diff->d . ' hari)';
									
									$jammasuk=$row["jam_masuk"];
							 if($jammasuk>='07:31:00')
							 {
								 ////////////////////////////untuk input data terlambat
								 if (isset($_REQUEST['submit']))
                                 {
                                       $p = "INSERT INTO data_terlambat (nik, nama, departemen, tanggal, total_jam_terlambat)
		                               VALUES 
			                           ('$pins','$namas','$departemens','$tanggals','$ini')";
                                       $insertQuery=mysql_query($insert);
                                  }
					
							 	//$insertTerlambat = "INSERT INTO data_terlambat (id_data_karyawan, id_att_log, terlambat) VALUES (" . $row['pin'];  "," . $row['id']; ", Tidak Terlambat)";
							 	//echo $insertTerlambat;
							 	//echo "Terlambat".$keterlambatan ;
								
								$jamterlambat = "07:31:00";
								$keterlambatan = $jammasuk - $jamterlambat;
								echo $keterlambatan ." jam" ."</br>";
								$pins = $row['pin'];
								$qmasuk= "SELECT TIME(scan_date) as waktu FROM att_log WHERE pin='$pins' AND MONTH(scan_date) = 8 AND TIME(scan_date) <='16:30:00' AND TIME(scan_date) >='07:31:01'";
								//echo "qjumlah ". $qmasuk;
								$ressjmlh = mysqli_query($conn2, $qmasuk);
								while($rowjml=mysqli_fetch_assoc($ressjmlh))
								{
									echo "jml : ". $rowjml['waktu'] . "</br>";
									$waktu1=strtotime($rowjml['waktu']);
									$waktu2=strtotime("07:31:00");
									echo "waktu1 : " . $rowjml['waktu'] . "</br>";
									echo "waktu2 : " ."07:31:00". "</br>";
									//$total = $rowjml['waktu'] - "07:32:53";
									
									 //menghitung selisih dengan hasil detik
        $diff    =$waktu1 - $waktu2;
        
        //membagi detik menjadi jam
        $jam    =floor($diff / (60 * 60));
        
        //membagi sisa detik setelah dikurangi $jam menjadi menit
        $menit    =$diff - $jam * (60 * 60);

        //menampilkan / print hasil
        //echo 'Hasilnya adalah '.number_format($diff,0,",",".").' detik<br /><br />';
        echo 'waktu terlambat : ' . $jam .  ' jam dan ' . floor( $menit / 60 ) . ' menit' . "</br>";
		$jumlah = strtotime($jam. ":" .floor( $menit / 60 ).":00");
		
		$coba = $jam .floor( $menit / 60 );
		echo "iiiiiiiini jam dan menit jadi satu ".$coba;			
		
        $ini += $coba;
		echo "/////".$ini;
		
		//////////////////////////////// coba penghitungan gaji
$gaji = '5000000';
$pembaian = $gaji / '10380';
$hasilgaji = $pembaian * $ini;
$totalgaji = $gaji - $hasilgaji;
echo "%%%%%%%%%%gaji ku :". $totalgaji;		
		
	
									
									
									//echo "sementara  : " . $total . "</br>";
								}
								$jumlah += $jumlah;
								echo "jumlah selisih  : " . date('H:i:s',$jumlah);	
								echo  "</br>";
								//echo "keterlambatan  : " . $total . "</br>";
								
								//echo "jammasuk". $row["jam_masuk"];
								$time1 = strtotime('07:31:00');
								$time2 = strtotime($jammasuk);
								$subTime = $time1 - $time2;
								$h = ($subTime/(60*60))%24;
								$m = ($subTime/60)%60;
								$s = ($subTime/60*60)%60;
								echo $m." minit\n";
								echo $s." detik\n";
								$jams = $keterlambatan.$m .$s;
								
								$total = $jams;
								echo "<br> total : ".$total;
								
							
								//$j = "INSERT INTO data_terlambat (nik, nama, departemen, tanggal, total_jam_terlambat) VALUES ('$pins','$namas','$departemens','$tanggals','$jams');
								
								
								//echo $jammasuk;
							 	//echo "belum terlambat";
								
								//function selisih($jammasuk,$jamterlambat)
								//{
									//list ($h,$m,$s) = explode(":",$jammasuk);
									//$dtAwal = mktime($h,$m,$s,"1","1","1");
									//list ($h,$m,$s) = explode(":",$jamterlambat);
									
									//$dtAkhir = mktime($h,$m,$s,"1","1","1");
									//$dtSelisih = $dtAkhir-$dtAwal;
									
									//$totalmenit=$dtSelisih/60;
									//$jam=explode(".",$totalmenit/60);
									//$sisamenit=($totalmenit/60)-$jam[0];
									//$sisamenit2=$sisamenit*60;
									
									//return "$jam[0] jam $sisamenit2 menit";
								//}
								//echo selisih($jammasuk,$jamterlambat);
								
							 }
							 else
							 {
								
							 	echo "Tidak terlambat";
							 	//echo "terlambat";
							 }
									
									?>
								</td>
								<td>
									<?php
									//echo $row["durasi_kontrak_bulan"];
									?>
								</td>
								<td>
									<?php
									//echo $row["akhir_kontrak"];
									?>
								</td>


								<td>
									<a href="izin.php?scan=<?php echo $row["scan"]; ?>">IZIN</a>

								</td>
							</tr>
						
						<?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>