<!DOCTYPE html>
<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" />
<link rel="stylesheet" type="text/css" href="../css/tab.css" />
<?php
include ("../navigation/header.php");
$emp_id = $_GET['emp_id'];

?>

<?php
$today = date("Y-m-d");
$firstday = date("Y").'-'.date("m").'-01';
$lastday = date("Y-m-d", mktime(0,0,0,date("m")+1,0,date("Y")));

	
$table_name2 = $_SESSION['db_prefix']."_employee";
$employee_query = "SELECT * FROM $table_name2 WHERE emp_id ='".$emp_id."' ";
$employee_result = mySQL_query($employee_query);
$employee_num = mysql_num_rows($employee_result);	


$a0 = mysql_result($employee_result, 0, "emp_first_name");
$a1 = mysql_result($employee_result, 0, "emp_last_name");
$a2 = mysql_result($employee_result, 0, "id_number");
$a3 = mysql_result($employee_result, 0, "birth_date");
$a4 = mysql_result($employee_result, 0, "employ_date");
$search_date = $a4;
$a6 = mysql_result($employee_result, 0, "gender");
$a7 = mysql_result($employee_result, 0, "bag_box");
$a8 = mysql_result($employee_result, 0, "box_no");
$a9 = mysql_result($employee_result, 0, "postal_place");
$a10 = mysql_result($employee_result, 0, "phys_address");
$a11 = mysql_result($employee_result, 0, "phys_place");
$a12 = mysql_result($employee_result, 0, "emergency_name");
$a13 = mysql_result($employee_result, 0, "emergency_phone");
$a14 = mysql_result($employee_result, 0, "position");
$a15 = mysql_result($employee_result, 0, "pay_period");
$a16 = mysql_result($employee_result, 0, "rate");

$a18 = mysql_result($employee_result, 0, "bank");
$a19 = mysql_result($employee_result, 0, "bank_branch");
$a20 = mysql_result($employee_result, 0, "bank_account");
$a21 = mysql_result($employee_result, 0, "clothing_size");
$a22 = mysql_result($employee_result, 0, "shoe_size");
$a23 = mysql_result($employee_result, 0, "cell");
$a24 = mysql_result($employee_result, 0, "phone");
$a25 = mysql_result($employee_result, 0, "email");
$a26 = mysql_result($employee_result, 0, "country");
$a27 = mysql_result($employee_result, 0, "marital_status");
$a28 = mysql_result($employee_result, 0, "department");
$a29 = mysql_result($employee_result, 0, "position");
$a30 = mysql_result($employee_result, 0, "employ_date");
$a31 = mysql_result($employee_result, 0, "end_employ_date");
$a32 = mysql_result($employee_result, 0, "expatriate");
$a33 = mysql_result($employee_result, 0, "permit_number");
$a34 = mysql_result($employee_result, 0, "permit_date");
$a35 = mysql_result($employee_result, 0, "nationality");
$a36 = mysql_result($employee_result, 0, "notes");
$a37 = mysql_result($employee_result, 0, "leave_days");
$a38 = mysql_result($employee_result, 0, "time_keeping");
$a39 = mysql_result($employee_result, 0, "time_zone");
$a40 = mysql_result($employee_result, 0, "emp_no");
$a41 = mysql_result($employee_result, 0, "premature_end_date");
$a42 = mysql_result($employee_result, 0, "emp_group");

if ($a42=='E') {
$table_name = $_SESSION['db_prefix']."_time_sheet";
$time_query = "SELECT SUM(check_out_min - check_in_min - lunch_min) AS recorded_time, SUM(time_zone_out - time_zone_in - lunch_period) AS required_time FROM $table_name WHERE emp_id ='".$emp_id."' AND attendance_date >= '".$firstday."' AND attendance_date <= '".$lastday."' ";


$time_result = mySQL_query($time_query);
$time_num = mysql_num_rows($time_result);
$recorded_time = mysql_result($time_result, 0, "recorded_time");
$required_time = mysql_result($time_result, 0, "required_time");
if ($required_time=='') {$required_time = 1;}

$attendance = ($recorded_time / $required_time) * 100;
if ($attendance<=0) {$attendance = 0; }
}

