<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");
require_once ('../include/tc_calendar.php');


$show = $_GET['show'];

$table_name = $_SESSION['db_prefix']."_product_store";
$table_name2 = $_SESSION['db_prefix']."_product_store_lines";
$product_query = "SELECT $table_name.product_item_id,  $table_name.item_name, $table_name2.product_store_line_id, $table_name2.batch_code FROM $table_name, $table_name2 WHERE $table_name.product_item_id=$table_name2.product_item_id AND ($table_name2.quantity_in - $table_name2.quantity_out) > 0 and subCategory = 'Production' ORDER BY $table_name.item_name DESC";
$product_result = $con->query($product_query);
	$w = 0;
	$arrId3 = array ();
	$arrName3 = array ();
	while($row = $product_result->fetch_assoc()) {
		$product_store_line_id = $row['product_store_line_id'];
		$product_item_name = $row['item_name'];
		$batch_code = $row['batch_code'];
		
		$arrId3[$w] = $product_store_line_id;
		$arrName3[$w] = $product_item_name.' '.$batch_code;
		$w++;
	}
	
$table_name = $_SESSION['db_prefix']."_product_store";
$table_name2 = $_SESSION['db_prefix']."_product_store_lines";
$product_query = "SELECT $table_name.product_item_id,  $table_name.item_name, $table_name2.product_store_line_id, $table_name2.batch_code FROM $table_name, $table_name2 WHERE $table_name.product_item_id=$table_name2.product_item_id AND ($table_name2.quantity_in - $table_name2.quantity_out) > 0 and subCategory = 'Sales product' ORDER BY $table_name.item_name DESC";
$product_result = $con->query($product_query);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while($row = $product_result->fetch_assoc()) {
		$product_store_line_id = $row['product_store_line_id'];
		$product_item_name = $row['item_name'];
		$batch_code = $row['batch_code'];
		
			
		$arrId4[$w] = $product_store_line_id;
		$arrName4[$w] = $product_item_name.' '.$batch_code;
		$w++;
	}
	

if ($show==1) {
$box_select = $_GET['box_select'];
if ($box_select=='A') {
$product_store_line_id = $_GET['production_product_no_select'];
}

if ($box_select=='B') {
$product_store_line_id = $_GET['sales_product_no_select'];
}
	
$table_name = $_SESSION['db_prefix']."_product_store";
$table_name2 = $_SESSION['db_prefix']."_product_store_lines";
$batch_no_query = "SELECT $table_name.product_item_id,  $table_name.item_name, $table_name2.batch_code, ($table_name2.quantity_in - $table_name2.quantity_out) AS stock_quantity FROM $table_name, $table_name2 WHERE $table_name.product_item_id=$table_name2.product_item_id AND $table_name2.product_store_line_id = '".$product_store_line_id."' ";
$batch_no_result = $con->query($batch_no_query);
$row = mysqli_fetch_assoc($batch_no_result);
$item_name = $row['item_name'];
$batch_code = $row['batch_code'];
$stock_quantity = $row['stock_quantity'];

}


?>

<link href="../css/main.css" rel="stylesheet" type="text/css" />

<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 

</head>
<?php
if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
?>
<body>

<div class="main_frame">
<div class="page_head_frame">
        <label class="label_page_head">Batch code store labels </label>
</div>

<?php 
if ($show==0) {
?>
<div class="page_middle_frame">
<form action="stock_batch_no_display.php" method="get" name="form1">
<table width="698" border="0">
<tr>
<td colspan="2">Select  batch code to print store label for:</td>
<td width="248"><input name="show" type="hidden" value="1" />
  <img src="../images/info_blue.png" width="16" height="16" />only  items with stock can be selected</td>
</tr>
<tr>
  <td width="130">Production product:</td>
  <td width="306">
    <select name="production_product_no_select" class="selectbox300" id="production_product_no_select"  onfocus="document.getElementById('box_select').value='A'; document.getElementById('sales_product_no_select').selectedIndex=0;">
      <option value=" " selected="selected" >&nbsp;</option>
      <?php
    	for ($j = 0; $j < count($arrId3); $j++) {
			echo "<option value=".$arrId3[$j].">".$arrName3[$j]."</option>";	
		}
     ?>
    </select>
    </td>
  <td rowspan="2"><input name="box_select" id="box_select" type="hidden" value="" /><input type="submit" name="date_select_button" id="date_select_button" value="Select" class="imagebutton" onclick="needToConfirm = false;"/></td>
</tr>
<tr>
  <td>Sales product:</td>
  <td><select name="sales_product_no_select" class="selectbox300" id="sales_product_no_select"  onfocus="document.getElementById('box_select').value='B'; document.getElementById('production_product_no_select').selectedIndex=0;">
    <option value=" " selected="selected" >&nbsp;</option>
    <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
  </select></td>
  </tr>
</table>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("box_select","req","- product.");
  
</script>           
</div>
<?php 
}
?>

<?php 
if ($show==1) {
?>
<div class="page_middle_frame">
<div  style="text-align:center;">
<label style="font-size:18px; font-weight:bold"><?php echo $item_name ?></label><br />
<br />
<br />


<label style="font-size:36px; font-weight:bold"><?php echo $batch_code ?></label>
<br />
<br />
Stock quantity: <?php echo $stock_quantity ?><br />
  <br /><br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
  <br />
  <br />
</div>
<form action="stock_batch_no_print.php" method="get" target="_blank" >
<input name="product_store_line_id_text" type="hidden" value="<?php echo $product_store_line_id ?>" />
<input name="print_button" type="submit" class="imagebutton" value="Print store label" />
<input type="checkbox" name="stock_quantity_checkbox" id="stock_quantity_checkbox" />
print current stock quantity
<div style="float:right"><input name="new_button" type="button" value="Select new" class="imagebutton" onclick="needToConfirm = false; window.location='stock_batch_no_display.php?show=0';"/></div>
</form>
</div>
<?php
} ?>


</div>

<?php include ('../navigation/side_bar.php'); ?>

</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "store/store_main.php?date=&branch=";	
    include ("../navigation/store_sidebar.php");?>
    <?php include ('../navigation/side_bar.php'); ?>
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>
</html>
