<!--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-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/hr_sidebar.php");
?>
<?php
require_once('../include/tc_calendar.php');
	$date = mysql_real_escape_string($_GET['date']);
	
	
	if ($date==1) {
	$start = mysql_real_escape_string($_GET['date1']);
    $end = mysql_real_escape_string($_GET['date2']);
	}
	else {
	$start = date("Y-m-01");
	$end = date("Y-m-d");
	}
		
	if ($date!=1) {
	   $ds = "1"; }
	   else {
		$ds = date("d", strtotime($start) );
	   }
	$ms = date("m", strtotime($start) );
	$ys = date("Y", strtotime($start) );
	
	
	$de = date("d", strtotime($end) );
	$me = date("m", strtotime($end) );
	$ye = date("Y", strtotime($end) );	 
	
	//$endsearch = date('Y-m-d', strtotime('+1 day', strtotime($end)));
	
$item_id = $_GET['item_id'];	

$table_name = $_SESSION['db_prefix']."_store_items";
$item_query = "SELECT item_name, category, subCategory, quantity, price, unit  FROM $table_name WHERE store_item_id = '".$item_id."' ";
$item_result = mySQL_query($item_query);
$e1 = mysql_result($item_result, 0, "item_name");
$e2 = mysql_result($item_result, 0, "category");
$e3 = mysql_result($item_result, 0, "subCategory");
$e4 = mysql_result($item_result, 0, "quantity");
$e5 = mysql_result($item_result, 0, "price");
$e6 = mysql_result($item_result, 0, "unit");

	
$table_name2 = $_SESSION['db_prefix']."_employee_issue";
$issue_query = "SELECT * FROM $table_name2 WHERE store_item_id='".$item_id."' AND receive_date >= '".$start."' AND receive_date <= '".$end."' ";
$issue_result = mySQL_query($issue_query);
$issue_num = mysql_num_rows($issue_result);

$itemTT = "<label class=tip_text_label_bold>Click for all details.</label>";


?>
<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="700" height="125" valign="top" ><div class="page_head_frame">
        
        <table width="700" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Issued items</label>&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $e1 ?></label></td>
            </tr>
        </table>
      </div>
        <br />
<br />
<br />
<br />
  <form action="issued_item_list.php" method="get" name="dateform" class="today" id="dateform">
    <table width="721"  id='table_calendar'>
      <tr>
        <td height="20" colspan="3" align="left" valign="middle"><label class="label_std">Select time period to display</label></td>
        <td valign="middle">&nbsp;</td>
        <td valign="middle">&nbsp;</td>
        <td valign="middle"><input name="date" type="hidden" id="date" value="1" /></td>
      </tr>
      <tr>
        <td width="16" height="25" valign="middle">&nbsp;&nbsp; </td>
        <td width="39" valign="middle"><label class="label_std">  from:</label> </td>
        <td width="234" valign="middle"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
	 	$myCalendar->writeScript();?></td>
        <td width="33" valign="middle"><label class="label_std">to:</label></td>
        <td width="269" valign="middle"><?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
		$myCalendar->writeScript();?></td>
        <td width="102" valign="middle">&nbsp;&nbsp;
          <label>
            <input name="button5" type="submit" class="linkbutton"  id="button5" value="Go" />
          </label></td>
      </tr>
    </table>
  </form>
</td> <!--center of tableMain-->
</tr>
<tr>
<td> <!--center of tableMain-->
<div class="scroll_frame_long">
<table width="697" id="table_display">
  <tr>
    <td width="136">Item name: </td>
    <td colspan="5"><a href="../store/store_item_display.php?store_item_id=<?php echo $item_id ?> " onmouseover="ddrivetip('<?php echo $itemTT ?>', 120)"; onmouseout="hideddrivetip()"><?php echo $e1 ?></a>&nbsp;</td>
  </tr>
  <tr>
    <td>Category:</td>
    <td width="185"><?php echo $e2 ?></td>
    <td width="101">Sub category:</td>
    <td colspan="3"><?php echo $e3 ?></td>
  </tr>
  <tr>
    <td>Present stock:</td>
    <td><?php echo $e4  ?></td>
    <td>Cost:</td>
    <td width="84"><?php echo $e5 ?></td>
    <td width="69">Unit:</td>
    <td width="94"><?php echo $e6 ?></td>
  </tr>
