<!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");
?>

<!--jscript-->
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script language="JavaScript" src="../jscript/tablesort.js"  type="text/javascript"></script> 

</head>
<?php
if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");
	
$month = date("m");
if ( ($month==1) OR ($month==3) OR ($month==5) OR ($month==7) OR ($month==8) OR ($month==10) OR ($month==12) ) { $day = 31; }
if ( ($month==4) OR ($month==6) OR ($month==9) OR ($month==11) ) { $day = 30; }
if ($month==2)  { $day = 29; }

$year = date("Y");
$start = $year.'-'.$month.'-01';
$end = $year.'-'.$month.'-'.$day;	

	
$table_name = $_SESSION['db_prefix']."_production_plan WHERE (depalleted IS NULL OR depalleted = 'no') AND cancelled ='no' ";
$production_query = "SELECT * FROM $table_name ";
$production_result = mySQL_query($production_query);
$production_num = mysql_num_rows($production_result);
	
$table_name = $_SESSION['db_prefix']."_production_plan";
$tiles_query = "SELECT * FROM $table_name WHERE sub_category = 'Tiles'  AND ( production_date  >= '".$start."' AND  production_date  <= '".$end."') AND depalleted = 'yes' AND cancelled ='no'   GROUP BY mix_design_name";
$tiles_result = mySQL_query($tiles_query);
$tiles_num = mysql_num_rows($tiles_result);


$table_name = $_SESSION['db_prefix']."_production_plan";
$accessories_query = "SELECT * FROM $table_name WHERE sub_category = 'Accessories'  AND ( production_date  BETWEEN '".$start."' AND '".$end."') AND depalleted = 'yes' AND cancelled ='no'   GROUP BY mix_design_name";
$accessories_result = mySQL_query($accessories_query);
$accessories_num = mysql_num_rows($accessories_result);


?>
<body>

<div class="main_frame">
<div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Production this month</label></td>
            </tr>
        </table>
</div>
       
<div class="page_middle_frame">
<label class="label_std" style="font-size:16px">Ongoing production</label>
 <table width="692" id="table_list" class="sortable-onload-1r rowstyle-alt no-arrow "  >
    <thead>
      <tr>
        <th width="75" align="center"  class="sortable-numeric">Production no</th>
        <th width="75" align="center" class="sortable-date-dmy">Production  date</th>
        <th width="150" align="center" class="sortable-text">Product </th>
        <th width="76" align="center" class="sortable-text">Group</th>
        <th width="64" align="center" class="sortable-text">Batch code</th>
        <th width="68" align="center" >Est count</th>
        <th width="75" align="center" >Wet count</th>
        <th width="73" align="center" >Depalleted</th>
        </tr>
    </thead>
    <tbody>
      <?php
