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

$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {

include ("../navigation/store_sidebar.php");
	
				  
$subCat = $_GET['subCat'];
								
$subCatText = $subCat;	
$table_name2 = $_SESSION['db_prefix']."_store_items"; 
		
$tip_reserved_text='';
$reservedTT='';		 
		if ($subCat=="Complete") {
		$items_query = "SELECT * FROM $table_name2 WHERE category!='Old'  ORDER BY item_name ASC";
		}
		else {
		$items_query = "SELECT * FROM $table_name2 WHERE subCategory = '".$subCat."'  ORDER BY item_name ASC";
		}
						
		$items_result = execsql($items_query);
    	$items_num = mysql_num_rows($items_result);
				
			
    	
?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<link href="../css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/tabs.css" />

<!--jscript-->
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script> 
       
</head>

<body>

<div class="main_frame">
 
  <div class="page_head_frame">
    <label class="label_page_head">Store Items List <?php echo $subCatText ?></label>
  </div>

<div class="page_middle_frame" style="height:510px;"> 


   <script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table_1').dataTable( {
					"sScrollY": "400px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                             	{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
  <table width="380" id="scroll_table_1" class="data_display">
      <thead>
        <tr>
          <th width="181">Product Name</th>
          <th width="23">&nbsp;</th>
          <th width="74">Stock qty</th>
          <th width="74">Min stock</th>
        </tr>
      </thead>
      <tbody>
        <?php 
    $i=0;
    while($i < $items_num){
	       $b1 = mysql_result($items_result, $i, "store_item_id");
	       $b2 = mysql_result($items_result, $i, "item_name");
	       $b3 = mysql_result($items_result, $i, "location");
		   $b4 = mysql_result($items_result, $i, "subCategory");
	       $b5 = mysql_result($items_result, $i, "quantity");
	       $b6 = mysql_result($items_result, $i, "minimumStock");
	       $b7 = mysql_result($items_result, $i, "price");
		   $b8 = mysql_result($items_result, $i, "unit");
		   $b9 = mysql_result($items_result, $i, "supplier_id");
		   
		   //$b11 = mysql_result($items_result, $i, "prereserved");
		   $b12 = '0';
		   
$table_name3 = $_SESSION['db_prefix']."_item_history";
$history_query = "SELECT entry, quantity, total, date FROM $table_name3 WHERE store_item_id = '".$b1."' ORDER BY history_id DESC LIMIT 10";
$history_result = mySQL_query($history_query);
$history_num = mysql_num_rows($history_result); 
		
$historyTT_body	='';  
$k=0;
while ($k<$history_num) {
          $h1 = mysql_result($history_result, $k, "date");
		  $h2 = mysql_result($history_result, $k, "entry");
		  $h2a='';
		  if ($h2=="5") {$h2a='stock count';}
		  if ($h2=="10") {$h2a='item added to store';}
		  if ($h2=="11") {$h2a='stock received';}
		  if ($h2=="13") {$h2a='order delivered';}
		  if ($h2=="14") {$h2a='employee supplied';}
		  if ($h2=="15") {$h2a='department supplied';}
		  if ($h2=="16") {$h2a='return from employee';}
		  if ($h2=="18") {$h2a='return from order';}
		  if ($h2=="19") {$h2a='company supplied';}
		  if ($h2=="20") {$h2a='used in production';}
		  if ($h2=="21") {$h2a='from production';}
		  if ($h2=="30") {$h2a='fuel supply';}
		  if ($h2=="35") {$h2a='adjustment receive note';}
		  
		  $h3 = mysql_result($history_result, $k, "quantity");
		  if ($h2==5) {if ($h3>0) {$h3='+'.$h3;} }
		  if (($h2==11)  OR ($h2==16)  OR ($h2==18) OR ($h2==21)) {$h3='+'.$h3;}
		  if ( ($h2==13) OR ($h2==14) OR ($h2==15) OR ($h2==19) OR ($h2==30) ) {$h3='-'.$h3;}
		  $h4 = mysql_result($history_result, $k, "total");

$historyTT_body=$historyTT_body.'<tr><td>'.date("d-m-Y", strtotime($h1)) .'</td><td>'.$h2a.'</td><td align=right>'.$h3.'</td><td align=right>'.$h4.'</td></tr>'; 
$k++;
}

$historyTT_head='<b>Recent history:</b><br><br><table id=table_tool_tip width=400 border=1 cellspacing=0 cellpadding=0><tr><td width=75>date</td><td width=75>action</td><td width=50>qty</td><td width=50>stock qty</td></tr>';
$historyTT_foot='</table><br><b>Click for full history</b>';		   
$historyTT = $historyTT_head.$historyTT_body.$historyTT_foot; 	   
			   
		   
		   
		   
    ?>
        <tr class="alt">
          <td align="left"><a href="store_item_history.php?store_item_id=<?php echo $b1 ?>&date=0" onMouseover="ddrivetip('<?php echo $historyTT ?>', 400)"; onMouseout="hideddrivetip()"><?php echo $b2 ?></a></td>
          <td align="left"><?php echo $b2 ?></td>
          <td align="right"><?php
         
			if($b5<0){
				echo "<font color=\"red\">".number_format($b5 , 0, '.', ',')."</font>";
				}
			else {
			 if($b5<$b6){
				echo "<font color=\"orange\">".number_format($b5 , 0, '.', ',')."</font>";
				}
		       else{
			     echo number_format($b5 , 0, '.', ',');
		     }	
		   }
			
			?></td>
          <td align="right"><?php echo $b6 ?></td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>
          </div>
       
 
  </div>
 </div> 
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "store/store_main.php?date=0&branch=&subCatSelect=Tiles";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>

