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

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
</head>
<?php
if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");
	
$production_date = $_GET['production_date'];	
	

$table_name = $_SESSION['db_prefix']."_production_plan";
$plan_other_query = "SELECT production_no, production_date, batch_code, mix_design_name FROM $table_name WHERE production_date = '".$production_date."' ";
$plan_other_result = mySQL_query($plan_other_query);
$plan_other_num = mysql_num_rows($plan_other_result);


?>
<body>

<div class="main_frame">
<table width="630" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="52" colspan="4" align="left" valign="top"><div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Day production plan &nbsp;&nbsp;<?php echo date("l, d-m-Y", strtotime($production_date)) ?></label></td>
            </tr>
        </table>
      </div>
       

<div class="page_middle_frame"><br />
  <br />
  <table id="table_details_display">
  <thead>
  <tr>
      <td>Product</td>
      <td align="center">Planned<br />
        skip/batch</td>
      <td align="center">Produced <br />
        skips/batch</td>
      <td align="center">Estimated<br />
        products</td>
      <td align="center">Produced<br />
        wet products</td>
      <td align="center">Depalleted</td>
      <td align="center">Pallets</td>
      <td align="center">&nbsp;</td>
    </tr>
    </thead>
    <?php
$total=0;
$i=0;
while ($i<$plan_other_num) {
		$line_production_no = mysql_result($plan_other_result, $i, "production_no");
		$mix_design_name = mysql_result($plan_other_result, $i, "mix_design_name");
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_query = "SELECT quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'skip' ";
		$skip_result = mySQL_query($skip_query);
		$skip_quantity = mysql_result($skip_result, 0, "quantity");
		
		$skip_count=0;
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_count_query = "SELECT quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'skip_count' ";
		$skip_count_result = mySQL_query($skip_count_query);
		$skip_count_num = mysql_num_rows($skip_count_result);
		$k=0;
		while ($k<$skip_count_num) {
		$s_quantity = mysql_result($skip_count_result, $k, "quantity");
		$skip_count = $skip_count + $s_quantity;
		$k++;
		}
				
		$estimated_quantity=0;
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$estimated_query = "SELECT quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'estimated' ";
		$estimated_result = mySQL_query($estimated_query);
		$estimated_num = mysql_num_rows($estimated_result);
		$k=0;
		while ($k<$estimated_num) {
		$e_quantity = mysql_result($estimated_result, $k, "quantity");
		$estimated_quantity = $estimated_quantity + $e_quantity;
		$k++;
		}
		
		$wet_quantity=0;		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_query = "SELECT quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'wet_count' ";
		$wet_result = mySQL_query($wet_query);
		$wet_num = mysql_num_rows($wet_result);
		$k=0;
		while ($k<$wet_num) {
		$w_quantity = mysql_result($wet_result, $k, "quantity");
		$wet_quantity = $wet_quantity + $w_quantity;
		$k++;
		}
		
		$dry_quantity = 0;
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dry_query = "SELECT quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'dry_count' ";
		$dry_result = mySQL_query($dry_query);
		$dry_num = mysql_num_rows($dry_result);
		$k=0;
		while ($k<$dry_num) {
		$d_quantity = mysql_result($dry_result, $k, "quantity");
		$dry_quantity = $dry_quantity + $d_quantity;
		$k++;
		}
		
		$dep_quantity = 0;
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dep_query = "SELECT quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'dep_count' ";
		$dep_result = mySQL_query($dep_query);
		$dep_num = mysql_num_rows($dep_result);
		$k=0;
		while ($k<$dep_num) {
		$d_quantity = mysql_result($dep_result, $k, "quantity");
		$dep_quantity = $dep_quantity + $d_quantity;
		$k++;
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$pallets_query = "SELECT quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'pallets' ";
		$pallets_result = mySQL_query($pallets_query);
		$pallets_num = mysql_num_rows($pallets_result);
		if ($pallets_num>0) {
		$pallets_quantity = mysql_result($pallets_result, 0, "quantity");
		}
		else {
		$pallets_quantity = '0';
		}
		?>
    
    <tr>
      <td width="154"><?php echo $mix_design_name ?></td>
      <td width="76" align="right"><?php echo number_format($skip_quantity, 1, '.', ',') ?></td>
      <td width="76" align="right"><?php echo number_format($skip_count, 1, '.', ',') ?></td>
      <td width="76" align="right"><?php echo number_format($estimated_quantity, 0, '.', ',') ?></td>
      <td width="96" align="right"><?php echo number_format($wet_quantity, 0, '.', ',') ?></td>
      <td width="76" align="right"><?php echo number_format($dep_quantity, 0, '.', ',') ?></td>
      <td width="76" align="right"><?php echo number_format($pallets_quantity, 0, '.', ',') ?></td>
      <td width="34" align="right"><a href="count_production_print.php?production_no=<?php echo $line_production_no ?>" target="_blank" onMouseover="ddrivetip('Click to print count sheet', 150)"; onMouseout="hideddrivetip()"><img src="../images/print.png" width="24" height="20" /></a></td>
    </tr>
    <?php
  $i++;
}
?>
  </table><br />
<br />
  
  <a href="day_production_print.php?production_no=<?php echo $line_production_no ?>" target="_blank"><input name="print_button" type="button" value="Print" class="imagebutton" /></a>
  <br />
  <br />
  <br />
  <br />
<br />
<br />
<br />

</div>
    </td>
    </tr>
    </table>
</div>

<?php include ('../navigation/side_bar.php'); ?>

</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "production/production_main.php";	
    include ("../navigation/[production_sidebar.php");?>
    <?php include ('../navigation/side_bar.php'); ?>
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>
</html>
