<!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"; 		 
		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";
		}
		
		if ($subCat=="Old") {
		$items_query = "SELECT * FROM $table_name2 WHERE category='Old' ORDER BY item_name ASC";	
		}
		
		$items_result = execsql($items_query);
    	$i = 0;
    	$items_num = mysql_num_rows($items_result);
		
		if ($items_num==0) {
		  $message="No records to show";
		  }
		else {
		  $message="End of list";
		  }
		
    	
?>
<!--style sheets-->
<!--reference to main.css removed-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

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

<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "asc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": false},
								{"bSortable": false},
								{"bSortable": true},
								{"iDataSort": 9},
								{"bVisible": false}							
								 ]
				} );
			} );
		</script>

</head>

<body>


<div class="main_frame" style="height:auto;">
  <!--reference to main.css removed-->
  <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:auto;">
    <table width="672" class="data_display" id="scroll_table" >
      <thead>
        <tr>
          <th width="164">Product Name</th>
          <th width="23">&nbsp;</th>
          <th width="65">Sub category</th>
          <th width="65">Location</th>
          <th width="32">Unit</th>
          <th width="55">Cost price</th>
          <th width="69"">Sales price</th>
          <th width="65">Min qty</th>
          <th width="67">Stock qty</th>
          <th width="23">&nbsp;</th>
        </tr>
      </thead>
      <tbody>
        <?php 

    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");
		   $b10 = mysql_result($items_result, $i, "price_2");
		   $b11 = mysql_result($items_result, $i, "prereserved");
		   $b12 = mysql_result($items_result, $i, "reserved");
		   $b13 = mysql_result($items_result, $i, "class");
		   
		   $table_name2 = $_SESSION['db_prefix']."_suppliers";
           $suppliers_query = "SELECT account_name   FROM $table_name2 WHERE supplier_id = '".$b9."' ";
           $suppliers_result = mySQL_query($suppliers_query);
		   $suppliers_num = mysql_num_rows($suppliers_result);
           if ($suppliers_num!=0) {
		   $b9a = mysql_result($suppliers_result, 0, "account_name");
		   }
		   else {
			   $b9a="";
		   }
		   
		   
		   
           		   
		   $itemTT =
		   "<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=250 ><tr><td  width=75>Item name:</td><td width=175>".$b2."</td></tr><tr><td>Supplier:</td><td>".$b9a."</td></tr></table><br><b>Click for details</b>";
		   
		      
    ?>
        <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); 
?><img src=../images/history.png  width=20 height=16><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;
$h2a='';
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='used in production';}
		  if ($h2=="41") {$h2a='issued to job';}
		  $h3 = mysql_result($history_result, $k, "quantity");
		  $h4 = mysql_result($history_result, $k, "total");?>
<tr><td><?php echo date("d-m-Y", strtotime($h1)) ?></td><td><?php echo $h2a ?></td><td><?php echo $h3 ?></td><td><?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="left"><a href="store_items_list.php?subCatSelect=<?php echo $b4?>" onMouseover="ddrivetip('Click to see store list for <?php echo $b4?>', 200)"; onMouseout="hideddrivetip()"><?php echo $b4?></a></td>
          <td align="left"><?php echo $b3 ?></td>
          <td align="left"><?php echo $b8 ?></td>
          <td align="right"><?php echo number_format($b7 , 2, '.', ',') ?></td>
          <td align="right"><?php echo number_format($b10 , 2, '.', ',') ?></td>
          <td align="right"><?php echo $b6  ?></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);
		     }	
		   }
			
			?></td>
          <td align="right"><?php echo $b5?></td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>
    <div align="left">
      <label class="label_end">
        <?php  echo $message ?>
      </label>
    </div>
  </div>
</div>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "store/store_main.php";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
