<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php 
include ("../navigation/header.php");

$page_name = "Production-main";
include ("../navigation/access.php");

if ($permission_num==1) {

include ("../navigation/production_sidebar.php");
include('../include/period_select_date.php');	
 
$table_name = $_SESSION['db_prefix']."_production_plan";	 	
$display_query = "SELECT production_no, production_date, mix_design_name, mix_design_cost  FROM $table_name WHERE production_date >= '".$start."' AND production_date <= '".$end."' AND sub_category = 'Tiles' AND produced_wet = 'yes' GROUP BY mix_design_name";


$display_result = execsql($display_query);
$i = 0;
$display_num = mysql_num_rows($display_result);
		
?> 

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

</head>


<body>

<div class="main_frame">
<div class="page_head_frame">
  <label class="label_page_head">Production tiles</label></div>
   
<br />
<br /><br />
<br />
<?php
$page='production_tiles_list.php';
$reference_name='';
$reference='';
$reference_name_2='';
$reference_2='';
include('../include/period_select_block.php');
?>


    
<br />
<div class="page_middle_frame">
<!--jscript-->
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
                         	 ]
				} );
			} );
		</script>    	
<table width="572" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="167" align="left">Mix design</th>
		  <th width="23" align="left">&nbsp;</th>
		  <th width="41" align="left">Skips</th>
		  <th width="104" align="left">Wet produced</th>
		  <th width="96" align="left">Average/skip</th>
		  <th width="113" align="left">Estimated/skip </th>
	    </tr>
	</thead>
	<tbody>
  <?php
  	$b4_tot = 0;
	$b5_tot = 0;
    $i=0;
    while($i < $display_num){
		 $b0 = mysql_result($display_result, $i, "production_no");
		 $b1 = mysql_result($display_result, $i, "production_date");
		 $b2 = mysql_result($display_result, $i, "mix_design_name");
		 $b3 = mysql_result($display_result, $i, "mix_design_cost");
		 $b10 = substr($b0,4,8);
		 
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$skip_count_query = "SELECT SUM(quantity) AS summed_quantity FROM $table_name WHERE mix_design_name = '".$b2."' AND  action = 'skip_count' AND action_date >= '".$start."' AND action_date <= '".$end."' GROUP BY mix_design_name ";
		$skip_count_result = mySQL_query($skip_count_query);
		$b4 = mysql_result($skip_count_result, 0, "summed_quantity");
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_count_query = "SELECT SUM(quantity) AS summed_quantity FROM $table_name WHERE mix_design_name = '".$b2."' AND  action = 'wet_count' AND action_date >= '".$start."' AND action_date <= '".$end."' GROUP BY mix_design_name ";
		$wet_count_result = mySQL_query($wet_count_query);
		$b5 = mysql_result($wet_count_result, 0, "summed_quantity");
		
		
		if ($b4!=0) {
		$b6 = $b5 / $b4;
		}
		else {
			$b6=0;
		}
		
		$table_name = $_SESSION['db_prefix']."_mix_design";
		$est_query = "SELECT est_qty FROM $table_name WHERE mix_design = '".$b2."' ";
		$est_result = mySQL_query($est_query);
		$est_num = mysql_num_rows($est_result);
		$b7 = mysql_result($est_result, 0, "est_qty");
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$production_query = "SELECT production_no, quantity FROM $table_name WHERE mix_design_name = '".$b2."' AND (action = 'skip_count') AND action_date >= '".$start."' AND action_date <= '".$end."' ";
		$production_result = mySQL_query($production_query);
		$production_num = mysql_num_rows($production_result);
		$production_line = '';
		$k=0;
		while ($k<$production_num) {
		$production_no = mysql_result($production_result, $k, "production_no");
		$skip_count = mysql_result($production_result, $k, "quantity");
		
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_count_query = "SELECT quantity FROM $table_name WHERE production_no = '".$production_no."' AND action = 'wet_count'  AND action_date BETWEEN '".$start."' AND '".$end."' ";
		$wet_count_result = mySQL_query($wet_count_query);
		$wet_count_num = mysql_num_rows($wet_count_result);
		$wet_count = mysql_result($wet_count_result, 0, "quantity");
		
		
		
		$production_line = $production_line."<tr><td>".$production_no."</td><td>".$skip_count."</td><td>".$wet_count."</td></tr>";
		$k++;
		}
		
		$productionTT = "<table width=200px;><tr><td width=100px;>Production no</td><td width=50px;>Skips</td><td  width=50px;>Produced</td></tr>".$production_line."</table>"
		
		
		?>
		<tr >
		  <td align="left"><a href="" onMouseover="ddrivetip('<?php echo $productionTT ?>', 210)"; onMouseout="hideddrivetip()"><?php echo $b2 ?></a></td>
		  <td align="left" ><?php echo $b2 ?></td>
		  <td align="right"><?php echo number_format($b4, 1, '.', ','); $b4_tot = $b4_tot + $b4;  ?></td>
		  <td align="right"><?php echo number_format($b5, 0, '.', ','); $b5_tot = $b5_tot + $b5; ?></td>
		  <td align="right"><?php echo number_format($b6, 0, '.', ',') ?></td>
		  <td align="right"><?php echo number_format($b7, 0, '.', ',') ?></td>
	    </tr>
	<?php
		$i++; 
	}
	?>
	<tfoot>	
        <tr >
		  <td align="right">Totals:</td>
		  <td align="left" >&nbsp;</td>
		  <td align="right"><?php echo number_format($b4_tot, 1, '.', ',') ?></td>
		  <td align="right"><?php echo number_format($b5_tot, 0, '.', ',') ?></td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
	    </tr> 
    </tfoot>      
</table>
<br>
	
Click <a href="day_production_tiles_list.php?sub_cat=Tiles&date=">here</a> for a day specified list.	
</div>    
</div>
</body>
<?php } else {  ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "production/production_main.php?";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>