<!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 = "Packing";
include ("../navigation/access.php");
require_once ('../include/tc_calendar.php');


$show = $_GET['show'];


$table_name = $_SESSION['db_prefix']."_production";
$code_query = "SELECT production_no, production_date, product_item_id, produced_no FROM $table_name ORDER BY production_no DESC";
$code_result = $con->query($code_query);
$code_num = mysqli_num_rows($code_result);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while($row = $code_result->fetch_assoc()) {
		$production_no = $row['production_no'];
		$production_date = $row['production_date'];
		$produced_no = $row['produced_no'];
		$product_item_id = $row['product_item_id'];
			$table_name = $_SESSION['db_prefix']."_product_store";
			$item_name_query = "SELECT item_name FROM $table_name WHERE product_item_id = '".$product_item_id."' ";
			$item_name_result = $con->query($item_name_query);
			$row = mysqli_fetch_assoc($item_name_result);
			$item_name = $row['item_name'];
			
		$arrId4[$w] = $production_no;
		$arrName4[$w] = $production_no.' '.date("d-m-Y", strtotime($production_date)).' '.$item_name.' '.$produced_no;
		$w++;
	}
	

if ($show==1) {
$production_print_no = $_GET['production_no_select'];
	
$table_name = $_SESSION['db_prefix']."_production";
$batch_no_query = "SELECT production_date, product_item_id, batch_code, produced_no  FROM $table_name WHERE production_no = '".$production_print_no."'  ";
$batch_no_result = $con->query($batch_no_query);
$row = mysqli_fetch_assoc($batch_no_result);
$production_date = $row['production_date'];
$product_item_id = $row['product_item_id'];
$batch_code = $row['batch_code'];
$produced_no = $row['produced_no'];

$table_name = $_SESSION['db_prefix']."_product_store";
$item_name_query = "SELECT item_name FROM $table_name WHERE product_item_id = '".$product_item_id."'  ";
$item_name_result = $con->query($item_name_query);
$row = mysqli_fetch_assoc($item_name_result);
$item_name = $row['item_name'];


	}
?>

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></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> 
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/go_to_url.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>  


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

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

<?php 
if ($show==0) {
?>
<div class="page_middle_frame">
<form action="print_batch.php" method="get" name="form1">
<table width="649" border="0">
<tr>
<td colspan="2">Select production no to print batch code for:</td>
<td width="260"><input name="show" type="hidden" value="1" /></td>
</tr>
<tr>
  <td width="117">Production no:</td>
  <td width="260">
    <select name="production_no_select" autofocus="autofocus" class="selectbox300" id="production_no_select" >
      <option value=" " selected="selected" >&nbsp;</option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select>
    </td>
  <td><input type="submit" name="date_select_button" id="date_select_button" value="Select" class="imagebutton" onclick="needToConfirm = false;"/></td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("production_no_select","req","- a production no.");
</script>                
</div>
<?php 
}
?>

<?php 
if ($show==1) {
?>
<div class="page_middle_frame">
Batch code for production no <?php echo $production_print_no ?> of <?php echo date("l, d-m-Y", strtotime($production_date)) ?> for <?php echo $item_name ?>.<br />
<br />
No of products produced: <?php echo $produced_no ?><br />
<br /><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<label style="font-size:24px; font-weight:bold;"><?php echo $batch_code ?></label>
<br />
<br />
<br />
<div style="margin-top:10px; margin-left:25px;">
<form action="../store/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
</form>
</div>


</div>
<?php
} ?>


</div>

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

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