<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
include ("../navigation/header.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")));

$emp_id = $_GET['emp_id'];
include('../include/period_select_date.php');	

$table_name2 = $_SESSION['db_prefix']."_employee";
$employee_query = "SELECT emp_first_name, emp_last_name, emp_group FROM $table_name2 WHERE emp_id ='".$emp_id."' ";
$employee_result = $con->query($employee_query);
$row = mysqli_fetch_assoc($employee_result);
$a0 = $row['emp_first_name'];
$a1 = $row['emp_last_name'];
$a42 = $row['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 = $con->query($time_query);
$row = mysqli_fetch_assoc($time_result);
$recorded_time = $row['recorded_time'];
$required_time = $row['required_time'];

if ($required_time=='') {$required_time = 1;}
$attendance = ($recorded_time / $required_time) * 100;
}
 
$table_name = $_SESSION['db_prefix']."_employee_supply_lines";
$display_query = "SELECT emp_supply_no, issue_date, status, emp_id, store_item_id, quantity, price FROM $table_name WHERE issue_date >= '".$start."' AND issue_date <='".$end."' AND emp_id = '".$emp_id."' ";
$display_result = $con->query($display_query);
$display_num = mysqli_num_rows($display_result); 

$table_name2 = $_SESSION['db_prefix']."_employee";
$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$emp_id."' ";
$employee_result = $con->query($employee_query);
$row = mysqli_fetch_assoc($employee_result);
$emp_name = $row['emp_first_name'].' '.$row['emp_last_name'];
?> 

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<link rel="stylesheet" type="text/css" href="../css/tab.css" />

<!--jscript-->
</script> 


</head>


<body>
<?php

include ("../navigation/hr_sidebar.php");
$page_name = "HR-main";
include ("../navigation/access.php");
$current_page = "issued_employee_list.php";
if ($permission_num==1) {
?>
<div class="main_frame">
<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>

<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?date=') {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>
     </div>
     
<div class="tab_middle_frame">     

<?php
$page='issued_employee_list.php';
$reference_name='emp_id';
$reference=$emp_id;
$reference_name_2='';
$reference_2='';
$reference_name_3='';
$reference_3='';
include('../include/period_select_block_small.php');
?>



<div class="page_inside_frame" style="width:650px;">
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
								{"iDataSort": 3},
								{"bVisible": false},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}					
								 ]
				} );
			} );
		</script>    	
<table width="650" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="34">No</th>
		  <th width="34">&nbsp;</th>
		  <th width="58">Date</th>
		  <th width="25">&nbsp;</th>
		  <th width="166">Item</th>
		  <th width="21" >Status</th>
          <th width="69" >Quantity</th>
		  <th width="56" >Price</th>
		  <th width="86" >Returnable</th>
		  <th width="95" >Not returnable</th>
		  </tr>
	</thead>
	<tbody>
  <?php
    $b5_tot=0;
	$b6_tot=0;
    while($row = $display_result->fetch_assoc()) {
		$b0 = $row["emp_supply_no"];
		$b1 = $row["issue_date"];
		$b2 = $row["store_item_id"]; 
		$b3 = $row["quantity"]; 	
		$b4 = $row["price"];
		$b7 = $row["status"];
		 
		 	$table_name = $_SESSION['db_prefix']."_store_items";
			$name_query = "SELECT item_name, subCategory, location, minimumStock, price, returnable  FROM $table_name WHERE store_item_id = '".$b2."'  ";
			$name_result = $con->query($name_query);
			$row = mysqli_fetch_assoc($_result);
			$b2a = $row["item_name"];
			$b2a = $row["item_name"];
			$a1a = $row["item_name"];
			$a1b = $row["subCategory"];
			$a1c = $row["location"];
			$a1d = $row["minimumStock"];
			$a1e = $row["returnable"]; 
			$a1f = $row["price"];
		 
		 if ($a1e=='yes') { 		
		 		$b5 = $b3 * $b4;
		 		$b5_tot = $b5_tot + $b5;
				$b6='';
		 }
		 else {
			 	$b6 = $b3 * $b4;
		 		$b6_tot = $b6_tot + $b6;
				$b5='';
		 }
		 
		 	
		 
		 $itemTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Item name:</td><td width=175>".$a1a."</td></tr><tr><td>Group</td><td>".$a1b."</td></tr><tr><td>Location:</td><td>".$a1c."</td></tr><tr><td>Min. stock</td><td>".$a1d."</td></tr><tr><td>Price</td><td>".$a1f."</td></tr></table><b>Click for details</b>";
		?>
		<tr >
		  <td ><?php if ($b7=='S') { ?><a href="../store/employee_supply.php?emp_supply_no=<?php echo $b0 ?>" onMouseover="ddrivetip('<?php echo $itemTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $b0 ?></a><?php } ?>
               <?php if ($b7=='R') { ?><a href="../store/employee_return.php?emp_supply_no=<?php echo $b0 ?>" onMouseover="ddrivetip('<?php echo $itemTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $b0 ?></a><?php } ?></td>
		  <td ><?php echo $b0 ?></td>
		  <td ><?php echo date("d-m-Y", strtotime($b1 ))?></td>
		  <td ><?php echo $b1 ?></td>
		  <td align="left"><a href="../store/store_item_display.php?store_item_id=<?php echo $b2 ?>" onMouseover="ddrivetip('<?php echo $itemTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $b2a ?></a></td>
		  <td align="left"><?php echo $b7 ?></td>
			<td align="left"><?php echo $b3?></td>
			<td align="right"><?php echo number_format($b4, 2, '.', ',') ?></td>
			<td align="right"><?php if ($b5!='') {echo number_format($b5, 2, '.', ','); } ?></td>
			<td align="right"><?php if ($b6!='') {echo number_format($b6, 2, '.', ','); } ?></td>
			</tr>
		     
		<?php
		$i++; 
	}
	?>
    </tbody>
    <tfoot>
    <tr >
		  <td colspan="8" align="right" >Total: &nbsp;&nbsp;</td>
		  <td align="right"><?php echo number_format($b5_tot, 2, '.', ',') ?>&nbsp;</td>
		  <td align="right"><?php echo number_format($b6_tot, 2, '.', ',') ?></td>
		  </tr>
        </tfoot>
	
</table>
		
</div>	
</div>    
</div>
</div>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "store/store_main.php";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>