<!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) {
	
$product = $_GET['product'];	

include ("../navigation/production_sidebar.php");
include('../include/period_select_date.php');	

$table_name = $_SESSION['db_prefix']."_mix_design";
$mixQuery = "SELECT  mix_design FROM $table_name WHERE product_type = 'Accessories' ORDER BY mix_design ASC";
$mixResult = execsql($mixQuery);
$mixNum = mysql_num_rows($mixResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $mixNum) {
		$arrId4[$w] = mysql_result($mixResult, $w, 'mix_design');
		$arrName4[$w] = mysql_result($mixResult, $w, 'mix_design');
		$w++;
	}
 
$table_name = $_SESSION['db_prefix']."_production_plan";
if ($product=='All') {	 	
$display_query = "SELECT production_no, production_date, mix_design_name FROM $table_name WHERE production_date >= '".$start."' AND production_date <= '".$end."' AND depalleted = 'yes'  AND sub_category = 'Accessories'" ;
}
else {
$display_query = "SELECT production_no, production_date, mix_design_name  FROM $table_name WHERE mix_design_name = '".$product."' AND production_date >= '".$start."' AND production_date <= '".$end."' AND depalleted = 'yes'  AND sub_category = 'Accessories'" ;
}
$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" />

</head>


<body>

<div class="main_frame">
<div class="page_head_frame">
  <label class="label_page_head">Breakage accessories</label></div>
   
<br />
<br /><br />
<br />
<?php
$page='breakage_acc_list.php';
$reference_name='product';
$reference=$product;
$reference_name_2='';
$reference_2='';
include('../include/period_select_block.php');
?>


    
<br />
<div class="page_middle_frame">
<div>
<form action="breakage_acc_list.php" method="get" name="form_2">
<div style="float:left;">
Select single product:

<select name="product_select" autofocus class="selectbox300" id="product_select" onchange="window.location.href= this.form.product_select.options[this.form.product_select.selectedIndex].value">
  <option value="<?php echo $product ?>" selected="selected" ><?php echo $product ?></option>
  <option value="breakage_acc_list.php?product=All&date=1&date1=<?php echo $start ?>&date2=<?php echo $end ?>">All</option>
  <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
 ?>			
  <option value="breakage_acc_list.php?product=<?php echo $arrId4[$j] ?>&date=1&date1=<?php echo $start ?>&date2=<?php echo $end ?>"><?php echo $arrName4[$j] ?></option>	
 <?php }
     ?>
</select>
</div>
</form>

<div style="float:left;">
<br>
<img src="../images/info_blue.png" width="16" height="16">
<label class="label_info">List only shows production cycles which are completely depalleted.</label>          
</div>

</div>
<!--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": [[ 1, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"iDataSort": 2},
								{"bVisible": false},
                              	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
                         	 ]
				} );
			} );
		</script>    	
<table width="601" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="88" align="left">Production no</th>
		  <th width="49" align="left">Date</th>
		  <th width="27" align="left">&nbsp;</th>
		  <th width="139" align="left">Tile type</th>
		  <th width="67" align="left">Produced</th>
		  <th width="76" align="left">Depalleted</th>
		  <th width="76" align="left">Breakage</th>
		  <th width="43" align="left">%</th>
	    </tr>
	</thead>
	<tbody>
  <?php
    $b4_tot = 0;
	$b5_tot = 0;
	$b6_tot = 0;
	$b7_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");
		 
		 
		$b4=0;
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_count_query = "SELECT quantity FROM $table_name WHERE production_no = '".$b0."' AND  action = 'wet_count' ";
		$wet_count_result = mySQL_query($wet_count_query);
		$wet_count_num = mysql_num_rows($wet_count_result);
		$k=0;
		while ($k<$wet_count_num) {
		   $b4a = mysql_result($wet_count_result, $k, "quantity");
		   $b4 = $b4 +$b4a;
		   $k++;
		}
		
		$b5=0;
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dep_count_query = "SELECT quantity FROM $table_name WHERE production_no = '".$b0."' AND  action = 'dep_count' ";
		$dep_count_result = mySQL_query($dep_count_query);
		$dep_count_num = mysql_num_rows($dep_count_result);
		$k=0;
		while ($k<$dep_count_num) {
		   $b5a = mysql_result($dep_count_result, $k, "quantity");
		   $b5 = $b5 +$b5a;
		   $k++;
		}
				
		$b6 = $b4 - $b5;
		if ($b4>0) {
		$b7 = ($b6 / $b4) * 100;	
		}
		else {
		$b7 = 0;
		}
		
		$b4_tot = $b4_tot + $b4;
		$b5_tot = $b5_tot + $b5;
		
		$b6_tot = $b4_tot - $b5_tot;
		
		if ($b4_tot>0) {
		$b7_tot = ($b6_tot / $b4_tot) * 100;	
		}
		else {
		$b7_tot = 0;
		}

		?>
		<tr >
		  <td ><a href="production_plan_report.php?production_no=<?php echo $b0 ?>" onMouseover="ddrivetip('Click to view production report', 150)"; onMouseout="hideddrivetip()"><?php echo $b0 ?></a></td>
		  <td ><?php echo date("d-m-Y", strtotime($b1 ))?></td>
		  <td ><?php echo $b1 ?>&nbsp;</td>
		  <td align="left"><?php echo $b2 ?></td>
		  <td align="right"><?php echo $b4 ?></td>
		  <td align="right"><?php echo $b5 ?></td>
		  <td align="right"><?php echo $b6 ?></td>
		  <td align="right"><?php echo number_format($b7, 2, '.', ',') ?></td>
	    </tr>
   	<?php
		$i++; 
	}
	?>
    <tfoot>
		<tr >
		  <td >&nbsp;</td>
		  <td >&nbsp;</td>
		  <td >&nbsp;</td>
		  <td align="left">&nbsp;</td>
		  <td align="right"><?php echo $b4_tot ?></td>
		  <td align="right"><?php echo $b5_tot ?></td>
		  <td align="right"><?php echo $b6_tot ?></td>
		  <td align="right" bgcolor="#CCCCCC"><?php echo number_format($b7_tot, 2, '.', ',') ?></td>
	    </tr>
	  </tfoot> 
</tbody>   
</table>
		
</div>	
</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'); ?>