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

<script language="javascript" src="../jscript/chainedselects.js"></script>
<script language="javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  
<?php
include ("../navigation/header.php");
$page_name = "Production-edit";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");

$production_no = $_GET['production_no'];

$table_name = $_SESSION['db_prefix']."_production_plan";
$plan_query = "SELECT production_no, production_date, mix_design_name, sub_category FROM $table_name WHERE production_no = '".$production_no."' ";
$plan_result = mySQL_query($plan_query);
$production_date = mysql_result($plan_result, 0, "production_date");
$mix_design_name = mysql_result($plan_result, 0, "mix_design_name");
$sub_category = mysql_result($plan_result, 0, "sub_category");


$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$count_query = "SELECT SUM(quantity) as summed_quantity FROM $table_name WHERE production_no = '".$production_no."' AND action = 'dry_count' GROUP BY production_no ";
$count_result = mySQL_query($count_query);
$count_num = mysql_num_rows($count_result);
$summed_quantity = mysql_result($count_result, 0, "summed_quantity");

$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$plan_line_query = "SELECT plan_line_id, action_date, quantity FROM $table_name WHERE production_no = '".$production_no."' AND action = 'dry_count' ";
$plan_line_result = mySQL_query($plan_line_query);
$plan_line_num = mysql_num_rows($plan_line_result);

?>

</head>

<body>
<div class="main_frame" style="height:auto; min-height:555px;">
<div class="page_head_frame">
          <table width="690" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="493"><label class="label_page_head">
              Edit production plan
              <?php echo $production_no ?></label>
              </td>
              <td width="197"><label style="font-size:18px; "></label><br /><label style="font-size:18px; "></label></td>
            </tr>
          </table>
        </div>
        <br />
<div class="page_middle_frame">        
<div class="page_inside_frame">        

<form action="dry_count_edit_save.php" method="get" name="form1" id="form1">
  <p>
    <label style="font-size:18px;"> Production no:  <?php echo $production_no ?></label> 
    <input name="production_no_text" type="hidden" value="<?php echo $production_no ?>" /> <br />
    <label style="font-size:18px;"> Production to produce:  <?php echo $mix_design_name?></label>
    &nbsp;&nbsp;
    <label style="font-size:14px;">(<?php echo$sub_category ?> ) </label>  
  <br />
  <br />
  <label style="font-size:18px;">Total products counted:  <?php echo $summed_quantity ?></label>
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
    <br />
    New counted quantity:</p>
  <table width="372" id="table_display">
  <?php
  $i=0;
  while ($i<$plan_line_num) {
	  $plan_line_id = mysql_result($plan_line_result, $i, "plan_line_id");
	  $action_date = mysql_result($plan_line_result, $i, "action_date");
	  $quantity = mysql_result($plan_line_result, $i, "quantity");
   ?>  
    <tr>
      <td width="98"><?php echo date("d-m-Y", strtotime($action_date)) ?>
        <input type="hidden" name="count_date<?php echo $i ?>" id="count_date<?php echo $i ?>"  value="<?php echo $action_date ?>"/><input type="hidden" name="plan_line_id<?php echo $i ?>" id="plan_line_id<?php echo $i ?>" value="<?php echo $plan_line_id ?>" /></td>
      <td width="116"><?php echo $quantity ?><input name="saved_quantity<?php echo $i ?>" id="saved_quantity<?php echo $i ?>" type="hidden" value="<?php echo $quantity ?>" /></td>
      <td width="142">new count: 
        <input type="text" name="count_text<?php echo $i ?>" id="count_text<?php echo $i ?>" class="text60"  width="60px;"/></td>
    </tr>
   <?php 
   $i++;
}
?>
<input name="line_num" type="hidden" value="<?php echo $i ?>" />

  </table>
  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="submit" name="count_button" id="count_button" value="Save" class="imagebutton"/>
  </p>
</form>
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("counted_text","req","- counted quantity.");
</script>
  <br />
  <br />
<br />
<br />
<br />
</div>
<div class="page_inside_frame">
  <input name="close_button" type="button" value="Close" class="imagebutton" onclick="cancel_confirmation(3, '../production/production_main.php');"/>
  </div>
</div>
</div>
</form>
<?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");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>