$i=0;

	while ($i < $production_num) {
		$b0 = mysql_result($production_result, $i, "production_no");
		$b1 = mysql_result($production_result, $i, "production_date");
		$b2 = mysql_result($production_result, $i, "mix_design_name"); 	
		
		$b3 = mysql_result($production_result, $i, "batch_code");
		$b4 = mysql_result($production_result, $i, "sub_category");
		
		$b9 = mysql_result($production_result, $i, "planned");
		$b10 = mysql_result($production_result, $i, "produced_wet");
		$b11 = mysql_result($production_result, $i, "depalleted");
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$estimated_query = "SELECT SUM(quantity) as estimated_quantity FROM $table_name WHERE production_no = '".$b0."' AND action = 'estimated' ";
		$estimated_result = mySQL_query($estimated_query);
		$estimated_num = mysql_num_rows($estimated_result);
		if ($estimated_num>0) {
		$b15 = mysql_result($estimated_result, 0, "estimated_quantity");
		}
		else {
			$b15=0;
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$wet_query = "SELECT SUM(quantity) as wet_quantity FROM $table_name WHERE production_no = '".$b0."' AND action = 'wet_count' ";
		$wet_result = mySQL_query($wet_query);
		$wet_num = mysql_num_rows($wet_result);
		if ($wet_num>0) {
		$b16 = mysql_result($wet_result, 0, "wet_quantity");
		}
		else {
			$b16=0;
		}
		
		$table_name = $_SESSION['db_prefix']."_production_plan_lines";
		$dry_query = "SELECT SUM(quantity) as dry_count FROM $table_name WHERE production_no = '".$b0."' AND action = 'dep_count' ";
		$dry_result = mySQL_query($dry_query);
		$dry_num = mysql_num_rows($dry_result);
		if ($dry_num>0) {
		$b17 = mysql_result($dry_result, 0, "dry_count");
		}
		else {
			$b17=0;
		}
		
		
		$b19 = '';
		$b20 = '';
				
		//$jobTT ="<table id=table_tool_tip width=300 ><tr><td  width=100>Job no:</td><td width=175>".$b0."</td></tr><tr><td valign=top>Project no /place:</td><td>".$b9."&nbsp;".$b10."</td></tr><tr><td>Project description:</td><td>".$b11."</td></tr><tr><td>Designer:</td><td>".$b12."</td></tr><tr><td>Job value:</td><td>P ".number_format($b13, 2, '.', ',')."</td></tr><tr><td>Delivery date:</td><td>".$b2a."</td></tr></table><br><b>Click for details</b>";
		$jobTT ='';

		//$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
		$customerTT='';
?>
      <tr class="alt">
        <td align="left" style="padding-left:0px;"><a href="production_plan.php?production_no=<?php echo $b0?>" onmouseover="ddrivetip('Click to see complete day production plan.', 200)"; onmouseout="hideddrivetip()" target="_parent"><?php echo $b0?></a></td>
        <td><?php  echo date("d-m-Y", strtotime($b1))?></td>
        <td><?php  echo $b2?></td>
        <td><?php  echo $b4?></td>
        <td><?php  echo $b3?></td>
        <td align="right"><?php if ($b9=='yes') {?>
          <a href="production_plan.php?production_no=<?php echo $b0?>" onMouseover="ddrivetip('Click to view the production plan', 110)"; onMouseout="hideddrivetip()"><?php echo number_format($b15, 0, '.', ',');} ?></a>
        </td>
        <td align="right">
		<?php if ($b10=='yes') {?>
          <a href="production_plan.php?production_no=<?php echo $b0?>" onMouseover="ddrivetip('Wet count done.<br>Click to view the production plan.', 160)"; onMouseout="hideddrivetip()"><?php echo number_format($b16, 0, '.', ',');  ?>&nbsp;&nbsp;<img src="../images/checkmark-black.fw.png" width="8" height="8" /></a>
          <?php }?>
         <?php if ($b10=='no') {?>
          <a href="wet_count.php?production_no=<?php echo $b0?>" onMouseover="ddrivetip('Click to count wet production', 150)"; onMouseout="hideddrivetip()"><?php echo number_format($b16, 0, '.', ',');  ?>&nbsp;&nbsp;<img src="../images/plus.fw.png" width="8" height="8" /></a>
          <?php }?>
          <?php if ($b10=='') {?>
          <a href="wet_count.php?production_no=<?php echo $b0?>" onMouseover="ddrivetip('Click to count wet production', 150)"; onMouseout="hideddrivetip()"><?php echo number_format($b16, 0, '.', ',');  ?>&nbsp;&nbsp;<img src="../images/plus.fw.png" width="8" height="8" /></a>
          <?php }?>
          </td>
        <td align="right">
		<?php if ($b11=='no') {?>
          <a href="depallet_count.php?production_no=<?php echo $b0?>" onmouseover="ddrivetip('Click to count depalleted', 150)"; onmouseout="hideddrivetip()"><?php echo number_format($b17, 0, '.', ',');  ?>&nbsp;&nbsp;<img src="../images/plus.fw.png" width="8" height="8" /></a>
          <?php }?>
          <?php if ($b11=='') {?>
          <a href="depallet_count.php?production_no=<?php echo $b0?>" onmouseover="ddrivetip('Click to count depalleted', 150)"; onmouseout="hideddrivetip()"><?php echo number_format($b17, 0, '.', ',');  ?>&nbsp;&nbsp;<img src="../images/plus.fw.png" width="8" height="8" /></a>
          <?php }?>
		</td>
        </tr>
      <?php
    $i++;
		
	}?>
    </tbody>
  </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},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
<a href="day_production_tiles_list.php?date=&sub_cat=Tiles" onMouseover="ddrivetip('Click for specified day production list.', 180)"; onMouseout="hideddrivetip()"><label class="label_std" style="font-size:16px">Tiles</label></a>
  <table width="692" id="scroll_table" class="data_display" >
    <thead>
    <tr>
      <th width="126" align="center">Product</th>
      <th width="58" align="center">Planned<br />
        skips</th>
      <th width="65" align="center">Planned<br />
products</th>
      <th width="67" align="center">Skip<br />
        produced</th>
      <th width="76" align="center">Estimated<br />
        products</th>
      <th width="76" align="center">Produced<br />
wet products</th>
      <th width="52" align="center">+/-</th>
      <th width="76" align="center">Depalleted</th>
      <th width="56" align="center">+/-</th>
      </tr>
    </thead>
    <?php