$table_name = $_SESSION['db_prefix']."_time_sheet";
$late_query = "SELECT  emp_id  FROM $table_name WHERE emp_id ='".$emp_id."' AND attendance_status = 'Late' AND attendance_date > '".$search_date."' ";
$late_result = mySQL_query($late_query);
$late_num = mysql_num_rows($late_result);

$table_name = $_SESSION['db_prefix']."_time_sheet";
$early_query = "SELECT  emp_id  FROM $table_name WHERE emp_id ='".$emp_id."' AND attendance_status = 'Early' ";
$early_result = mySQL_query($early_query);
$early_num = mysql_num_rows($early_result);

$table_name = $_SESSION['db_prefix']."_time_sheet";
$absent_query = "SELECT  emp_id  FROM $table_name WHERE emp_id ='".$emp_id."' AND attendance_status = 'Absent' ";
$absent_result = mySQL_query($absent_query);
$absent_num = mysql_num_rows($absent_result);

$table_name = $_SESSION['db_prefix']."_time_sheet";
$not_clocked_query = "SELECT  emp_id  FROM $table_name WHERE emp_id ='".$emp_id."' AND attendance_status = 'Not clocked' ";
$not_clocked_result = mySQL_query($not_clocked_query);
$not_clocked_num = mysql_num_rows($not_clocked_result);

$table_name = $_SESSION['db_prefix']."_warnings";
$warning_query = "SELECT  emp_id  FROM $table_name WHERE emp_id ='".$emp_id."' ";
$warning_result = mySQL_query($warning_query);
$warning_num = mysql_num_rows($warning_result);


$start = date("Y-m-d", strtotime("-3 month") ) ;



$table_name = $_SESSION['db_prefix']."_permissions";
$view_query = "SELECT access_id  FROM  $table_name  WHERE access_id ='". $_SESSION['access_id']."' AND page_name = 'HR-wages' ";
$view_result = mySQL_query($view_query);
$view_num = mysql_num_rows($view_result);
if ($view_num!=0) {
	$view='yes';
}
else {
$view='no';
}


//$table_name = $_SESSION['db_prefix']."_loans_lines_temp ";
//$total_query = "SELECT SUM(amount_debit) AS total_amount FROM $table_name WHERE loans_id = '".$_SESSION['loans_id']."' ";
//$total_result = mySQL_query($total_query);
//$total_amount = mysql_result($total_result, 0, "total_amount");

?>
<!--style sheets-->


<!--jscript-->
<script type="text/javascript" src="../jscript/tablesort.js"></script>
 
</head>
<body>
<?php

$page_name = "HR-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/hr_sidebar.php");
	$current_page = "employee_details.php"


?>
<div class="main_frame" style="height:auto">
  <div class="page_head_frame">
        <?php if ($a42=='E') { ?>
        <?php $attendance_label = "label_attendance_green" ;
		if ($attendance<96)  { $attendance_label = "label_attendance_orange" ; }
        if ($attendance<92)  { $attendance_label = "label_attendance_red" ; }?>
        <?php } ?>
        <table width="700" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="515"><label class="label_page_head">Employee</label>&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $a0." ".$a1 ?></label></td>
            <td width="165" align="center"><?php if ($a42=='E') { ?>attendance:<br />              <label class="<?php echo $attendance_label ?>"><?php echo number_format($attendance, 2, '.', ',')?> %</label> <?php } ?></td>
            </tr>
        </table>
      </div>
        <br />

<br />

<div class="page_middle_frame">

<div class="tab_button_holder_frame">
      <a href="employee_details.php?emp_id=<?php echo $emp_id ?>"><div class="<?php if ($current_page =='employee_details.php') {echo 'tab_button_active'; } else { echo 'tab_button'; }?>"><div align="center">Details</div></div></a>
      <a href="attendance_list.php?emp_id=<?php echo $emp_id ?>&date="><div class="<?php if ($current_page =='attendance_list.php') {echo 'tab_button_active'; } else { echo 'tab_button'; }?>"><div align="center">Attendance</div></div></a>
      <a href="employee_warnings_list.php?emp_id=<?php echo $emp_id ?>&date="><div class="<?php if ($current_page =='discipline_list.php') {echo 'tab_button_active'; } else { echo 'tab_button'; }?>"><div align="center">Discipline</div></div></a>
      <a href="issued_employee_list.php?emp_id=<?php echo $emp_id ?>&date="><div class="<?php if ($current_page =='issued_employee_list.php') {echo 'tab_button_active'; } else { echo 'tab_button'; }?>"><div align="center">Store issues</div></div></a>
      <a href="employee_details_edit.php?emp_id=<?php echo $emp_id ?>&date="><div class="<?php echo 'tab_button'; ?>"><div align="center">Edit</div></div></a>
     </div>

 <div class="tab_middle_frame">
