<!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" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.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";
$tiles_query = "SELECT * FROM $table_name WHERE production_date = '".$production_date."' GROUP BY mix_design_name";
$tiles_result = mySQL_query($tiles_query);
$tiles_num = mysql_num_rows($tiles_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 &nbsp;&nbsp;<?php echo date("l, d-m-Y", strtotime($production_date)) ?></label></td>
            </tr>
        </table>
      </div>
       
<div class="page_middle_frame">
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
<table width="692" id="scroll_table" class="data_display" >
  <thead>
    <tr>
      <th width="139" align="center">Product</th>
      <th width="58" align="center">Planned<br />
        skips</th>
      <th width="76" align="center">Skip<br />
        produced</th>
      <th width="76" align="center">Estimated<br />
        products</th>
      <th width="96" align="center">Produced<br />
wet products</th>
      <th width="96" align="center">Produced<br />
        dry products</th>
      <th width="76" align="center">Depalleted</th>
      <th width="39" align="center">&nbsp;</th>
      </tr>
    </thead>
    <?php
$total=0;
$i=0;
while ($i<$tiles_num) {
		$mix_design_name = mysql_result($tiles_result, $i, "mix_design_name");
			
		$skip_quantity_tot=0;
		$skip_produced_tot=0;
		$est_quantity_tot=0;
		$wet_produced_tot=0;
		$dry_produced_tot=0;
		$depalleted_tot=0;
		$productionTT_body='';
			
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$name_query = "SELECT production_no, production_date  FROM $table_name WHERE mix_design_name = '".$mix_design_name."'  ";
		$name_result = mySQL_query($name_query);
		$name_num = mysql_num_rows($name_result);
		$n=0;
		while ($n<$name_num) {
			$production_no = mysql_result($name_result, $n, "production_no");
			$production_date = mysql_result($name_result, $n, "production_date");
			
		
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_query = "SELECT SUM(quantity) AS summed_skip FROM $table_name WHERE production_no = '".$production_no."' AND action = 'skip' GROUP BY action ";
		$skip_result = mySQL_query($skip_query);
		$skip_num = mysql_num_rows($skip_result);
		if ($skip_num!=0) {
		  $skip_quantity = mysql_result($skip_result, 0, "summed_skip");
		}
		else {
			$skip_quantity = 0;
		}
		$skip_quantity_tot = $skip_quantity_tot + $skip_quantity;
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_produced_query = "SELECT SUM(quantity) AS summed_skip_produced FROM $table_name WHERE production_no = '".$production_no."' AND action = 'skip_count' GROUP BY action ";
		$skip_produced_result = mySQL_query($skip_produced_query);
		$skip_produced_num = mysql_num_rows($skip_produced_result);
		if ($skip_produced_num!=0) {
		  $skip_produced = mysql_result($skip_produced_result, 0, "summed_skip_produced");
		}
		else {
			$skip_produced = 0;
		}
		$skip_produced_tot = $skip_produced_tot + $skip_produced;
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$estimated_query = "SELECT SUM(quantity) AS summed_estimated FROM $table_name WHERE production_no = '".$production_no."' AND action = 'estimated' GROUP BY action ";
		$estimated_result = mySQL_query($estimated_query);
		$estimated_num = mysql_num_rows($estimated_result);
		if ($estimated_num!=0) {
		  $est_quantity = mysql_result($estimated_result, 0, "summed_estimated");
		}
		else {
			$est_quantity = 0;
		}
		$est_quantity_tot = $est_quantity_tot + $est_quantity;
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_produced_query = "SELECT SUM(quantity) AS summed_wet_produced FROM $table_name WHERE production_no = '".$production_no."' AND action = 'wet_count' GROUP BY action ";
		$wet_produced_result = mySQL_query($wet_produced_query);
		$wet_produced_num = mysql_num_rows($wet_produced_result);
		if ($wet_produced_num!=0) {
		  $wet_produced = mysql_result($wet_produced_result, 0, "summed_wet_produced");
		}
		else {
			$wet_produced = 0;
		}
		$wet_produced_tot = $wet_produced_tot + $wet_produced;
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dry_produced_query = "SELECT SUM(quantity) AS summed_dry_produced FROM $table_name WHERE production_no = '".$production_no."' AND action = 'dry_count' GROUP BY action ";
		$dry_produced_result = mySQL_query($dry_produced_query);
		$dry_produced_num = mysql_num_rows($dry_produced_result);
		if ($dry_produced_num!=0) {
		  $dry_produced = mysql_result($dry_produced_result, 0, "summed_dry_produced");
		}
		else {
			$dry_produced = 0;
		}
		$dry_produced_tot = $dry_produced_tot + $dry_produced;
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$depalleted_query = "SELECT SUM(quantity) AS summed_depalleted FROM $table_name WHERE production_no = '".$production_no."' AND action = 'dep_count' GROUP BY action ";
		$depalleted_result = mySQL_query($depalleted_query);
		$depalleted_num = mysql_num_rows($depalleted_result);
		if ($depalleted_num!=0) {
		  $depalleted = mysql_result($depalleted_result, 0, "summed_depalleted");
		}
		else {
			$depalleted = 0;
		}
		$depalleted_tot = $depalleted_tot + $depalleted;	
		
		$productionTT_body = $productionTT_body.'<tr><td>'.$production_no.'</td><td>'.date("d-m-Y", strtotime($production_date)).'</td></tr>';
		
		
		$n++;
		}
		$productionTT_header='<b>Production for '.$mix_design_name.'</b><br><table><tr><td width=100>Prdoduction no</td><td width=100>production date</td></tr>';		
		$productionTT_footer='</table><br>Click for details.';
		$productionTT=$productionTT_header.$productionTT_body.$productionTT_footer;
		?>
    <tr>
      <td><a href="production_item_list.php?mix_design_name=<?php echo $mix_design_name ?>&date=" onMouseover="ddrivetip('<?php echo $productionTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $mix_design_name ?></a></td>
      <td align="right"><?php echo number_format($skip_quantity_tot, 1, '.', ',') ?></td>
      <td align="right"><?php echo number_format($skip_produced_tot, 1, '.', ',') ?></td>
      <td align="right"><?php echo number_format($est_quantity_tot, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($wet_produced_tot, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($dry_produced_tot, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($depalleted_tot, 0, '.', ',') ?></td>
      <td align="right"><a href="count_production_print.php?production_no=<?php echo $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>
</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>
