<!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_no = $_GET['production_no'];	
	
$table_name = $_SESSION['db_prefix']."_production_plan";
$plan_query = "SELECT production_no, production_date, batch_code, mix_design_name FROM $table_name WHERE production_no = '".$production_no."' ";
$plan_result = mySQL_query($plan_query);
$plan_num = mysql_num_rows($plan_result);
$production_date = mysql_result($plan_result, 0, "production_date");
$batch_code = mysql_result($plan_result, 0, "batch_code");

$table_name = $_SESSION['db_prefix']."_production_plan";
$plan_other_query = "SELECT production_no, production_date, batch_code, mix_design_name, cancelled FROM $table_name WHERE production_no <> '".$production_no."' AND 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 />
Batch code: <?php echo $batch_code ?>
  <table id="table_details_display">
    <tr>
      <td width="181" >Product</td>
      <td width="24" align="center" >&nbsp;</td>
      <td width="66" align="center">Planned<br />
        skip/batch</td>
      <td width="67" align="center">Skip/batch<br />
        produced</td>
      <td width="66" align="center">Estimated<br />
        products</td>
      <td width="66" align="center">Produced<br />
wet products</td>
      <td width="62" align="center">Produced<br />
        dry products</td>
      <td width="70" align="center">Depalleted products</td>
      <td width="58" align="center">Pallets packed</td>
    </tr>
    <?php
$total=0;
$i=0;
while ($i<$plan_num) {
		$line_production_no = mysql_result($plan_result, $i, "production_no");
		$mix_design_name = mysql_result($plan_result, $i, "mix_design_name");
		$cancelled = mysql_result($plan_other_result, $i, "cancelled");
				
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_query = "SELECT SUM(quantity) AS 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");
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_count_query = "SELECT SUM(quantity) AS 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);
		if ($skip_count_num >0) {
		$skip_count = mysql_result($skip_count_result, 0, "quantity");
		}
		else {
		$skip_count = '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);
		if ($estimated_num>0) {
		$estimated_quantity = mysql_result($estimated_result, 0, "quantity");
		}
		else {
		$estimated_quantity='0';
		}
		
				
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_query = "SELECT SUM(quantity) AS 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);
		if ($wet_num>0) {
		$wet_quantity = mysql_result($wet_result, 0, "quantity");
		}
		else {
		$wet_quantity = '0';
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dry_query = "SELECT SUM(quantity) AS 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);
		if ($dry_num>0) {
		$dry_quantity = mysql_result($dry_result, 0, "quantity");
		}
		else {
		$dry_quantity = '0';
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dep_query = "SELECT SUM(quantity) AS 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);
		if ($dep_num>0) {
		$dep_quantity = mysql_result($dep_result, 0, "quantity");
		}
		else {
		$dep_quantity = '0';
		}
		
		$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><?php echo $mix_design_name ?></td>
      <td align="center"><?php if ($cancelled=='yes') {?>
        <img src="../images/round_red.png" width="12" height="12" />
        <?php } else { ?>
        <img src="../images/round_green.png" width="12" height="12" />
        <?php } ?></td>
      <td align="right"><?php echo number_format($skip_quantity, 1, '.', ',') ?></td>
      <td align="right"><?php echo number_format($skip_count, 1, '.', ',') ?></td>
      <td align="right"><?php echo number_format($estimated_quantity, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($wet_quantity, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($dry_quantity, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($dep_quantity, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($pallets_quantity, 0, '.', ',') ?></td>
    </tr>
    <?php
  $i++;
}
?>
  </table>
  <br />
Other production today:
<table id="table_details_display">
    <?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");
		$cancelled = mysql_result($plan_other_result, $i, "cancelled");
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_query = "SELECT SUM(quantity) AS quantity FROM $table_name WHERE  production_no = '".$line_production_no."' AND action = 'skip' ";
		$skip_result = mySQL_query($skip_query);
		$skip_num = mysql_num_rows($skip_result);
		if ($skip_num>0) {
		$skip_quantity = mysql_result($skip_result, 0, "quantity");
		}
		else {
			$skip_quantity ='0';
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_count_query = "SELECT SUM(quantity) AS 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);
		if ($skip_count_num >0) {
		$skip_count = mysql_result($skip_count_result, 0, "quantity");
		}
		else {
		$skip_count = '0';
		}
				
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$estimated_query = "SELECT SUM(quantity) AS 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);
		if ($estimated_num>0) {
		$estimated_quantity = mysql_result($estimated_result, 0, "quantity");
		}
		else {
		$estimated_quantity='0';
		}
		
				
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_query = "SELECT SUM(quantity) AS 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);
		if ($wet_num>0) {
		$wet_quantity = mysql_result($wet_result, 0, "quantity");
		}
		else {
		$wet_quantity = '0';
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dry_query = "SELECT SUM(quantity) AS 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);
		if ($dry_num>0) {
		$dry_quantity = mysql_result($dry_result, 0, "quantity");
		}
		else {
		$dry_quantity = '0';
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dep_query = "SELECT SUM(quantity) AS 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);
		if ($dep_num>0) {
		$dep_quantity = mysql_result($dep_result, 0, "quantity");
		}
		else {
		$dep_quantity = '0';
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$pallets_query = "SELECT SUM(quantity) AS 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="180"><?php echo $mix_design_name ?></td>
      <td width="26" align="center"><?php if ($cancelled=='yes') {?>
        <img src="../images/round_red.png" width="12" height="12" />
        <?php } else { ?>
        <img src="../images/round_green.png" width="12" height="12" />
        <?php } ?></td>
      <td width="66"><?php echo number_format($skip_quantity, 1, '.', ',') ?></td>
      <td width="66" align="right"><?php echo number_format($skip_count, 1, '.', ',') ?></td>
      <td width="66" align="right"><?php echo number_format($estimated_quantity, 0, '.', ',') ?></td>
      <td width="66" align="right"><?php echo number_format($wet_quantity, 0, '.', ',') ?></td>
      <td width="66" align="right"><?php echo number_format($dry_quantity, 0, '.', ',') ?></td>
      <td width="66" align="right"><?php echo number_format($dep_quantity, 0, '.', ',') ?></td>
      <td width="58" align="right"><?php echo number_format($pallets_quantity, 0, '.', ',') ?></td>
    </tr>
    <?php
  $i++;
}
?>
  </table><br />
<br />
  
  <a href="day_production_print.php?production_no=<?php echo $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>
