<!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 FROM $table_name WHERE production_date BETWEEN '".$start."' AND '".$end."' GROUP BY production_date ";
$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">Production plan</label></div>
   
<br />
<br /><br />
<br />
<?php
$page='production_plan_list.php';
$reference_name='';
$reference='';
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": [[ 1, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                              	{"bSortable": true},
                         	 ]
				} );
			} );
		</script>    	
<table width="662" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="148">Date</th>
		  <th width="36">&nbsp;</th>
		  <th width="462">&nbsp;</th>
       </tr>
	</thead>
	<tbody>
  <?php
  
    $i=0;
    while($i < $display_num){
		 $b1 = mysql_result($display_result, $i, "production_date");
		 
		 	$table_name = $_SESSION['db_prefix']."_production_plan";
			$name_query = "SELECT production_no, mix_design_name FROM $table_name WHERE production_date = '".$b1."' ";
			$name_result = mySQL_query($name_query);
			$name_num = mysql_num_rows($name_result);
			
						
			$line_text='';
  			$summary_line='';
			$n=0;
			while ($n<$name_num) {
			   $mix_design_name = mysql_result($name_result, $n, "mix_design_name");
			   $production_no = mysql_result($name_result, $n, "production_no");
			   
			  	$table_name = $_SESSION['db_prefix']."_production_plan_lines";
				$quantity_query = "SELECT quantity FROM $table_name WHERE production_no = '".$production_no."' ";
				$quantity_result = mySQL_query($quantity_query);
				$quantity_num = mysql_num_rows($quantity_result);
				if ($quantity_num!=0) {
				$quantity = mysql_result($quantity_result, 0, "quantity"); }
				else {
					$quantity=0;
				}
			    							 
		 	   $line_text = $line_text.'<tr><td>'.$mix_design_name.'</td><td>'.$quantity.'</td></tr>';
		 	   $summary_line = $summary_line.' | '.$mix_design_name; 
			   $n++;
			}
						
		 $productionTT =
		   "<b>Production on this day</b><br><table id=table_tool_tip width=250 border=1 ><tr><td width=175>Production item</td><td>Skip/batch<br>quantity</td></tr>".$line_text."</table><br><b>Click for details</b>";
		   
		if (strlen($summary_line) > 150) {
               $summary_line = substr($summary_line, 0, 150) . '...'; }

   
		   

		?>
		<tr >
		  <td ><a href="production_plan_summary.php?production_date=<?php echo $b1 ?>" onMouseover="ddrivetip('<?php echo $productionTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo date("l, d-m-Y", strtotime($b1 ))?></a></td>
		  <td ><?php echo $b1 ?>&nbsp;</td>
		  <td align="left"><?php echo $summary_line ?></td>
	   </tr>
		     
		<?php
		$i++; 
	}
	?>
   
</table>
		
	
</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'); ?>