<!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-wet count";
include ("../navigation/access.php");
?>

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

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


require_once ('../include/tc_calendar.php');
$count_date = strtotime(date("Y-m-d"));
$d = date("d", $count_date );
$m = date("m", $count_date );
$y = date("Y", $count_date );

$production_no = $_GET['production_no'];

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

$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$wet_counted_query = "SELECT sum(quantity) AS summed_quantity FROM $table_name WHERE production_no = '".$production_no."' AND action = 'wet_count' GROUP BY production_no ";
$wet_counted_result = mySQL_query($wet_counted_query);
$wet_counted_num = mysql_num_rows($wet_counted_result);
if ($wet_counted_num!=0) {
$wet_counted = mysql_result($wet_counted_result, 0, "summed_quantity");
}
else {
	$wet_counted = 0;
}

$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$dep_counted_query = "SELECT sum(quantity) AS summed_quantity FROM $table_name WHERE production_no = '".$production_no."' AND action = 'dep_count' GROUP BY production_no ";
$dep_counted_result = mySQL_query($dep_counted_query);
$dep_counted_num = mysql_num_rows($dep_counted_result);
if ($dep_counted_num!=0) {
$dep_counted = mysql_result($dep_counted_result, 0, "summed_quantity");
}
else {
	$dep_counted = 0;
}

$max_count = $wet_counted - $dep_counted;

?>

<!--jscript-->
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  
<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> 
<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 type="text/javascript">
function validate_required(input,alerttxt,maxvalue)
{
with (input)
  {
  if (value>maxvalue)
    {
    alertMessage(1, 'wet_count.php', 'The quantity entered makes the total counted quantity to exceed the produced quantity.<br><br>You can adjust the quantity or click the Count button again to save.');
	//input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head> 
<body>

<div class="main_frame">
<div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Production depallet count</label></td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
       <br />


<div class="page_middle_frame">
<label style="font-size:18px;"> Production no:  <?php echo $production_no.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$mix_design_name?></label>&nbsp;&nbsp;<label style="font-size:14px;">(<?php echo$sub_category ?> ) </label><br />
  <br />
<div class="page_inside_frame">
<form action="depallet_count_save.php" method="get" name="form1" id="form1">  
  Allready counted: <?php echo number_format($dep_counted, 0, '.', ',') ?>
  <input type="hidden" name="allready_counted" id="allready_counted" value="<?php echo $dep_counted ?>" />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  Wet produced: <?php echo number_format($wet_counted, 0, '.', ',') ?>&nbsp;&nbsp;&nbsp;&nbsp;Production date: &nbsp;&nbsp;&nbsp;<?php echo date("l, d-m-Y", strtotime($production_date)) ?> 
  <input name="mix_design_name_text" type="hidden" value="<?php echo $mix_design_name ?>" />
  <br />
  <br />
<?php

		$myCalendar = new tc_calendar("count_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2015, 2090);
		$myCalendar->writeScript();
?>

<br /><br />

  Pallets used:&nbsp;&nbsp;&nbsp; 
  <input type="text" name="pallets_text" id="pallets_text" class="text60" onkeypress="return numbersonly(this, event)" autocomplete="off"/><br />
<br />

  Depalleted quantity:&nbsp;&nbsp;&nbsp; 
  <input type="text" name="counted_text" id="counted_text" class="text60" onkeypress="return numbersonly(this, event)" onBlur="validate_required(counted_text, '', <?php echo $max_count ?>)" autocomplete="off"/>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  Final count:
    <label>
      <input type="radio" name="final_group" value="yes" id="final_group_0" />
      yes</label>
   &nbsp;&nbsp;
    <label>
      <input type="radio" name="final_group" value="no" id="final_group_1" />
      no</label>
   
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input type="submit" name="count_button" id="count_button" value="Count" class="imagebutton"/>
  <input name="production_no_text" type="hidden" value="<?php echo $production_no ?>" />
  </form>
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("counted_text","req","- counted quantity.");
  frmvalidator.addValidation("final_group","selone","- final count.");
</script>
  <br />

<br />
</div>
<br />
<div class="page_inside_frame" style="">
  <input name="close_button" type="button" value="Close" class="imagebutton" onclick="cancel_confirmation(3, '../production/production_main.php');"/>
  </div>
</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>
