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

$packing_no = $_GET['packing_no'];

$table_name = $_SESSION['db_prefix']."_production";
$production_no_query = "SELECT production_no, production_date, product_item_id, batch_code, produced_no, packed_no, packing_date, damaged_no, packing_design_no FROM $table_name WHERE packing_no = '".$packing_no."'  ORDER BY production_id DESC LIMIT 1";
$production_no_result = $con->query($production_no_query);
$row = mysqli_fetch_assoc($production_no_result);
$production_no = $row['production_no'];
$production_date = $row['production_date'];
$product_item_id = $row['product_item_id'];
$bb_string = $row['batch_code'];
$produced_no = $row['produced_no'];
$packed_no = $row['packed_no'];
$damaged_no = $row['damaged_no'];
$packing_date = $row['packing_date'];
$packing_design_no = $row['packing_design_no'];

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

$table_name = $_SESSION['db_prefix']."_packaging_design";
$packing_name_query = "SELECT packaging_design FROM $table_name WHERE design_no = '".$packing_design_no."'  ";
$packing_name_result = $con->query($packing_name_query);
$row = mysqli_fetch_assoc($packing_name_result);
$packing_design_name = $row['packaging_design'];


$table_name = $_SESSION['db_prefix']."_packaging_design";
$pack_design_query = "SELECT design_no, packaging_design FROM $table_name ORDER BY packaging_design ASC";
$pack_design_result = $con->query($pack_design_query);
$pack_design_num = mysqli_num_rows($pack_design_result);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $pack_design_num) {
		$row = mysqli_fetch_assoc($pack_design_result);
		$arrId2[$w] = $row['design_no'];
		$arrName2[$w] = $row['packaging_design'];
		$w++;
	}
	
$packing_date_edit = strtotime(date($packing_date));
$d = date("d", $packing_date_edit );
$m = date("m", $packing_date_edit );
$y = date("Y", $packing_date_edit );
?>

<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>  

<script>
function packed_calc() {
	var produced = document.getElementById('produced_text').value;
	var e = document.getElementById("damaged_select");
	var damaged = e.options[e.selectedIndex].value;
	var packed = 0;
	
	packed = produced - damaged;
	
	document.getElementById('packed_no_text').value = packed; 
		
}
</script>



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

<div class="main_frame">
<div class="page_head_frame">
        <label class="label_page_head">Edit Packing </label>
</div>


<div class="page_middle_frame">
<form action="packing_edit_save.php" method="get" name="form2">
Packing no <?php echo $packing_no ?> for <?php echo $product_name ?> on <?php echo date("l, d-m-Y", strtotime($packing_date))  ?>:
<input name="packing_date_day" id="packing_date_day" type="hidden" value="<?php echo date("Y-m-d", strtotime($packing_date)) ?>" />
<input type="hidden" name="packing_no" id="packing_no" value="<?php echo $packing_no ?>" />
 <br />
<br />
Production no:&nbsp;&nbsp;<?php echo $production_no ?>&nbsp;&nbsp;&nbsp;&nbsp;Production date:&nbsp;&nbsp;<?php echo date("l, d-m-Y", strtotime($production_date)) ?>

<br />
<br />
Best before:&nbsp;&nbsp;<?php echo $bb_string; ?> 
<input name="batch_code_string" type="hidden" value="<?php echo $bb_string ?>" /><br />
<br />

<table width="523" border="0" cellpadding="0">
  <tr>
    <td height="25">Packing date:</td>
    <td><?php
		$myCalendar = new tc_calendar("packing_date_edit", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2018, 2025);
		$myCalendar->writeScript();
?></td>
    </tr>
  <tr>
    <td width="167">No of products packed:</td>
    <td width="269"><label for="skips_select"></label>
      <input type="text" name="produced_text" id="produced_text" class="text70" onfocus = "this.select(); "onkeypress="return numbersonly(this, event)" value="<?php echo $packed_no ?>" onchange="packed_calc();" /> </td>
    </tr>
  <tr>
    <td>No of broken products:</td>
    <td><select name="damaged_select" id="damaged_select"  class="select80" onchange="packed_calc();">
      <option value="0">0</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
      <option value="9">9</option>
      <option value="10">10</option>
      <option value="<?php echo $damaged_no ?>" selected="selected"><?php echo $damaged_no ?></option>
      
    </select></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>New no of products packed:</td>
    <td><input type="text" name="packed_no_text" id="packed_no_text" class="text50" onfocus="packed_calc();" readonly="readonly"/></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Packing design used:</td>
    <td><select name="pack_design_select" autofocus="autofocus" class="selectbox300" id="pack_design_select" >
      <option value="<?php echo $packing_design_no ?>" selected="selected"><?php echo $packing_design_name ?></option>
      <?php
    	for ($j = 0; $j < count($arrId2); $j++) {
			echo "<option value=".$arrId2[$j].">".$arrName2[$j]."</option>";	
		}
     ?>
    </select></td>
    </tr>
</table>
<br />
<br />
<table width="600" border="0">
  <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="product_item_id" id="product_item_id" value="<?php echo $product_item_id ?>" />
        <input name="close_button" type="button" class="imagebutton" id="close_button" onClick="cancel_confirmation(3, '../production/production_main.php');" value="Close"/>
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onClick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
</table>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form2");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("packed_no_text","req","- packed products.");
</script>
</div>



</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>
