<!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 = mysql_real_escape_string($_GET['subCatSelect']);
								
$subCatText = $subCat;	
$table_name2 = $_SESSION['db_prefix']."_store_items"; 
		
$tip_reserved_text='';
$reservedTT='';		 
		if ($subCat=="Complete") {
		$gab_items_query = "SELECT * FROM $table_name2 WHERE category!='Old' AND branch = 'Gaborone' ORDER BY item_name ASC";
		$ftw_items_query = "SELECT * FROM $table_name2 WHERE category!='Old' AND branch = 'Francistown' ORDER BY item_name ASC";
		$com_items_query = "SELECT * FROM $table_name2 WHERE category!='Old' ORDER BY item_name ASC";	
		}
		else {
		$gab_items_query = "SELECT * FROM $table_name2 WHERE subCategory = '".$subCat."' AND branch = 'Gaborone'  ORDER BY item_name ASC";
		$ftw_items_query = "SELECT * FROM $table_name2 WHERE subCategory = '".$subCat."' AND branch = 'Francistown'  ORDER BY item_name ASC";
		$com_items_query = "SELECT * FROM $table_name2 WHERE subCategory = '".$subCat."' ORDER BY item_name ASC";
		}
		
				
		$gab_items_result = execsql($gab_items_query);
    	$gab_items_num = mysql_num_rows($gab_items_result);
		$ftw_items_result = execsql($ftw_items_query);
    	$ftw_items_num = mysql_num_rows($ftw_items_result);
		$com_items_result = execsql($com_items_query);
    	$com_items_num = mysql_num_rows($com_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;"> 



<ul class="tabs">
      <li>
          <input type="radio" checked name="tabs" id="tab1">
          <label class="tab" for="tab1">Gaborone</label>
          <div id="tab-content1" class="tab-content animated fadeIn">
   <script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table_1').dataTable( {
					"sScrollY": "400px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "asc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                             	{"iDataSort": 3},
								{"bVisible": false},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
  <table width="662" 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="26">&nbsp;</th>
          <th width="80">&nbsp;</th>
          <th width="77">Reserved</th>
          <th width="91">Available</th>
          <th width="74">Min stock</th>
        </tr>
      </thead>
      <tbody>
        <?php 
    $i=0;
    while($i < $gab_items_num){
	       $b1 = mysql_result($gab_items_result, $i, "store_item_id");
	       $b2 = mysql_result($gab_items_result, $i, "item_name");
	       $b3 = mysql_result($gab_items_result, $i, "location");
		   $b4 = mysql_result($gab_items_result, $i, "subCategory");
	       $b5 = mysql_result($gab_items_result, $i, "quantity");
	       $b6 = mysql_result($gab_items_result, $i, "minimumStock");
	       $b7 = mysql_result($gab_items_result, $i, "price");
		   $b8 = mysql_result($gab_items_result, $i, "unit");
		   $b9 = mysql_result($gab_items_result, $i, "supplier_id");
		   
		   //$b11 = mysql_result($items_result, $i, "prereserved");
		   $b12 = '0';
    ?>
        <tr class="alt">
          <td align="left"><a href="store_item_history.php?store_item_id=<?php echo $b1 ?>&date=0" onMouseover="ddrivetip('<?php           
$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); 
?><b>Recent history:</b><br><br><table id=table_tool_tip width=250 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><?php
$k=0;
while ($k<$history_num) {
          $h1 = mysql_result($history_result, $k, "date");
		  $h2 = mysql_result($history_result, $k, "entry");
		  if ($h2=="5") {$h2a='stock count';}
		  if ($h2=="10") {$h2a='new';}
		  if ($h2=="20") {$h2a='received';}
		  if ($h2=="30") {$h2a='to department';}
		  if ($h2=="31") {$h2a='to employee';}
		  if ($h2=="40") {$h2a='delivered to job';}
		  if ($h2=="41") {$h2a='issued to job';}
		  if ($h2=="42") {$h2a='Additional delivery to job';}
		  if ($h2=="43") {$h2a='cash sale';}
		  $h3 = mysql_result($history_result, $k, "quantity");
		  if ($h2==5) {if ($h3>0) {$h3='+'.$h3;} }
		  if ($h2==20) {$h3='+'.$h3;}
		  if (($h2==30) OR ($h2==31) OR ($h2==40) OR ($h2==41) OR ($h2==42) OR ($h2==43)) {$h3='-'.$h3;}
		  $h4 = mysql_result($history_result, $k, "total");?>
<tr><td><?php echo date("d-m-Y", strtotime($h1)) ?></td><td><?php echo $h2a ?></td><td align=right><?php echo $h3 ?></td><td align=right><?php echo $h4 ?></td><?php 
$k++;
}
?></tr></table><br><b>Click for full history</b>', 260)"; 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 $b5 ?></td>
          <td align="right">&nbsp;</td>
          <td align="right">&nbsp;</td>
          <td align="right"><?php echo ($b5-$b12) ?></td>
          <td align="right"><?php echo $b6 ?></td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>
          </div>
        </li>
        <li>
          <input type="radio" name="tabs" id="tab2">
          <label class="tab" for="tab2">Francistown</label>
          <div id="tab-content2" class="tab-content animated fadeIn"><br>
          
          <script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table_2').dataTable( {
					"sScrollY": "400px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bVisible": false},
                             	{"iDataSort": 3},
								{"bVisible": false},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
  <table width="662" id="scroll_table_2" class="data_display">
      <thead>
        <tr>
          <th width="181">Product Name</th>
          <th width="23">&nbsp;</th>
          <th width="74">Stock qty</th>
          <th width="26">&nbsp;</th>
          <th width="80">&nbsp;</th>
          <th width="77">Reserved</th>
          <th width="91">Available</th>
          <th width="74">Min stock</th>
        </tr>
      </thead>
      <tbody>
        <?php 
    $i=0;
    while($i < $ftw_items_num){
	       $b1 = mysql_result($ftw_items_result, $i, "store_item_id");
	       $b2 = mysql_result($ftw_items_result, $i, "item_name");
	       $b3 = mysql_result($ftw_items_result, $i, "location");
		   $b4 = mysql_result($ftw_items_result, $i, "subCategory");
	       $b5 = mysql_result($ftw_items_result, $i, "quantity");
	       $b6 = mysql_result($ftw_items_result, $i, "minimumStock");
	       $b7 = mysql_result($ftw_items_result, $i, "price");
		   $b8 = mysql_result($ftw_items_result, $i, "unit");
		   $b9 = mysql_result($ftw_items_result, $i, "supplier_id");
		   
		   //$b11 = mysql_result($items_result, $i, "prereserved");
		   $b12 = '0';
    ?>
        <tr class="alt">
          <td align="left"><a href="store_item_history.php?store_item_id=<?php echo $b1 ?>&date=0" onMouseover="ddrivetip('<?php           
$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); 
?><b>Recent history:</b><br><br><table id=table_tool_tip width=250 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><?php
$k=0;
while ($k<$history_num) {
          $h1 = mysql_result($history_result, $k, "date");
		  $h2 = mysql_result($history_result, $k, "entry");
		  if ($h2=="5") {$h2a='stock count';}
		  if ($h2=="10") {$h2a='new';}
		  if ($h2=="20") {$h2a='received';}
		  if ($h2=="30") {$h2a='to department';}
		  if ($h2=="31") {$h2a='to employee';}
		  if ($h2=="40") {$h2a='delivered to job';}
		  if ($h2=="41") {$h2a='issued to job';}
		  if ($h2=="42") {$h2a='Additional delivery to job';}
		  if ($h2=="43") {$h2a='cash sale';}
		  $h3 = mysql_result($history_result, $k, "quantity");
		  if ($h2==5) {if ($h3>0) {$h3='+'.$h3;} }
		  if ($h2==20) {$h3='+'.$h3;}
		  if (($h2==30) OR ($h2==31) OR ($h2==40) OR ($h2==41) OR ($h2==42) OR ($h2==43)) {$h3='-'.$h3;}
		  $h4 = mysql_result($history_result, $k, "total");?>
<tr><td><?php echo date("d-m-Y", strtotime($h1)) ?></td><td><?php echo $h2a ?></td><td align=right><?php echo $h3 ?></td><td align=right><?php echo $h4 ?></td><?php 
$k++;
}
?></tr></table><br><b>Click for full history</b>', 260)"; 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 $b5 ?></td>
          <td align="right">&nbsp;</td>
          <td align="right">&nbsp;</td>
          <td align="right"><?php echo ($b5-$b12) ?></td>
          <td align="right"><?php echo $b6 ?></td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>
    </div>
        </li>
        <li>
          <input type="radio" name="tabs" id="tab3">
          <label class="tab" for="tab3">Combined</label>
          <div id="tab-content3" class="tab-content animated fadeIn">
       <script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table_3').dataTable( {
					"sScrollY": "400px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "asc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                             	{"iDataSort": 3},
								{"bVisible": false},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
  <table width="662" id="scroll_table_3" class="data_display">
      <thead>
        <tr>
          <th width="181">Product Name</th>
          <th width="23">&nbsp;</th>
          <th width="74">Stock qty</th>
          <th width="26">&nbsp;</th>
          <th width="80">&nbsp;</th>
          <th width="77">Reserved</th>
          <th width="91">Available</th>
          <th width="74">Min stock</th>
        </tr>
      </thead>
      <tbody>
        <?php 
    $i=0;
    while($i < $com_items_num){
	       $b1 = mysql_result($com_items_result, $i, "store_item_id");
	       $b2 = mysql_result($com_items_result, $i, "item_name");
	       $b3 = mysql_result($com_items_result, $i, "location");
		   $b4 = mysql_result($com_items_result, $i, "subCategory");
	       $b5 = mysql_result($com_items_result, $i, "quantity");
	       $b6 = mysql_result($com_items_result, $i, "minimumStock");
	       $b7 = mysql_result($com_items_result, $i, "price");
		   $b8 = mysql_result($com_items_result, $i, "unit");
		   $b9 = mysql_result($com_items_result, $i, "supplier_id");
		   $b10 = mysql_result($com_items_result, $i, "branch");
		   
		   //$b11 = mysql_result($items_result, $i, "prereserved");
		   $b12 = '0';
    ?>
        <tr class="alt">
          <td align="left"><a href="store_item_history.php?store_item_id=<?php echo $b1 ?>&date=0" onMouseover="ddrivetip('<?php           
$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); 
?><b>Recent history:</b><br><br><table id=table_tool_tip width=250 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><?php
$k=0;
while ($k<$history_num) {
          $h1 = mysql_result($history_result, $k, "date");
		  $h2 = mysql_result($history_result, $k, "entry");
		  if ($h2=="5") {$h2a='stock count';}
		  if ($h2=="10") {$h2a='new';}
		  if ($h2=="20") {$h2a='received';}
		  if ($h2=="30") {$h2a='to department';}
		  if ($h2=="31") {$h2a='to employee';}
		  if ($h2=="40") {$h2a='delivered to job';}
		  if ($h2=="41") {$h2a='issued to job';}
		  if ($h2=="42") {$h2a='Additional delivery to job';}
		  if ($h2=="43") {$h2a='cash sale';}
		  $h3 = mysql_result($history_result, $k, "quantity");
		  if ($h2==5) {if ($h3>0) {$h3='+'.$h3;} }
		  if ($h2==20) {$h3='+'.$h3;}
		  if (($h2==30) OR ($h2==31) OR ($h2==40) OR ($h2==41) OR ($h2==42) OR ($h2==43)) {$h3='-'.$h3;}
		  $h4 = mysql_result($history_result, $k, "total");?>
<tr><td><?php echo date("d-m-Y", strtotime($h1)) ?></td><td><?php echo $h2a ?></td><td align=right><?php echo $h3 ?></td><td align=right><?php echo $h4 ?></td><?php 
$k++;
}
?></tr></table><br><b>Click for full history</b>', 260)"; 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 $b5 ?></td>
          <td ><?php echo $b10 ?></td>
          <td align="right">&nbsp;</td>
          <td align="right"><?php echo ($b5-$b12) ?></td>
          <td align="right"><?php echo $b6 ?></td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>

</div>
        </li>
</ul>
 
  </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 }
?>

