
<?php
    include("../include/session.php");
   if( !$session->isAdmin() && !$session->isRadstoneReceptionUser()  && !$session->isRadstoneStoreUser()  ){
	//header("Location: ../Store/storeMenu.php");?>
	<script language="javascript" type="text/javascript">
        <!--
		  window.location="denied.php";
        -->
       </script>
	   <?php }
    else {
    	include("../storeHeader.php");
//        include("../include/db.php");
        
				  
		$subCat = mysql_real_escape_string($_GET['subCatSelect']);
						
		$category = mysql_real_escape_string($_GET['CategorySelect']);
		$categoryText = $category;		
		if ($subCat=="") {
		      $subCatText = "";
		}
		else
		   $subCatText = " - ".$subCat;
		
		 		 
		if ($category=="Direct Materials") {
		$q = "SELECT * FROM products WHERE category = '".$category."' AND isRemoved != '1'  ORDER BY productName ASC";	
		}
		else {
		$q = "SELECT * FROM products WHERE category = '".$category."' AND subCategory = '".$subCat."' AND isRemoved != '1'  ORDER BY productName ASC";
		}
		$result = execsql($q);
    	$i = 0;
    	$num = mysql_num_rows($result);
		
		if ($num==0) {
		  $message="No records to show";
		  }
		else {
		  $message="End of list";
		  }
		
    	
?>

	   <script type="text/JavaScript">
<!--
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
       </script>
       
<link rel="stylesheet" href="../css/dhtmlwindow.css" type="text/css" />
<script type="text/javascript" src="../css/dhtmlwindow.js"></script>
<link rel="stylesheet" href="../css/modal.css" type="text/css" />
<script type="text/javascript" src="../css/modal.js"></script>

<link rel="stylesheet" type="text/css" href="../css/jquery.autocomplete.css" />
<script type="text/javascript" src="../css/jquery.1.4.2.js"></script>
<script type="text/javascript" src="../css/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<script>
 $(document).ready(function(){
  $("#searchText").autocomplete("stock_autocomplete.php", {
        selectFirst: true
  });
 });
</script>

<script type="text/javascript" src="../css/tablesort.js"></script>
	   <link href="../css/main.css" rel="stylesheet" type="text/css" />
	   <div class="headerbox2">Stock List <?php echo $categoryText ?><?php echo $subCatText ?><br />
               
       </div>
	   
       <table width="596" class="sortable-onload-0 rowstyle-alt no-arrow " id="tableList"  >
    <thead>
      <tr>
        <th width="212" class="sortable-text">Product Name</th>
        <th width="82" class="sortable-text">Category</th>
        <th width="146" class=\"sortable-text">Sub Cat </th>
        <th width="66" class=\"sortable-numeric">Qty</th>
        <th width="66" class="sortable-numeric">Min</th>
      </tr>
      <tr>
            <th width="212" >(Click for item history.)</th>
            
            <th width="82">&nbsp;</th>
            <th width="146">&nbsp;</th>
            <th width="66">&nbsp;</th>
            <th width="66">&nbsp;</th>
            <!--        <th>Reserved Stock</th>-->
          </tr>
    </thead>
    <tbody>
    <?php 

    	while($i < $num){
	       $b1 = mysql_result($result, $i, "productId");
	       $b2 = mysql_result($result, $i, "productName");
	       $b3 = mysql_result($result, $i, "category");
		   $b4 = mysql_result($result, $i, "subCategory");
	       $b5 = mysql_result($result, $i, "quantity");
	       $b6 = mysql_result($result, $i, "minimumStock");
	       $b7 = mysql_result($result, $i, "reserved");
    
    ?>
    <tr class="alt">
       <td><div align="left"><a href="stockMovement.php?monthdisplay=0&cat=<?php echo $b3 ?>&productIdSelect=<?php echo $b1 ?>&date=0" onmouseover="ddrivetip('<?php echo $b2."<br>(".$b1.")<br>".$b3."<br><b>Click for item history</b>" ?>','lightyellow', 150)" onmouseout="hideddrivetip()";>
         <?php echo $b2?>
      </a></div></td>
        <td><div align="left">
          <?php echo $b3?>
        </div></td>
      
        <td align="right"><div align="left">
          <?php echo $b4?>
        </div></td>
        <td align="right"><?php
         
			if($b5<0){
				echo "<font color=\"red\">".number_format($b5)."</font>";
				}
			else {
			 if($b5<$b6){
				echo "<font color=\"orange\">".number_format($b5)."</font>";
				}
		       else{
			     echo number_format($b5);
		     }	
		   }
			
			?></td>
       
      <td align="right"><?php echo number_format($b6)?></td>
      </tr> 
    
<?php 
		$i++;
    	}
    	?></tbody>
</table>
<b><font color='#FF0000'><?php  echo $message ?></font></b>
    	<?php 
    	include("../footer.php");
    }
//    
	
?>