</table>
<table width="697" id="table_list" class="sortable-onload-0r rowstyle-alt no-arrow "  >
  <tr>
    <th class="sortable-date-dmy">Date</th>
    <th class="sortable-text">Employee</th>
    <th class="sortable-text">Qty</th>
    <th class="sortable-text">Unit</th>
    <th >Cost</th>
    <th class="sortable-text">Loan/give</th>
    <th class="sortable-date-dmy">Return date</th>
    </tr>
<?php 

$i=0;
$a6tot = 0;
$a7tot = 0;
while ($i<$issue_num) {

	$a =  mysql_result($issue_result, $i, "issue_id");
	$a0 = mysql_result($issue_result, $i, "receive_date");
	$a1 = mysql_result($issue_result, $i, "store_item_id");
	    $table_name = $_SESSION['db_prefix']."_store_items";
    	$item_query = "SELECT  `item_name`, `subCategory`, unit  FROM $table_name WHERE `store_item_id` = '".$a1." ' ";
		$item_result = mySQL_query($item_query);
        $a1a = mysql_result($item_result, 0, "item_name");
		$a2 = mysql_result($item_result, 0, "subCategory");
		$a8 = mysql_result($item_result, 0, "unit");
	
	$a3 = mysql_result($issue_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name  FROM $table_name WHERE emp_id = $a3 ";
		
		$employee_result = mySQL_query($employee_query);
        $a3a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		//$a7 = mysql_result($employee_result, 0, "department");
	
	$a4 = mysql_result($issue_result, $i, "cost");
	$a6 = mysql_result($issue_result, $i, "quantity");
	$a7 = $a4*$a6;
	$a6tot = $a6tot + $a6;
	$a7tot = $a7tot + $a7;
	$a9 = mysql_result($issue_result, $i, "loan");
	$a9 = mysql_result($issue_result, $i, "loan");
	
	$a5 = mysql_result($issue_result, $i, "return_date");
	if ($a5=='0000-00-00') {
		$a5a='';
	}
	else {
		$a5a = date("d-m-Y", strtotime($a5) );
	}
	
		
	//$employeeTT = "<label class=tip_text_label>".$a1."</label><br><label class=tip_click_label>Click for details</label>";  
	$employeeTT = "<label class=tip_text_label>".$a3a."</label><br><label class=tip_click_label>Click to view all issues to this employee</label>";  
	?>
    
  
  
  <tr>
    <td width="58" align="left"><?php echo date("d-m-Y", strtotime($a0 )) ?></td>
    <td width="306" align="left"><a href="issued_employee_list.php?emp_id=<?php echo $a3 ?>&date=0 " onMouseover="ddrivetip('<?php echo $employeeTT ?>', 220)"; onMouseout="hideddrivetip()"> <?php echo $a3a ?>  </a></td>
    <td width="58" align="left"><?php echo $a6." ".$a8?></td>
    <td width="59" align="right"><?php echo number_format($a4, 2, '.', ',') ?></td>
    <td width="52" align="right"><?php echo number_format($a7, 2, '.', ',') ?></td>
    <td width="72" align="left"><?php echo $a9 ?></td>
    <td width="60" align="left"><?php echo $a5a  ?></td>
    </tr>
  
  <?php
  $i++;
}
?>
<tr>
    <td colspan="2" align="right">Totals:</td>
    <td align="left"><?php echo $a6tot ?></td>
    <td align="right">&nbsp;</td>
    <td align="right"><?php echo number_format($a7tot, 2, '.', ',') ?></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
  </tr>
</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/hr_main.php?date=";	
include ("../navigation/hr_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</html>