<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include('../include/session.php');
	

?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script type="text/javascript" src="../jscript/tooltip.js"></script>

</head>

<body>
<?php
$_SESSION['current_page']  = "store";
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");

$table_name2 = $_SESSION['db_prefix']."_store_items"; 
$items_min_query = "SELECT store_item_id FROM $table_name2 WHERE quantity < minimumStock ";
$items_min_result = execsql($items_min_query);
$items_min_num = mysql_num_rows($items_min_result);

$table_name2 = $_SESSION['db_prefix']."_store_items"; 
$items_non_query = "SELECT store_item_id FROM $table_name2 WHERE (quantity <= 0) AND (minimumStock <> 0) ";
$items_non_result = execsql($items_non_query);
$items_non_num = mysql_num_rows($items_non_result);


$short_reserved = 0;
$table_name2 = $_SESSION['db_prefix']."_store_items"; 
$reserved_query = "SELECT store_item_id, quantity FROM $table_name2";
$reserved_result = execsql($reserved_query);
$reserved_num = mysql_num_rows($reserved_result);
$i=0;

while ($i<$reserved_num) {
	$store_item_id = mysql_result($reserved_result, $i, "store_item_id");
  	$stock_qty = mysql_result($reserved_result, $i, "quantity");
	
	$table_name = $_SESSION['db_prefix']."_order_job_lines";
	$job_reserved_query = "SELECT SUM(quantity) AS summed_quantity, SUM(delivered) AS summed_delivered FROM $table_name WHERE store_item_id = '".$store_item_id."' GROUP BY store_item_id";
	$job_reserved_result = mySQL_query($job_reserved_query);
	$job_reserved_num = mysql_num_rows($job_reserved_result);
	$m=0;
	while ($m<$job_reserved_num) {
						$reserved = mysql_result($job_reserved_result, $m, "summed_quantity")-mysql_result($job_reserved_result, $m, "summed_delivered");
						$m++;
			
						if ($stock_qty<$reserved) {
							  $short_reserved = $short_reserved + 1;
						}
	}
						
	$table_name2 = $_SESSION['db_prefix']."_mworks_order_job_lines";
	$job_reserved2_query = "SELECT SUM(quantity) AS summed_quantity, SUM(delivered) AS summed_delivered FROM $table_name2 WHERE store_item_id = '".$store_item_id."' GROUP BY store_item_id";
	$job_reserved2_result = mySQL_query($job_reserved2_query);
	$job_reserved2_num = mysql_num_rows($job_reserved2_result);
	$m=0;
	while ($m<$job_reserved2_num) {
						$reserved2 = mysql_result($job_reserved2_result, $m, "summed_quantity")-mysql_result($job_reserved2_result, $m, "summed_delivered");
						$m++;
			
						if ($stock_qty<$reserved2) {
							  $short_reserved = $short_reserved + 1;
							  
						}					
	}
	$i++;
}









if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
	?>
<div class="main_frame" style="height:auto;">
 <div class="page_head_frame">
          <table width="640" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><label class="label_page_head">Store </label></td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
       
    
      <div  class="page_middle_frame">
        <div class="page_inside_frame"><br>
        <img src="../images/exclamation_mark_green_small.png" width="20" height="32">You completed the wizard, you cannot return to it.
        <br>
        </div>  
      
  </div>
  
</div>
</body>
<?php } else {
$_SESSION['denied_return'] = $_SESSION['location'];	
include ("../navigation/store_sidebar.php");?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</html>