$total=0;
$i=0;
$all_skip_produced_tot=0;
$all_wet_produced_tot=0;
$all_depalleted_tot = 0;
while ($i<$tiles_num) {
		$mix_design_name = mysql_result($tiles_result, $i, "mix_design_name");
			
		$skip_quantity_tot=0;
		$skip_produced_tot=0;
		
		$planned_quantity_tot=0;
		$wet_produced_tot=0;
		$est_quantity_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."' AND ( production_date  BETWEEN '".$start."' AND '".$end."') AND depalleted = 'yes' ORDER BY production_no";
		$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";
		$planned_query = "SELECT SUM(quantity) AS summed_estimated FROM $table_name WHERE production_no = '".$production_no."' AND action = 'estimated' GROUP BY action ";
		$planned_result = mySQL_query($planned_query);
		$planned_num = mysql_num_rows($planned_result);
		if ($planned_num!=0) {
		  $planned_quantity = mysql_result($planned_result, 0, "summed_estimated");
		}
		else {
			$planned_quantity = 0;
		}
		$planned_quantity_tot = $planned_quantity_tot + $planned_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']."_mix_design";
		$estimated_query = "SELECT est_qty FROM $table_name WHERE mix_design = '".$mix_design_name."' ";
		$estimated_result = mySQL_query($estimated_query);
		$estimated_num = mysql_num_rows($estimated_result);
		$est_quantity = mysql_result($estimated_result, 0, "est_qty");
		$est_quantity_tot =  $skip_produced_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;
		
		
		$dif_produced_tot = $wet_produced_tot - $est_quantity_tot;
		
				
		$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;
		
		
		$dif_depalleted_tot = $depalleted_tot - $wet_produced_tot;
			
		
		$productionTT_body = $productionTT_body.'<tr><td>'.$production_no.'</td><td>'.date("d-m-Y", strtotime($production_date)).'</td><td>'.number_format($skip_produced, 1, '.', ',').'</td><td>'.number_format($wet_produced, 0, '.', ',').'</td></tr>';
		
		
		$n++;
		}
		$productionTT_header='<b>Production for '.$mix_design_name.'</b><br><table><tr><td width=100>Production no</td><td width=100>Production date</td><td width=40>Skips</td><td width=100>Produced</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 ?>', 350)"; 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($planned_quantity_tot, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($skip_produced_tot, 1, '.', ','); $all_skip_produced_tot = $all_skip_produced_tot + $skip_produced_tot; ?></td>
      <td align="right"><?php echo number_format($est_quantity_tot, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($wet_produced_tot, 0, '.', ','); $all_wet_produced_tot = $all_wet_produced_tot + $wet_produced_tot; ?></td>
      <td align="right"><?php if ( $dif_produced_tot<0) { echo '<font color=red>'.number_format($dif_produced_tot, 0, '.', ',').'</font>'; } else { echo number_format($dif_produced_tot, 0, '.', ','); } ?></td>
      <td align="right"><?php echo number_format($depalleted_tot, 0, '.', ','); $all_depalleted_tot = $all_depalleted_tot + $depalleted_tot; ?></td>
      <td align="right"><?php if ( $dif_depalleted_tot<0) { echo '<font color=red>'.number_format($dif_depalleted_tot, 0, '.', ',').'</font>'; } else {echo number_format($dif_depalleted_tot, 0, '.', ','); } ?></td>
      </tr>
    <?php
  $i++;
}
?>
<tfoot>
<tr>
      <td>&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($all_skip_produced_tot, 1, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($all_wet_produced_tot, 0, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($all_depalleted_tot, 0, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
    </tr>
</tfoot>
  </table>
<div align="left" >
<img src="../images/info_blue.png" width="16" height="16">
<label class="label_info" style="font-size:10px;">List includes completed production cycles only.</label>          
</div>
</div>

<div class="page_middle_frame">
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table_2').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},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
<br />
<a href="day_production_tiles_list.php?date=&amp;sub_cat=Accessories" onmouseover="ddrivetip('Click for specified day production list.', 180)"; onmouseout="hideddrivetip()">
<label class="label_std" style="font-size:16px">Accessories</label>
</a>
<table width="692" id="scroll_table_2" class="data_display" >
    <thead>
    <tr>
      <th width="124" align="center">Product</th>
      <th width="58" align="center">Planned<br />
        batch</th>
      <th width="67" align="center"><p>Planned<br />
        products
      </p></th>
      <th width="67" align="center">Batch<br />
        produced</th>
      <th width="76" align="center">Estimated<br />
        products</th>
      <th width="76" align="center">Produced<br />
wet products</th>
      <th width="56" align="center">+/-</th>
      <th width="76" align="center">Depalleted</th>
      <th width="52" align="center">+/-</th>
      </tr>
    </thead>
    <?php
$total=0;
$i=0;
$all_skip_produced_tot=0;
$all_wet_produced_tot=0;
$all_depalleted_tot = 0;
while ($i<$accessories_num) {
		$mix_design_name = mysql_result($accessories_result, $i, "mix_design_name");
		
		
		$skip_quantity_tot=0;
		$skip_produced_tot=0;
		$planned_quantity_tot=0;
		$wet_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."' AND ( production_date  BETWEEN '".$start."' AND '".$end."')  AND depalleted = 'yes' ORDER BY production_no";
		$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";
		$planned_query = "SELECT SUM(quantity) AS summed_estimated FROM $table_name WHERE production_no = '".$production_no."' AND action = 'estimated' GROUP BY action ";
		$planned_result = mySQL_query($planned_query);
		$planned_num = mysql_num_rows($planned_result);
		if ($planned_num!=0) {
		  $planned_quantity = mysql_result($planned_result, 0, "summed_estimated");
		}
		else {
			$planned_quantity = 0;
		}
		$planned_quantity_tot = $planned_quantity_tot + $planned_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;
		}
		$planned_quantity_tot = $planned_quantity_tot + $est_quantity;
		
		$table_name = $_SESSION['db_prefix']."_mix_design";
		$estimated_query = "SELECT est_qty FROM $table_name WHERE mix_design = '".$mix_design_name."' ";
		$estimated_result = mySQL_query($estimated_query);
		$estimated_num = mysql_num_rows($estimated_result);
		$est_quantity = mysql_result($estimated_result, 0, "est_qty");
		$est_quantity_tot =  $skip_produced_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;
		
		
		$dif_produced_tot = $wet_produced_tot - $est_quantity_tot;
		
				
		$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;
		
		
		$dif_depalleted_tot = $depalleted_tot - $wet_produced_tot;			
		
		$productionTT_body = $productionTT_body.'<tr><td>'.$production_no.'</td><td>'.date("d-m-Y", strtotime($production_date)).'</td><td>'.number_format($skip_produced, 1, '.', ',').'</td><td>'.number_format($wet_produced, 0, '.', ',').'</td></tr>';
		
		
		$n++;
		}
		$productionTT_header='<b>Production for '.$mix_design_name.'</b><br><table><tr><td width=100>Production no</td><td width=100>Production date</td><td width=40>Skips</td><td width=100>Produced</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 ?>&amp;date=" onmouseover="ddrivetip('<?php echo $productionTT ?>', 250)"; onmouseout="hideddrivetip()"><?php echo $mix_design_name ?></a><a href=" " onmouseover="ddrivetip('<?php echo $productionTT ?>', 250)"; onmouseout="hideddrivetip()"></a></td>
      <td align="right"><?php echo number_format($skip_quantity_tot, 1, '.', ',') ?></td>
      <td align="right"><?php echo number_format($planned_quantity_tot, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($skip_produced_tot, 1, '.', ','); $all_skip_produced_tot = $all_skip_produced_tot + $skip_produced_tot; ?></td>
      <td align="right"><?php echo number_format($est_quantity_tot, 0, '.', ',') ?></td>
      <td align="right"><?php echo number_format($wet_produced_tot, 0, '.', ','); $all_wet_produced_tot = $all_wet_produced_tot + $wet_produced_tot; ?></td>
      <td align="right"><?php if ( $dif_produced_tot<0) { echo '<font color=red>'.number_format($dif_produced_tot, 0, '.', ',').'</font>'; } else { echo number_format($dif_produced_tot, 0, '.', ','); } ?></td>
      <td align="right"><?php echo number_format($depalleted_tot, 0, '.', ','); $all_depalleted_tot = $all_depalleted_tot + $depalleted_tot; ?></td>
      <td align="right"><?php if ( $dif_depalleted_tot<0) { echo '<font color=red>'.number_format($dif_depalleted_tot, 0, '.', ',').'</font>'; } else {echo number_format($dif_depalleted_tot, 0, '.', ','); } ?></td>
      </tr>
    <?php
  $i++;
}
?>
<tfoot>
 <tr>
      <td>&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($all_skip_produced_tot, 1, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($all_wet_produced_tot, 0, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($all_depalleted_tot, 0, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
    </tr>
</tfoot>
  </table>
<div align="left" >
<img src="../images/info_blue.png" width="16" height="16">
<label class="label_info" style="font-size:10px;">List includes completed production cycles only.</label>          
</div>
</div>
    
</div>

<?php include ('../navigation/side_bar.php'); ?>

</body>

<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = $_SESSION['location'];
    include ("../navigation/production_sidebar.php");
    include ('../navigation/side_bar.php'); 
	?>
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>
</html>
