<?php
include('../common/db_connection.php');
$Mainclass=new DB_Controller();
$Mainclass->Employee_COOKIE_Check();
$check_attendance=$Mainclass->Num_rows_Check('attendance_master','Attendance_Date',date('Y-m-d'));
if($check_attendance=="")
{
?>
<script>
//window.location.href="attendance.php";
</script>
<?php
}
?>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
<title>Attendance History</title>


<!--[if lt IE 10]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
      <![endif]-->

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="Admindek Bootstrap admin template made using Bootstrap 4 and it has huge amount of ready made feature, UI components, pages which completely fulfills any dashboard needs." />
<meta name="keywords" content="bootstrap, bootstrap admin template, admin theme, admin dashboard, dashboard template, admin template, responsive" />
<meta name="author" content="colorlib" />

 <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet"><link href="https://fonts.googleapis.com/css?family=Quicksand:500,700" rel="stylesheet">

<link rel="stylesheet" type="text/css" href="files/bower_components/bootstrap/css/bootstrap.min.css">

<link rel="stylesheet" href="files/assets/pages/waves/css/waves.min.css" type="text/css" media="all">

<link rel="stylesheet" type="text/css" href="files/assets/icon/feather/css/feather.css">

<link rel="stylesheet" type="text/css" href="files/assets/icon/themify-icons/themify-icons.css">

<link rel="stylesheet" type="text/css" href="files/assets/icon/icofont/css/icofont.css">

<link rel="stylesheet" type="text/css" href="files/assets/icon/font-awesome/css/font-awesome.min.css">

<link rel="stylesheet" type="text/css" href="files/assets/css/style.css">
<link rel="stylesheet" type="text/css" href="files/assets/css/pages.css">



<script language="javascript">
//==========for clock ===============//
function startTime()
{
 
  var date=new Date();
  var p=date.toLocaleTimeString();
  //alert(p);
  document.getElementById("clock").innerHTML=p;
  setTimeout(function(){startTime()},500);
}
//==========for clock ===============//
</script>




 <style type="text/css">
#tooltip
{
text-align: center;
color: #fff;
background: #111;
position: absolute;
z-index: 100;
padding: 5px 10px;
font-size:10px !important;
line-height:12px !important;
}

#tooltip:after /* triangle decoration */
{
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #111;
content: '';
position: absolute;
left: 50%;
bottom: -10px;
margin-left: -10px;
}

#tooltip.top:after
{
border-top-color: transparent;
border-bottom: 10px solid #111;
top: -20px;
bottom: auto;
}

#tooltip.left:after
{
left: 10px;
margin: 0;
}

#tooltip.right:after
{
right: 10px;
left: auto;
margin: 0;
}

.message_maindiv{
float:left;
height:auto;
padding:15px;
background-color:#fff8e6;
text-align:left;
font-size:12px;
color:#503a27;
}

.time_border{
 border-right:1px solid #263544;
}

.table>thead>tr>th {
       border-bottom-color: #CCC; border-left-color: #CCC;
}


@media only screen and (max-width:480px){
.time_border{
 border-right:0px solid #0066FF;
}
}



</style>
        
<script>
function isNumberKey(evt) 
{
	var charCode = (evt.which) ? evt.which : event.keyCode; 
	if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) 
	{
		return false;
	} 
	else 
	{
		return true;
	} 
} 

</script> 
       
 <script>
function page_submit()
{
	var pan=$("#pan").val();
	
	var Error=0;
	if(pan=='')
	{
		$("#pan").css('border-bottom','1px solid red');
		Error=1;
	}
	if(pan!='')
	{
		$("#pan").css('border-bottom','1px solid #ccc');
	}
	if(Error==1)
	{
		return false;
	}
	if(Error==0)
	{
		$("#main").submit();
	}
}
</script>   
</head>
<body>



<div id="pcoded" class="pcoded">
<div class="pcoded-overlay-box"></div>
<div class="pcoded-container navbar-wrapper">

<?php include('register-top-header.php'); ?>





<div class="pcoded-main-container">
<div class="pcoded-wrapper">

<?php include('register-side-menu.php'); ?>



<div class="pcoded-content">

<div class="page-header card">
<div class="row align-items-end">
<div class="col-lg-8">
<div class="page-header-title">

<div class="d-inline">
<h5 style="text-transform:uppercase; font-size:25px; font-weight:600;">Attendance History</h5>

</div>
</div>
</div>

</div>
</div>

<div class="pcoded-inner-content">
<div class="main-body">
<div class="page-wrapper">

<div class="page-body">
<div class="row">
<div class="col-sm-12">

<div class="card">

<div class="card-block">



<div class="row">
<?php
$condition="'".$_COOKIE['Payroll_Emp_Attendance']."'";
if($_POST['month']!="")
{
	$condition.=" AND MONTH(Attendance_Date) = '".$_POST['month']."'";
}
if($_POST['year']!="")
{
	$condition.=" AND YEAR(Attendance_Date) = '".$_POST['year']."'";
}
$ALL_attendances=$Mainclass->Fetch_All_datas("attendance_master","Emp_Temp_Id",$condition,"","","Attendance_Date");
?>
<form method="post">
<div class="col-sm-12" style="margin-bottom:20px;">
<div class="row">