<div class="page_inside_frame" style="width:650px;">
<div align="left">Personal details</div>
  <table width="650" id="table_details_display">
    <tr>
      <td width="128" height="25">First name:</td>
      <td width="126"><b><?php echo $a0?></b></td>
      <td width="112">Last name:</td>
      <td width="138"><b><?php echo $a1?></b></td>
      <td width="90">No:</td>
      <td width="134"><b><?php echo $a40?></b></td>
    </tr>
    <tr>
      <td height="25">Date of birth:</td>
      <td><b><?php echo date("d-m-Y", strtotime($a3 ))?></b></td>
      <td>id number:</td>
      <td><b><?php echo $a2?></b></td>
      <td>Marital status:</td>
      <td><b><?php echo $a27?></b></td>
    </tr>
    <tr>
      <td height="25">Nationality:</td>
      <td><b><?php echo $a35?></b></td>
      <td>Gender:</td>
      <td><b><?php echo $a6?></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>

<div class="page_inside_frame" style="width:650px;">
<div align="left">Contact details</div>
  <table width="650" id="table_details_display">
    <tr>
      <td width="120" height="25">Postal address:</td>
      <td width="110"><b><?php echo $a7." ".$a8?></b></td>
      <td width="109">Postal place:</td>
      <td width="122"><b><?php echo $a9?></b></td>
      <td width="84">Country:</td>
      <td width="117"><b><?php echo $a26?></b></td>
    </tr>
    <tr>
      <td height="25">Physical address:</td>
      <td><b><?php echo $a10?></b></td>
      <td>Place:</td>
      <td><b><?php echo $a11?></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="25">Phone:</td>
      <td><b><?php echo $a24?></b></td>
      <td>Cell:</td>
      <td><b><?php echo $a23?></b></td>
      <td>e-mail:</td>
      <td><b><?php echo $a25?></b></td>
    </tr>
    <tr>
      <td height="25">Emergency contact:</td>
      <td><b><?php echo $a12?></b></td>
      <td>Emergency cell:</td>
      <td><b><?php echo $a13?></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>


<div class="page_inside_frame" style="width:650px;">
<div align="left">Employment details</div>
  <table width="650" id="table_details_display">
    <tr>
      <td width="118" height="25">Employment date:</td>
      <td width="110"><b><?php echo date("d-m-Y", strtotime($a30 ))?></b></td>
      <td width="112">End contract:</td>
      <td width="113"><b>
        <?php if ($a31<'2030-01-01') { echo date("d-m-Y", strtotime($a31 )) ;} else { echo 'n/a';}?>
      </b></td>
      <td width="88">Premature end of contract:</td>
      <td width="121"><b>
        <?php if ($a41<$today) { echo '<font color=red>('.date("d-m-Y", strtotime($a41 )).')</font>';} else { echo 'n/a';}?>
      </b></td>
    </tr>
    <tr>
      <td height="25">Expatriate:</td>
      <td><b><?php echo $a32?></b></td>
      <td>Work permit:</td>
      <td><b><?php echo $a33?></b></td>
      <td>Expiry date:</td>
      <td><b><?php if ($a34!='2030-01-01') { echo date("d-m-Y", strtotime($a34 )); } ?></b></td>
    </tr>
    <tr>
      <td height="25">Position:</td>
      <td><b><?php echo $a29?></b></td>
      <td>Department:</td>
      <td><b><?php echo $a28?></b></td>
      <td>Time keeping:</td>
      <td><b><?php echo $a38?></b></td>
    </tr>
    <tr>
      <td height="25">Pay period:</td>
      <td><b><?php echo $a15?></b></td>
      <td>Rate:</td>
      <td><b><?php if ($view=='yes') {echo $a16; } else { echo '-----';} ?></b></td>
      <td>Time zone:</td>
      <td><?php echo '<b>'.$a39.'</b>' ?> </td>
    </tr>
    <tr>
      <td height="25">Leave:</td>
      <td colspan="2"><b><?php echo $a37?></b> days per month</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>

