<!--Notice: (c)2013 This page is part of the management program for Tlhomeso Timbers, Gaborone, 
and developed by Customized Software (Pty) Ltd, Gaborone, Botswana. 
Customized Software holds the copyright on the source code on this and all other pages in the 
management program. For more info contact Customized Software on email: info@bwcustomized.com-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "HR-employee list";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/hr_sidebar.php");
?>
<?php


$day = date("Y-m-d");

	
	
$table_name2 = $_SESSION['db_prefix']."_time_record";
$late_query = "SELECT emp_id, clock_in, clock_out, status, reason  FROM $table_name2 WHERE date = '".$day."' AND status = 'L' ";
$late_result = mySQL_query($late_query);
$late_num = mysql_num_rows($late_result);

$table_name2 = $_SESSION['db_prefix']."_time_record";
$absent_query = "SELECT emp_id, clock_in, clock_out, status, reason  FROM $table_name2 WHERE date = '".$day."' AND status = 'A' ";
$absent_result = mySQL_query($absent_query);
$absent_num = mysql_num_rows($absent_result);

$table_name2 = $_SESSION['db_prefix']."_time_record";
$record_query = "SELECT emp_id, clock_in, clock_out, status, reason  FROM $table_name2 WHERE date = '".$day."' AND status = '' ";
$record_result = mySQL_query($record_query);
$record_num = mysql_num_rows($record_result);

?>
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
</head>
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php include ('../include/tooltip.php'); ?>

<div class="main_frame">
  <table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="62" valign="top" ><div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Employees Today</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
        <br />
<br />
</td> <!--center of tableMain-->
</tr>
<tr>
<td align="left"> <div class="scroll_frame"> Late today
  <table width="769" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "  >
    <tr>
      <th class="sortable-text">name</th>
      <th class="sortable-text">department</th>
      <th class="sortable-date-dmy">clock-in</th>
      <th class="sortable-text">reason</th>
      <th class="sortable-text">&nbsp;</th>
    </tr>
    <?php 
$i=0;

while ($i<$late_num) {
	
	$a1 = mysql_result($late_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name, department  FROM $table_name WHERE emp_id = $a1 ";
		$employee_result = mySQL_query($employee_query);
        $a1a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		$a7 = mysql_result($employee_result, 0, "department");
		$a2 = mysql_result($late_result, $i, "clock_in");
		   $hours =  floor($a2/60); 
		   $mins =   $a2 % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a2a = $hours . ":" . $mins ;
		
		$start = date("Y-m-d", strtotime("-1 month") ) ;
		$table_name2 = $_SESSION['db_prefix']."_time_record";
		$late_check_query = "SELECT  emp_id  FROM $table_name2 WHERE emp_id = '".$a1."' and status = 'L' AND date >= '".$start."' ";
		$late_check_result = mySQL_query($late_check_query);
		$late_check_num = mysql_num_rows($late_check_result);
		if ($late_check_num>0) {
		  $a10  = $late_check_num;
		}
		else {
			$a10="";
		}
	
	$a6 = mysql_result($late_result, $i, "reason");
  
	?>
    <tr>
      <td width="155" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>"><?php echo $a1a ?></a></td>
      <td width="155" align="left"><?php echo $a7 ?></td>
      <td width="111" align="left"><?php  echo $a2a ?></td>
      <td width="247" align="left"><?php echo $a6 ?></td>
      <td width="77" align="left"><a href="late_absent_individual_list.php?emp_id=<?php echo $a1 ?>&start=<?php echo $start ?>&date=0" onMouseover="ddrivetip('This employee has been <?php echo $a10 ?> times late in the past month. Click to see records.', 150)"; onMouseout="hideddrivetip()" > <?php echo $a10 ?></a></td>
    </tr>
    <?php
  $i++;
}
?>
</table>
  <div align="left">
    <label class="label_end">end of list</label>
  </div>
</div> 
  </td>
  </tr>
  <tr>
  <td align="left">
<div class="scroll_frame">
Absent today
  <table width="771" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "  >
  <tr>
    <th class="sortable-text">name</th>
    <th class="sortable-text">department</th>
    <th class="sortable-text">reason</th>
    </tr>
<?php 
$i=0;

while ($i<$absent_num) {
	
	$b1 = mysql_result($absent_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name, department  FROM $table_name WHERE emp_id = $a1 ";
		$employee_result = mySQL_query($employee_query);
        $b1a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		$b7 = mysql_result($employee_result, 0, "department");
	$b6 = mysql_result($absent_result, $i, "reason");
	?>
  
  <tr>
    <td width="179" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>"><?php echo $b1a ?></a></td>
    <td width="124" align="left"><?php echo $b7 ?></td>
    <td width="444" align="left"><?php echo $b6 ?></td>
    </tr>
  <?php
  $i++;
}
?>

</table>
<div align="left"><label class="label_end">end of list</label></div>
</div></td>
</tr>
<tr>
  <td align="left">
<div class="scroll_frame">
Not recorded
  <table width="771" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "  >
  <tr>
    <th class="sortable-text">name</th>
    <th class="sortable-text">department</th>
    <th class="sortable-text">&nbsp;</th>
    </tr>
<?php 
$i=0;

while ($i<$record_num) {
	
	$a1 = mysql_result($record_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name, department  FROM $table_name WHERE emp_id = $a1 ";
		$employee_result = mySQL_query($employee_query);
        $a1a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		$a7 = mysql_result($employee_result, 0, "department");
	
	?>
  
  <tr>
    <td width="179" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>"><?php echo $a1a ?></a></td>
    <td width="124" align="left"><?php echo $a7 ?></td>
    <td width="444" align="left">&nbsp;</td>
    </tr>
  <?php
  $i++;
}
?>

</table>
<div align="left"><label class="label_end">end of list</label></div>
</div></td>
</tr>
</table>  <!--end of tableMain-->
  
</div>
</body>
<?php } else {
$_SESSION['denied_return'] = "hr_module/employee_list.php";	
include ("../navigation/hr_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
</html>