<div class="col-sm-4"><div class="form-group row">

<div class="col-sm-12">
<select name="month" id="month" class="form-control fill">
<option value="">Select Month</option>
<?php
for($i=date('m')+1;$i<=date('m')+12;$i++)
{
if($i<=12)
{
$j=$i;
}
if($i>12)
{
$j=$i-12;
}
?>
<option value="<?php echo $j;?>" <?php if($_POST['month']==$j){ echo 'selected';}?>><?php echo date("F", mktime(0,0,0,$j,10));?></option>
<?php
}
?>
</select>

</div>
</div></div>

<div class="col-sm-4"><div class="form-group row">

<div class="col-sm-12">
<select name="year" id="year" class="form-control fill">
<option value="">Select Year</option>
<?php
for($i=date('Y')-1;$i<=date('Y')+2;$i++)
{
?>
<option value="<?php echo $i;?>" <?php if($_POST['year']==$i){ echo 'selected';}?>><?php echo $i;?></option>
<?php
}
?>
</select>

</div>
</div></div>

<div class="col-sm-4"><div class="form-group row">

<div class="col-sm-12">
<input name="submit" type="submit" value="SUBMIT" class="btn waves-effect waves-light btn-inverse btn-square" style="padding:5px 19px; width:100%;">

</div>
</div></div>

</div>

</div>
</form>


<div class="col-sm-12">

<div class="table-responsive">
<table class="table" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCC" style="border-collapse:collapse;">
<thead >
<tr>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">SLN</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">DAY</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">DATE</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">P / A</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">TIME IN</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">TIME OUT</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">LATE BY</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">LOGOUT TYPE</th>
<th style="border-top:0px; font-weight:800; background-color:#f1f1f1;">Action</th>
</tr>
</thead>
<tbody>
<?php
if($_POST['year']!="" && $_POST['month']!="")

        {

			$Y=$_POST['year'];
			$m=$_POST['month'];
			$Selected_Date=$Y."-".$m."-01";
			$endofday=date("t",strtotime($Selected_Date));
		}

		else

		{

			$Y=date('Y');
			$m=date('m');
			$endofday=date("t");
		}

		/*if($_POST['month']!="")

		{

			

		}

		else

		{

			
		}*/



	

for($d=1; $d<=$endofday; $d++)
{

$time=mktime(12, 0, 0, $m, $d, $Y);          
if (date('m', $time)==$m)
$date=date('d-m-Y', $time);
$list=date('Y-m-d', $time);
$Day=date('l', $time);
//echo $_COOKIE['Payroll_Emp_Attendance'];
$condition="Emp_Temp_Id='".$_COOKIE['Payroll_Emp_Attendance']."' and Attendance_Date='".$list."'";		
$check_attendance=$Mainclass->Present_Num_rows_Check('attendance_master',$condition);
if($check_attendance>0)
{
$fetch_attn=$Mainclass->application_fetch('attendance_master',$condition);
}
$condition_holiday="Holiday_Date='".$list."'";		
$check_holiday=$Mainclass->Present_Num_rows_Check('holiday_client_master',$condition_holiday);
$condition_roster="Emp_Temp_Id='".$_COOKIE['Payroll_Emp_Attendance']."' and ".$d."_Day='OFF'";
$check_off=$Mainclass->Off_Num_rows_Check('roster_plan_master',"".$d."_Day",$condition_roster);		
$expiry_date = date($d.'-m-Y');
$today = date('d-m-Y');
$interval = $expiry_date - $today;

$condition_approve="Request_Date='".$list."' and Temp_Emp_Id='".$_COOKIE['Payroll_Emp_Attendance']."'";		
$check_approve=$Mainclass->Present_Num_rows_Check('attendance_request_master',$condition_approve);
$fetch_status=$Mainclass->application_fetch('attendance_request_master',$condition_approve);

?>
	<tr>
	<th scope="row" ><?php echo $d;?></th>
    <th><?php echo $Day;?></th>
    <th><?php echo $date;?></th>
    <th><?php if($check_attendance>0){echo 'Present';}else if($check_holiday>0){echo 'Holiday';}else if($check_off>0){echo "OFF";}else{echo 'Absent';} ?></th>
    <th><?php  if($check_attendance>0){echo date('h:i a',strtotime($fetch_attn['In_Time']));}?></th>
    <th><?php if($fetch_attn['Out_Time']!="0000-00-00 00:00:00" && $check_attendance>0){echo date('h:i a',strtotime($fetch_attn['Out_Time']));}?></th>
    <th><?php 

$actual_in_time=$fetch_attn['In_Time'];
$roster_in_time=$fetch_attn['Attendance_Date']." ".$fetch_attn['Roster_In_Time'].":00";		
	$dateDiff = intval((strtotime($actual_in_time)-strtotime($roster_in_time))/60);

									$hours = intval($dateDiff/60);
									$minutes = $dateDiff%60;
									$hrs=str_replace('-','',$hours);
									$min=str_replace('-','',$minutes);
									if($fetch_attn['Late_Count']==0)
									{
									if($hours!=0 && $check_attendance>0)
									{
										echo "Early by ".$hrs." Hrs ";
									}
									if($minutes!=0 && $check_attendance>0)
									{
										echo "Early by ".$min." Mins";
									}}
									else
									{
										if($hours!=0 && $check_attendance>0)
									{
										echo "Late by ".$hrs." Hrs ";
									}
									if($minutes!=0 && $check_attendance>0)
									{
										echo "Late by ".$min." Mins";
									}}?></th>
    <th><?php if($check_attendance>0){echo $fetch_attn['Out_With'];}?></th>
	<th><?php if($check_approve==0){ ?><a class="various" data-fancybox-type="iframe" href="non_attn_reason.php?d=<?php echo base64_encode($list); ?>" title="Request Attendance" data-toggle="tooltip"><?php if($check_attendance>0){echo '';}else if($check_holiday>0){echo '';}
	else if($check_off>0){echo "";}else{if($interval > -7 && $interval < 0 && date('m')==$m) {echo "Request Attendance";}} ;?></a><?php }else{echo $fetch_status['Status'];} ?></th>
	</td>
		

	</td>
	</tr>
<?php
	}
