<?php
date_default_timezone_set('Asia/Kolkata'); 
//echo $date = date("Y-m-d", time());
include ('../config.php');
@session_start();
@$user_id1=$_SESSION['user_id1'];
@$idvfied1=$_SESSION['idverified1'];
@$namevfied1=$_SESSION['namevfied1'];
if(!isset($_SESSION['user_id1'])){
	header("Location: index.php");
}

$timeout = 60 * 60 * 24 * 365;
$s_name = session_name();
if(isset( $_COOKIE[ $s_name ] )) {
  setcookie( $s_name, $_COOKIE[ $s_name ], time() + $timeout, '/' );
}

$sel1=mysqli_query($conn,"select * from hr_dump where empid='".@$user_id1."'");
$fetch1=mysqli_fetch_array($sel1);

$queryFR=mysqli_query($conn,"select * from tracker where Functional_Reporting='$fetch1[Employee_Number]'");
$dataFR=mysqli_fetch_array($queryFR);

$queryFR=mysqli_query($conn,"select * from emp_leave where Functional_Reporting='$fetch1[Employee_Number]'");
$dataFR=mysqli_fetch_array($queryFR);

$connemp=mysqli_query($conn,"select * from hr_dump where empid='".$_GET['empid']."'");
$empdata=mysqli_fetch_array($connemp);
?>

<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>View Attendance</title>
	<style>
		.tds {
			min-width: 150px;
			max-width: 200px;
			white-space: normal;
			overflow-wrap: break-word;
			word-break: break-word;
		}
	</style>
	<?php	include ('header.php');	?>
	
	<div id="appCapsule">
        <div class="section wallet-card-section pt-1">
            <div class="wallet-card">
				<?php	include ('include/wallet-balance.php');	?>
 
				
				
				<div class="row text-center mb-4">
					<div class="col-md-12 col-sm-12 text-center">
						<a href="team-dr-bh-all.php" class="btn btn-info">Go Back</a>
					</div>
					<h6 class="text-center"><?php echo $empdata['Employee_Full_Name']; ?> : <?php echo date('Y-M'); ?> Month</h6>
					<div class="table">
						<table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
							<thead>
							<tr class="small">
								<th>Date</th>
								<th>Office In - Out</th> 
								<th>In Location</th>
								<th>Out Location</th>
							</tr>
							</thead>
							<tbody>
							<?php //echo date("Y-m-01")."<br>"; echo date("Y-m-t")."<br>";
							$sn = date('Y-m-01');		$tn = date('Y-m-d');
							while( $sn <= $tn )
							{
								$cmsql=mysqli_query($conn,"select * from ams_final where empid='".$_GET['empid']."' AND OfficeDate LIKE '$sn'");
								$cmdata=mysqli_fetch_array($cmsql);
							?>
							<tr class='small'>
								<td><?php echo $sn; ?></td>
								<td><?php echo $cmdata['InTime']." - ".$cmdata['OutTime']; ?></td>
								<td class="tds"><?php echo $cmdata['location']; ?></td>
								<td><?php echo $cmdata['out_location']; ?></td>
							</tr>
							<?php
								//if ( $sn == date('M-t') )	{	exit;	}
								$sn++;	}
							?>
							</tbody>
						</table>
					</div>
					
					<h4>Attendance: <?php	$now = new DateTime();
						$firstDayOfCurrentMonth = new DateTime($now->format('Y-m-01'));
						$lastDayOfPreviousMonth = $firstDayOfCurrentMonth->sub(new DateInterval('P1D'));
						$lastM = $lastDayOfPreviousMonth->format('Y-m');
						echo $monthP = $lastDayOfPreviousMonth->format('M-Y');
					?></h4>
			
					<div class="table">
						<table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
							<thead>
							<tr class="small">
								<th>Date</th>
								<th>Office In - Out</th>
								<th>In Location</th>
								<th>Out Location</th>
							</tr>
							</thead>
							<tbody> 
							<?php		
							$query="select * from ams_final_hr where empid='".$_GET['empid']."' AND OfficeDate LIKE '%$lastM%' ORDER BY OfficeDate ASC";
							$result=mysqli_query($conn,$query);
							while($data=mysqli_fetch_assoc($result))
							{
							@$sn++;
							?>
							<tr class="small">
								<td><?php echo $data['OfficeDate'] ?></td>
								<td><?php echo $data['InTime']." - ".$data['OutTime']; ?></td>
								<td class="tds"><?php echo htmlspecialchars($data['location']); ?></td>
								<td><?php echo $data['out_location']; ?></td>
							</tr>
							<?php    }    ?>
							</tbody>
						</table>
					</div>
				</div>
				not wokring in mobile
				
            </div>
        </div>
	
	<?php	include ('include/copyright.php');	?>
	</div>
	
	<?php	include ('footer.php');	?>