<!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";
$estimated_query = "SELECT sum(quantity) AS summed_quantity FROM $table_name WHERE production_no = '".$production_no."' AND action = 'skip' GROUP BY production_no ";
$estimated_result = mySQL_query($estimated_query);
$estimated_num = mysql_num_rows($estimated_result);
if ($estimated_num!=0) {
$skip_estimated = mysql_result($estimated_result, 0, "summed_quantity");
}
else {
	$skip_estimated = 0;
}

$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$counted_query = "SELECT sum(quantity) AS summed_quantity FROM $table_name WHERE production_no = '".$production_no."' AND action = 'skip_count' GROUP BY production_no ";
$counted_result = mySQL_query($counted_query);
$counted_num = mysql_num_rows($counted_result);
if ($counted_num!=0) {
$skip_counted = mysql_result($counted_result, 0, "summed_quantity");
}
else {
	$skip_counted = 0;
}

$skip_max_count = $skip_estimated - $skip_counted;


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

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

$max_count = $estimated - $counted;

$table_name = $_SESSION['db_prefix']."_mix_design";
$est_count_query = "SELECT est_qty FROM $table_name WHERE mix_design = '".$mix_design_name."'  ";
$est_count_result = mySQL_query($est_count_query);
$est_count_num = mysql_num_rows($est_count_result);
$est_count = mysql_result($est_count_result, 0, "est_qty");


?>

<!--jscript-->
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only_decimal.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 skip_validate_required(input,alerttxt,maxvalue)
{
with (input)
  {
  if (value>maxvalue)
    {
    alertMessage(1, 'wet_count.php', 'The skip quantity entered makes the total counted skip quantity to exceed the estimated skip quantity.<br><br>You can adjust the quantity or click the Count button again to save.');
	document.getElementById('counted_text').disabled = false;
	document.getElementById('counted_text').value = document.getElementById('skip_text').value * <?php echo $est_count ?>; 	
	return false;
	}
  else
    {
	document.getElementById('counted_text').disabled = false;
	document.getElementById('counted_text').value = document.getElementById('skip_text').value * <?php echo $est_count ?>; 	
    return true;
    }
  }
 
  
}

</script> 



<script>
function check_count() {
document.getElementById('count_check_div').hidden=true;
document.getElementById('count_alert').value='no';
var new_count = document.getElementById('counted_text').value;
var est_count = '<?php echo $est_count ?>';
var skip_count = parseFloat(document.getElementById('skip_text').value).toFixed(1);;
var prog_count = skip_count * est_count;
var min_count = skip_count * (est_count * (98 / 100));
var max_count = skip_count * (est_count * (102 / 100));

if (new_count>max_count) { 
alertMessage(1, '', 'The counted quantity of '+new_count+' is >2% more than the estimated quantity for '+skip_count+' skips.');
document.getElementById('count_check_div').hidden=false;
document.getElementById('difference_text').value = 'The counted quantity of '+new_count+' is >2% more than the estimated quantity for '+skip_count+' skips.';
document.getElementById('count_alert').value='more';
}


if (new_count<min_count) { 
alertMessage(1, '', 'The counted quantity of '+new_count+' is >2% less than the estimated quantity for '+skip_count+' skips.');
document.getElementById('count_check_div').hidden=false;
document.getElementById('difference_text').value = 'The counted quantity of '+new_count+' is >2% less than the estimated quantity for '+skip_count+' skips.';
document.getElementById('count_alert').value='less';
}


}
</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 wet 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="wet_count_save.php" method="get" name="form1" id="form1">  
  Skips allready counted: <?php echo number_format($skip_counted, 1, '.', ',') ?>
  <input type="hidden" name="skip_allready_counted" id="skip_allready_counted" value="<?php echo $skip_counted ?>" />
  &nbsp;&nbsp;
  Skips estimated: <?php echo number_format($skip_estimated, 1, '.', ',') ?><br />
<br />

  Allready counted: <?php echo number_format($counted, 0, '.', ',') ?>
  <input type="hidden" name="allready_counted" id="allready_counted" value="<?php echo $counted ?>" />
  &nbsp;&nbsp;
  Estimated: <?php echo number_format($estimated, 0, '.', ',') ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Production date: &nbsp;&nbsp;&nbsp;<?php echo date("l, d-m-Y", strtotime($production_date)) ?> <br />
  <br />
<div style="float:left">Produced on: &nbsp;&nbsp; <?php echo date("d-m-Y", strtotime($production_date)) ?> <input name="count_date" type="hidden" value="<?php echo $production_date ?>" /></div>
<?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 /><br />

  Counted skips produced:&nbsp;&nbsp;&nbsp; 
  <input type="text" name="skip_text" id="skip_text" class="text60" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\..).*/, '$1')" onBlur="skip_validate_required(skip_text, '', <?php echo $skip_max_count ?>)" autocomplete="off" onfocus = "this.select(); document.getElementById('counted_text').value=''; document.getElementById('counted_text').disabled = true; document.getElementById('count_check_div').hidden=true;"/><br />
<br />
 
  
  Counted wet tiles:&nbsp;&nbsp;&nbsp; 
  <input type="text" name="counted_text" id="counted_text" class="text60" onkeypress="return numbersonly(this, event)" onblur="check_count();" autocomplete="off"  disabled="disabled" onfocus = "this.select(); document.getElementById('count_check_div').hidden=true;"/>
  &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 ?>" />
  <input name="mix_design_name_text" type="hidden" value="<?php echo $mix_design_name ?>" />
  <input type="hidden" name="count_alert" id="count_alert" value="no"/>
</form>
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("skip_text","req","- counted skips.");
  frmvalidator.addValidation("counted_text","req","- counted quantity.");
  frmvalidator.addValidation("final_group","selone","- final count.");
</script>
</script>
  <br />
<div id="count_check_div" hidden="true">
  <img src="../images/exclamation_mark_red_small.png" width="20" height="32" />
  <textarea name="difference_text" id="difference_text" cols="1" rows="1" style="width:650px;; font-family:Tahoma, Geneva, sans-serif;  font-size:12px; font-weight:bold; border:hidden; background-color:inherit;"></textarea>

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