?>	

</tbody>
</table>
</div>

</div>


 
  

</div>







</div>
</div>










</div>
</div>
</div>

</div>
</div>
</div>
</div>

<div id="styleSelector">
</div>
</div>
</div>
</div>
</div>


<!--[if lt IE 10]>
<div class="ie-warning">
    <h1>Warning!!</h1>
    <p>You are using an outdated version of Internet Explorer, please upgrade <br/>to any of the following web browsers to access this website.</p>
    <div class="iew-container">
        <ul class="iew-download">
            <li>
                <a href="http://www.google.com/chrome/">
                    <img src="../files/assets/images/browser/chrome.png" alt="Chrome">
                    <div>Chrome</div>
                </a>
            </li>
            <li>
                <a href="https://www.mozilla.org/en-US/firefox/new/">
                    <img src="../files/assets/images/browser/firefox.png" alt="Firefox">
                    <div>Firefox</div>
                </a>
            </li>
            <li>
                <a href="http://www.opera.com">
                    <img src="../files/assets/images/browser/opera.png" alt="Opera">
                    <div>Opera</div>
                </a>
            </li>
            <li>
                <a href="https://www.apple.com/safari/">
                    <img src="../files/assets/images/browser/safari.png" alt="Safari">
                    <div>Safari</div>
                </a>
            </li>
            <li>
                <a href="http://windows.microsoft.com/en-us/internet-explorer/download-ie">
                    <img src="../files/assets/images/browser/ie.png" alt="">
                    <div>IE (9 & above)</div>
                </a>
            </li>
        </ul>
    </div>
    <p>Sorry for the inconvenience!</p>
</div>
<![endif]-->


<script type="text/javascript" src="files/bower_components/jquery/js/jquery.min.js"></script>
<script type="text/javascript" src="files/bower_components/jquery-ui/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="files/bower_components/popper.js/js/popper.min.js"></script>
<script type="text/javascript" src="files/bower_components/bootstrap/js/bootstrap.min.js"></script>

<script src="../files/assets/pages/waves/js/waves.min.js" type="text/javascript"></script>

<script type="text/javascript" src="files/bower_components/jquery-slimscroll/js/jquery.slimscroll.js"></script>

<script type="text/javascript" src="files/bower_components/modernizr/js/modernizr.js"></script>
<script type="text/javascript" src="files/bower_components/modernizr/js/css-scrollbars.js"></script>

<!--<script src="../../../../cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js" type="text/javascript"></script>
<script src="../../../../cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js" type="text/javascript"></script>-->
<script type="text/javascript" src="files/assets/pages/form-validation/validate.js"></script>

<script type="text/javascript" src="files/assets/pages/form-validation/form-validation.js"></script>
<script src="files/assets/js/pcoded.min.js" type="text/javascript"></script>
<script src="files/assets/js/vertical/vertical-layout.min.js" type="text/javascript"></script>
<script src="files/assets/js/jquery.mCustomScrollbar.concat.min.js" type="text/javascript"></script>
<script type="text/javascript" src="files/assets/js/script.js"></script>



<link rel="stylesheet" type="text/css" href="source/jquery.fancybox.css" media="screen" />
<script type="text/javascript" src="lib/jquery.mousewheel.pack.js"></script>

<script type="text/javascript" src="source/jquery.fancybox.pack.js"></script>

<style type="text/css">
	.fancybox-custom .fancybox-skin {
		box-shadow: 0 0 50px #222;
	}
</style> 
<script>
$(document).ready(function() {
	$(".various").fancybox({
		maxWidth	: 500,
		maxHeight	: 450,
		fitToView	: true,
		width		: '100%',
		height		: '100%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
		 
	}); 
});

</script>



</body>


</html>
<script>startTime();</script>