<!--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" />
 

<?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)));
	
	
	
$table_name2 = $_SESSION['db_prefix']."_employee_issue";
$issue_query = "SELECT * FROM $table_name2 WHERE receive_date >= '".$start."' AND receive_date <= '".$end."' ";
$issue_result = mySQL_query($issue_query);
$issue_num = mysql_num_rows($issue_result);


?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></script>
<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": [
								{"iDataSort": 11},
								{"iDataSort": 2},
								{"bVisible": false},
								{"bSortable": true},
                              	{"iDataSort": 4},
								{"bVisible": false},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 12},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
</head>

<body>
<?php include ('../include/tooltip.php'); ?>

<div class="main_frame">
  <div class="page_head_frame">
     <table width="700" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Issued items</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
 </div>
        <br />
<br />
<br />
<br />
<div class="page_middle_frame">
<div class="page_inside_frame" style="width:670px;">
  <form action="issued_list.php" method="get" name="dateform" class="today" id="dateform">
    <table width="665"  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="18" height="25" valign="middle">&nbsp;&nbsp; </td>
        <td width="35" valign="middle"><label class="label_std">  from:</label> </td>
        <td width="226" 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="26" valign="middle"><label class="label_std">to:</label></td>
        <td width="251" 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="81" valign="middle">&nbsp;&nbsp;
          <label>
            <input name="button5" type="submit" class="linkbutton"  id="button5" value="Go" />
          </label></td>
      </tr>
    </table>
  </form>
</div>
<div class="page_inside_frame" style="width:670px;">
<table width="690" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th>Date</th>
    <th>Item</th>
    <th>2</th>
    <th>Group</th>
    <th>Employee</th>
    <th>5</th>
    <th>Qty</th>
    <th>Unit</th>
    <th>Cost</th>
    <th>Loan/give</th>
    <th>Return date</th>
    <th>11</th>
    <th>12</th>
    </tr>
    </thead>
<?php 

$i=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;
	$a7tot = $a7tot + $a7;
	$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) );
	}
	
		
	$itemTT = "<label class=tip_text_label>".$a1a."</label><br><label class=tip_text_label_bold>Click to see who else received this item.</label>";  
	$warningTT = "<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="39" align="left"><?php echo date("d-m-Y", strtotime($a0 )) ?></td>
    <td width="81" align="left"><a href="issued_item_list.php?item_id=<?php echo $a1?>&date=0" onmouseover="ddrivetip('<?php echo $itemTT ?>  ', 220)"; onmouseout="hideddrivetip()"><?php echo $a1a ?></a></td>
    <td width="23" align="left"><?php echo $a1 ?>&nbsp;</td>
    <td width="71" align="left"><?php echo $a2 ?></td>
    <td width="104" align="left"><a href="issued_employee_list.php?emp_id=<?php echo $a3 ?>&date=0 " onMouseover="ddrivetip('<?php echo $warningTT ?>', 220)"; onMouseout="hideddrivetip()"> <?php echo $a3a ?>  </a></td>
    <td width="23" align="left"><?php echo $a3 ?>&nbsp;</td>
    <td width="35" align="left"><?php echo $a6." ".$a8?></td>
    <td width="32" align="left"><?php echo number_format($a4, 2, '.', ',') ?></td>
    <td width="43" align="right"><?php echo number_format($a7, 2, '.', ',') ?></td>
    <td width="73" align="left"><?php echo $a9 ?></td>
    <td width="53" align="left"><?php echo $a5a  ?></td>
    <td width="24" align="left"><?php echo $a0 ?></td>
    <td width="33" align="left"><?php echo $a5 ?></td>
    </tr>
  
  <?php
  $i++;
}
?>
<tfoot>
<tr>
    <td colspan="8" align="right">Totals</td>
    <td align="right"><?php echo number_format($a7tot, 2, '.', ',') ?></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
  </tr>
  </tfoot>
</table>
<div align="left"></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>