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


$table_name = $_SESSION['db_prefix']."_employee_supply_lines";
$supply_query = "SELECT store_item_id, emp_id, SUM(quantity) AS summed_quantity, SUM(price) AS summed_price, issue_date FROM $table_name   GROUP BY store_item_id ORDER BY issue_date DESC";
$supply_result = mySQL_query($supply_query); 
$supply_num = mysql_num_rows($supply_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 ("../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>
<table width="643" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th>Store item</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;
$listTT_body='';
while ($i<$supply_num) {
	$a1 = mysql_result($supply_result, $i, "store_item_id");
			$table_name = $_SESSION['db_prefix']."_store_items";
			$name_query = "SELECT item_name, subCategory, location, minimumStock, maximumStock, price  FROM $table_name WHERE store_item_id = '".$a1."'  ";
			$name_result = mySQL_query($name_query);
			$a1a = mysql_result($name_result, 0, "item_name");
			$a1b = mysql_result($name_result, 0, "subCategory");
			$a1c = mysql_result($name_result, 0, "location");
			$a1d = mysql_result($name_result, 0, "minimumStock");
			$a1e = mysql_result($name_result, 0, "maximumStock");
			$a1f = mysql_result($name_result, 0, "price");
			
			
	$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;
	
	$table_name = $_SESSION['db_prefix']."_employee_supply_lines";
	$emp_query = "SELECT emp_id, SUM(quantity) as emp_quantity FROM $table_name WHERE store_item_id = '".$a1."' GROUP BY emp_id";
	$emp_result = mySQL_query($emp_query);
	$emp_num = mysql_num_rows($emp_result);
		
	$listTT_body='';
	$j=0;
	while ($j<$emp_num) {
		$a5 = mysql_result($emp_result, $j, "emp_id");
			$table_name2 = $_SESSION['db_prefix']."_employee";
			$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$a5."' ";
			$employee_result = mySQL_query($employee_query);
			$employee_num = mysql_num_rows($employee_result);	
			$a5a = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
		
		$a6 = mysql_result($emp_result, $j, "emp_quantity");
		$listTT_body = $listTT_body."<tr><td>".$a5a."</td><td align=center>".$a6."</td></tr>";
		$j++;
	}
	
	$listTT_head = "Issued to:<br><table id=table_tool_tip width=250 border=1><tr><td  width=200>Employee</td><td width=30 align=center>Quantity</td></tr>";
	$listTT_foot = "</table><b>Click for details</b>";
	
	$listTT = $listTT_head.$listTT_body.$listTT_foot;
	
$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>Max. stock</td><td>".$a1e."</td></tr><tr><td>Price</td><td>".$a1f."</td></tr></table><b>Click for details</b>";	

			
?>

  <tr>
    <td width="299" align="left"><a href="../store/store_item_display.php?store_item_id=<?php echo $a1 ?> " onMouseOver="ddrivetip('<?php echo $itemTT ?>', 260)"; onMouseOut="hideddrivetip()"><?php echo $a1a ?></a></td>
    <td width="66" align="center"><a href="item_issue_list.php?store_item_id=<?php echo $a1?>" onMouseover="ddrivetip('<?php echo $listTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $a2 ?></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>