<!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 = $con->query($items_query);
    	$items_num = mysqli_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},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
  <table width="409" id="scroll_table_1" class="data_display">
      <thead>
        <tr>
          <th width="167">Product Name</th>
          <th width="23">&nbsp;</th>
          <th width="73">Store group</th>
          <th width="46">Stock qty</th>
          <th width="76">Min stock</th>
        </tr>
      </thead>
      <tbody>
        <?php 
    		while($row = $items_result->fetch_assoc()) {
			$b1 = $row["store_item_id"];
			$b2 = $row["item_name"];
	        $b3 = $row["location"];
		    $b4 = $row["subCategory"];
	        $b5 = $row["quantity"];
	        $b6 = $row["minimumStock"];
	        $b7 = $row["price"];
		    $b8 = $row["unit"];
		    $b9 = $row["supplier_id"];
		   
		   //$b11 = $row["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 = $con->query($history_query);
$history_num = mysqli_num_rows($history_result); 
		
$historyTT_body	='';  
while($row = $history_result->fetch_assoc()) {
			$h1 = $row["date"];
			$h2 = $row["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=="18") {$h2a='return from order';}
		  if ($h2=="20") {$h2a='used in production';}
		  if ($h2=="21") {$h2a='produced (no new stock)';}
		  if ($h2=="22") {$h2a='production edited';}
		  if ($h2=="23") {$h2a='used in packing';}
		  if ($h2=="24") {$h2a='products packed';}
		  if ($h2=="25") {$h2a='production edited';}
		  if ($h2=="26") {$h2a='packing edited';}
		  if ($h2=="27") {$h2a='packing edited';}
		  
		  $h3 = $row["quantity"];
		  if ($h2==5) {if ($h3>0) {$h3='+'.$h3;} }
		  if (($h2==11) OR ($h2==18) OR ($h2==21)) {$h3='+'.$h3;}
		  if ( ($h2==13) ) {$h3='-'.$h3;}
		  if ( ($h2==21) OR ($h2==22) ) {$h3='';}
		  $h4 = $row["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>'; 
}

$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="left"><?php echo $b4 ?></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 
		
    	}
    	?>
      </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 }
?>

