<?php 

$subCat = mysql_real_escape_string($_GET['subCatSelect']);
								
$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' AND branch = 'Francistown' ORDER BY item_name ASC";
		}
		
		if ($subCat=="Tiles") {
		$items_query = "SELECT * FROM $table_name2 WHERE subCategory = 'Tiles' AND branch = 'Francistown'  ORDER BY item_name ASC";
		}
		
		if ($subCat=="Accessories") {
		$items_query = "SELECT * FROM $table_name2 WHERE subCategory = 'Accessories' AND branch = 'Francistown'   ORDER BY item_name ASC";
		}
		
		if ($subCat=="Consumables") {
		$items_query = "SELECT * FROM $table_name2 WHERE subCategory = 'Consumables' AND branch = 'Francistown'   ORDER BY item_name ASC";
		}
		
		if ($subCat=="Old") {
		$items_query = "SELECT * FROM $table_name2 WHERE category='Old' AND branch = 'Francistown'  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="page_middle_frame" style="height:510px;"> 

<ul class="tabs">
      <li>
          <input type="radio" name="tabs" id="tab1">
          <label class="tab" for="tab1"><a class="tabs" href="store_items_list.php?subCatSelect=<?php echo $subCat ?>&branch=Gaborone">Gaborone</a></label>
      <div id="tab-content1" class="tab-content animated fadeIn">    
  </div>
        </li>
        <li>
          <input type="radio" checked  name="tabs" id="tab2">
          <label class="tab" for="tab2"><a class="tabs" href="store_items_list.php?subCatSelect=<?php echo $subCat ?>&branch=Francistown">Francistown</a></label>
<div id="tab-content2" class="tab-content animated fadeIn">          

<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').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" 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">Branch</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 < $items_num){
	       $a1 = mysql_result($items_result, $i, "store_item_id");
	       $a2 = mysql_result($items_result, $i, "item_name");
	       $a3 = mysql_result($items_result, $i, "location");
		   $a4 = mysql_result($items_result, $i, "subCategory");
	       $a5 = mysql_result($items_result, $i, "quantity");
	       $a6 = mysql_result($items_result, $i, "minimumStock");
	       $a7 = mysql_result($items_result, $i, "price");
		   $a8 = mysql_result($items_result, $i, "unit");
		   $a9 = mysql_result($items_result, $i, "supplier_id");
		   $a10 = mysql_result($items_result, $i, "branch");
		   
		   //$a11 = mysql_result($items_result, $i, "prereserved");
		   $a12 = '0';
		   
	$table_name3 = $_SESSION['db_prefix']."_item_history";
$history_query = "SELECT entry, quantity, total, date FROM $table_name3 WHERE store_item_id = '".$a1."' 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");
		  if ($h2=="5") {$h2a='stock count';}
		  if ($h2=="10") {$h2a='new';}
		  if ($h2=="20") {$h2a='tiles&acc received';}
		  if ($h2=="21") {$h2a='tiles&acc delivered';}
		  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");

$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=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>';
$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 $a1 ?>&date=0" onMouseover="ddrivetip('<?php echo $historyTT ?>', 260)"; onMouseout="hideddrivetip()"><?php echo $a2 ?></a></td>
          <td align="left"><?php echo $a2 ?></td>
          <td align="right"><?php
         
			if($a5<0){
				echo "<font color=\"red\">".number_format($a5 , 0, '.', ',')."</font>";
				}
			else {
			 if($a5<$a6){
				echo "<font color=\"orange\">".number_format($a5 , 0, '.', ',')."</font>";
				}
		       else{
			     echo number_format($a5 , 0, '.', ',');
		     }	
		   }
			
			?></td>
          <td align="right"><?php echo $a5 ?></td>
          <td ><?php echo $a10 ?></td>
          <td >&nbsp;</td>
          <td align="right"><?php echo ($a5-$a12) ?></td>
          <td align="right"><?php echo $a6 ?></td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>
        
</div>
        </li>
        <li>
          <input type="radio" name="tabs" id="tab3">
          <label class="tab" for="tab3"><a class="tabs" href="store_items_list.php?subCatSelect=<?php echo $subCat ?>&branch=Combined">Combined</a></label>
           
 <div id="tab-content3" class="tab-content animated fadeIn">
 
          </div>
        </li>
</ul>
 
  </div>


