<!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');



$production_no = $_GET['production_no'];

$table_name = $_SESSION['db_prefix']."_production";
$production_query = "SELECT production_date, product_item_id, skips_no, batch_code, produced_no, recycled_no FROM $table_name WHERE production_no = '".$production_no."' ";
$production_result = $con->query($production_query);
$row = mysqli_fetch_assoc($production_result);
$production_date = $row['production_date'];
$product_item_id = $row['product_item_id'];
$skips_no = $row['skips_no'];
$batch_code = $row['batch_code'];
$produced_no = $row['produced_no'];
$recycled_no = $row['recycled_no'];


$table_name = $_SESSION['db_prefix']."_product_store";
$item_name_query = "SELECT item_name, mix_design_id  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);
$product_name = $row['item_name'];
$mix_design_id = $row['mix_design_id'];


$table_name = $_SESSION['db_prefix']."_mix_design";
$est_query = "SELECT design_no, est_qty FROM $table_name WHERE design_no = '".$mix_design_id."' ";
$est_result = $con->query($est_query);
$row = mysqli_fetch_assoc($est_result);
$design_no = $row['design_no'];
$est_qty = $row['est_qty'];

$production_date_edit = strtotime(date($production_date));
$d = date("d", $production_date_edit );
$m = date("m", $production_date_edit );
$y = date("Y", $production_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 production_calc() {
	
	var est_qty = <?php echo $est_qty ?>;
	
	var sskips = document.getElementById("skips_text").value;
		
	var recycled = document.getElementById("recycled_text").value;
		
	var produced = '0';
	skip_produced = +est_qty * sskips;
	produced = +skip_produced + +recycled;
	
	document.getElementById('produced_text').value = produced;
	
	alertMessage(1, '', 'The estimated number of products for '+sskips+' skips is '+skip_produced+'.<br>Total production would be now: '+produced+'.');
		
}
</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">Edit Production </label>
</div>



<div class="page_middle_frame">
<form action="production_edit_save.php" method="get" name="form2">
Production for <?php echo $product_name ?> on <?php echo date("l, d-m-Y", strtotime($production_date))  ?>:<input name="production_date_text" id="production_date_text" type="hidden" value="<?php echo $production_date ?>" />
<input type="hidden" name="mix_design_no" id="mix_design_no"  value="<?php echo $design_no ?>"/>
 <br />
<br />
Production no: <?php echo $production_no ?>&nbsp;&nbsp;
<input type="hidden" name="production_no" id="production_no" value="<?php echo $production_no ?>" />
&nbsp;&nbsp;Best before: &nbsp;&nbsp;&nbsp;<?php echo $batch_code; ?> 
<input name="batch_code_string" type="hidden" value="<?php echo $batch_code ?>" /><br />
<br />

<table width="548" border="0" cellpadding="0" >
  <tr>
    <td height="29">Production date:</td>
    <td><?php
		$myCalendar = new tc_calendar("production_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="162">No of skips:</td>
    <td width="380">
      <input type="text" name="skips_text" id="skips_text" class="text50"  value="<?php echo $skips_no ?>" onchange="production_calc();" onfocus = "this.select();"/>
      <input type="hidden" name="est_qty_text" id="est_qty_text" value="<?php echo $est_qty ?>" /></td>
    </tr>
  <tr>
    <td>No of recycled products:</td>
    <td><input type="text" name="recycled_text" id="recycled_text" class="text50"  value="<?php echo $recycled_no ?>" onfocus = "this.select();" onchange="production_calc();" /> </td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>No of produced products:</td>
    <td><input type="text" name="produced_text" id="produced_text" class="text50" value="<?php echo $produced_no ?>" onfocus = "this.select();" readonly="readonly"/></td>
    </tr>
</table>
<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("produced_text","req","- produced 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>
