<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--style sheets--> 
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<!--jscript-->

<?php
include('../include/session.php');

$store_item_id = $_GET['store_item_id'];	

$table_name = $_SESSION['db_prefix']."_employee_supply_lines";
$supply_query = "SELECT emp_id, store_item_id, SUM(quantity) AS summed_quantity, SUM(price) AS summed_price, issue_date FROM $table_name  WHERE store_item_id = '".$store_item_id."' GROUP BY emp_id ORDER BY emp_id DESC";
$supply_result = mySQL_query($supply_query); 
$supply_num = mysql_num_rows($supply_result);


$table_name = $_SESSION['db_prefix']."_store_items";
$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
$name_result = mySQL_query($name_query);
$store_item_name = mysql_result($name_result, 0, "item_name");

?>
<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 ("../navigation/header.php");
$page_name = "HR-main";
include ("../navigation/access.php");

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

<div class="main_frame">

<div class="page_head_frame">
      <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Store items issues to employees</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
      
<div class="page_inside_frame">
  <!--jscript-->
  <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, "asc" ]],
					"aoColumns": [
					     		{"bSortable": true},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bSortable": true},
								]
				} );
			} );
		</script>
       <label class="label_std"> Issues of <?php echo $store_item_name ?></label>
<table width="643" id="scroll_table" class="data_display" >
  <thead>
  <tr>
    <th>Employee</th>
    <th align="center">Quantity</th>
    <th align="center">Last issued</th>
    <th align="center">Cost</th>
    </tr>
    </thead>
<?php 

$i=0;
$a4_total=0;
while ($i<$supply_num) {
	$a1 = mysql_result($supply_result, $i, "emp_id");
			$table_name2 = $_SESSION['db_prefix']."_employee";
			$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$a1."' ";
			$employee_result = mySQL_query($employee_query);
			$employee_num = mysql_num_rows($employee_result);	
			$a1a = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
	$a2 = mysql_result($supply_result, $i, "summed_quantity");
	$a3 = mysql_result($supply_result, $i, "issue_date");
	$a4 = mysql_result($supply_result, $i, "summed_price");
	$a4_total = $a4_total + $a4;
	
	$employeeTT = "<label class=tip_text_label>".$a1a."</label><br><label class=tip_click_label>Click for details</label>";  
			
	?>

  <tr>
    <td width="299" align="left"><a href="../hr_module/employee_details.php?emp_id=<?php echo $a1?>" onMouseover="ddrivetip('<?php echo $employeeTT ?>  ', 150)"; onMouseout="hideddrivetip()"><?php echo $a1a ?></a></td>
    <td width="66" align="center"><a href="issued_employee_list.php?emp_id=<?php echo $a1 ?>&date=0&single=1&store_item_id=<?php echo $store_item_id ?>" onMouseover="ddrivetip('Click for history', 150)"; onMouseout="hideddrivetip()"><?php echo $a2 ?></a></td>
    <td width="186" align="center"><?php echo date("d-m-Y", strtotime($a3)) ?></td>
    <td width="72" align="right"><?php echo number_format($a4, 2, '.', ',') ?></td>
    </tr>
  
  <?php
  $i++;
}
?>
<tfoot>
<tr>
    <td colspan="3" align="right">Totals:</td>
    <td align="right"><?php echo number_format($a4_total, 2, '.', ',') ?></td>
    </tr>
  </tfoot>
</table>
</div>
</div>
</div>

<?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'); ?>


</body>
</html>