<div class="page_inside_frame" style="width:650px;">
<div align="left">Miscelaneous</div>
  <table width="650" id="table_details_display">
    <tr>
      <td width="124" height="25">Bank:</td>
      <td width="128"><b><?php echo $a18?></b></td>
      <td width="116">Branch:</td>
      <td width="139"><b><?php echo $a19?></b></td>
      <td width="90">Acc.number:</td>
      <td width="131"><b><?php echo $a20?></b></td>
    </tr>
    <tr>
      <td height="25">Clothing size:</td>
      <td><b><?php echo $a21?></b></td>
      <td>Shoe size:</td>
      <td><b><?php echo $a22?></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="25">Notes</td>
      <td colspan="5"><b><?php echo $a36?></b></td>
      </tr>
  </table>
</div>

<div class="page_inside_frame" style="width:650px;">
<div align="left">Other  recordings</div>
<table width="641" id="table_details_display">
  <tr>
    <td width="107" align="center">Late</td>
    <td width="146" align="center">Absent</td>
    <td width="166" align="center">Early</td>
    <td width="202" align="center">Warnings</td>
    </tr>
  <tr>
    <td align="center"><b><a href="late_list.php?emp_id=<?php echo $emp_id ?>&date=5&start=<?php echo $search_date ?>" onMouseover="ddrivetip('Click to see all late recordings', 150)"; onMouseout="hideddrivetip()"> <?php echo $late_num ?>  </a></b></td>
    <td align="center"><b><a href="absent_list.php?emp_id=<?php echo $emp_id ?>&date=5&start=<?php echo $search_date ?>" onMouseover="ddrivetip('Click to see all absent recordings', 175)"; onMouseout="hideddrivetip()"><?php echo $absent_num ?></a></b></td>
    <td align="center"><b><?php echo $early_num ?></b></td>
    <td align="center"><b><a href="warnings_individual_list.php?emp_id=<?php echo $emp_id ?>&date=5&start=<?php echo $search_date ?>" onMouseover="ddrivetip('Click to see all warnings', 150)"; onMouseout="hideddrivetip()"><?php echo $warning_num ?></a></b></td>
    </tr>
</table>

  <br>
  Store issues:
  <br>
  <table width="650" id="table_details_display">
    <tr>
      <td height="25">Click <a href="issued_employee_list.php?emp_id=<?php echo $emp_id ?>&date=5&start=<?php echo $search_date ?>&single=0"><b> here </b> </a> to see what was issued from the store.</td>
      </tr>
</table>
<br>
<?php
$table_name = $_SESSION['db_prefix']."_employee_notes";
$notes_query = "SELECT  note_date, note_text, entered_by FROM $table_name WHERE emp_id = '".$emp_id."'  ";
$notes_result = mySQL_query($notes_query);
$notes_num = mysql_num_rows($notes_result);
?>
Additional notes:
<table width="650" id="table_details_display">
  <tr>
    <td width="75">Date</td>
    <td width="86">Entered by</td>
    <td width="473">Note</td>
  </tr>
<?php
$i=0;
while ($i<$notes_num) {
	$note_date = mysql_result($notes_result, $i, "note_date");
	$note_text = mysql_result($notes_result, $i, "note_text");
	$entered_by = mysql_result($notes_result, $i, "entered_by");
?>	
  <tr>
    <td><?php echo date("d-m-Y", strtotime($note_date))  ?></td>
    <td><?php echo $entered_by ?></td>
    <td><?php echo $note_text ?></td>
  </tr>
  <?php
  $i++;
}
?>
</table>

</div>
</div>
</div> 
</div>
</body>
<?php } else {
$_SESSION['denied_return'] = "hr_module/hr_main.php?date=";	
include ("../navigation/hr_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</html>