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

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

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

if ($permission_num==1) {

include ("../navigation/dry_feed_production_sidebar.php");

if (isset($_GET['m'])) {
		$m = $_GET['m'];
}
else {
	$m = date("m");
}

if (isset($_GET['Y'])) {
		$Y = $_GET['Y'];
}
else {
	$Y = date("Y");
}

	$start = $Y."-".$m."-01";
	$end = $Y."-".$m."-31";
	if ($m=='02') {
		  $end = $Y."-".$m."-28";
		  
	}
	if ( ($m=='04') OR ($m=='06')  OR ($m=='09')  OR ($m=='11') ) {
		  $end = $Y."-".$m."-30";
		  
	}
	
switch ($m) {
    case 1: $month_name = 'January'; break;
	case 2: $month_name = 'February'; break;
	case 3: $month_name = 'March'; break;
	case 4: $month_name = 'April'; break;
	case 5: $month_name = 'May'; break;
	case 6: $month_name = 'June'; break;
	case 7: $month_name = 'July'; break;
	case 8: $month_name = 'August'; break;
	case 9: $month_name = 'September'; break;
	case 10: $month_name = 'October'; break;
	case 11: $month_name = 'November'; break;
	case 12: $month_name = 'December'; break;
}

$table_name = $_SESSION['db_prefix']."_production";	 	
$display_query = "SELECT production_no, production_date, product_item_id, batch_code, produced_no, SUM(packed_no) AS packed_no, packing_date  FROM $table_name WHERE production_type = 'dry-feed' AND production_date >= '".$start."' AND production_date <= '".$end."' GROUP BY production_no";
$display_result = $con->query($display_query);
$display_num = mysqli_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 <?php echo $month_name.' '.$Y ?></label></div>
   
<br />
<div class="page_middle_frame">

<div  style=" float:right;">
<?php 
if ($m!=12) {$m_next=$m+1; $y_next=$Y;} else { $m_next=1; $y_next=$Y+1;}
if ($m!=1)  {$m_prev=$m-1; $y_prev=$Y;} else { $m_prev=12; $y_prev=$Y-1;}
?>
<a href="dry_feed_main.php?m=<?php echo $m_prev ?>&Y=<?php echo $y_prev ?> "><input name="prev_button" type="button" value="< previous month" class="imagebutton" style="width:120px;"></a>
<a href="dry_feed_main.php?m=<?php echo $m_next ?>&Y=<?php echo $y_next ?> "><input name="next_button" type="button" value="next month >" class="imagebutton" style="width:120px;"></a>
</div>
<div  style=" float:left;">   
<label style="font-size:24px; font-weight:bold">Eco Feed Products</label>
</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": "250px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ], [ 1, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"iDataSort": 7},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
                         	 ]
				} );
			} );
		</script>    	
<table width="615" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th width="69" align="center">Prod<br>date</th>
		  <th width="48" align="center">Prod<br>no</th>
		  <th width="110" align="center">Product </th>
		  <th width="119" align="center">Batch code</th>
		  <th width="76" align="center">Produced</th>
		  <th width="68" align="center">&nbsp;</th>
		  <th width="86" align="center">Packing date</th>
		  <th width="10" align="center">&nbsp;</th>
	    </tr>
	</thead>
	<tbody>
  <?php
  	$b3_total = 0;
	$b4_total = 0;
	while($row = $display_result->fetch_assoc()) {
			$b0 = $row["production_date"];
			$b1 = $row["product_item_id"];
			$b2 = $row["batch_code"];
			$b3 = $row["produced_no"];
			$b4 = $row["packed_no"];
			$b5 = $row["production_date"];
			$b6 = $row["production_no"];

		 	$table_name = $_SESSION['db_prefix']."_product_store";
			$product_name_query = "SELECT item_name FROM $table_name WHERE product_item_id = '".$b1."' ";
			$product_name_result = $con->query($product_name_query);
			$row = mysqli_fetch_assoc($product_name_result);
			$b1a = $row['item_name'];

			
		?>
		<tr >
		  <td align="left"><?php echo date("d-m-Y", strtotime($b0)) ?></td>
		  <td align="left" ><a href="dry_feed_production_slip.php?production_no=<?php echo $b6 ?>" onMouseover="ddrivetip('Click for production details', 130)"; onMouseout="hideddrivetip()"><?php echo $b6 ?></a></td>
		  <td align="left" ><?php echo $b1a ?></td>
		  <td align="left"><?php echo $b2 ?> </td>
		  <td align="right"><?php echo $b3; $b3_total = $b3_total + $b3; ?></td>
		  <td align="right">&nbsp;</td>
		  <td align="left"><?php if ($b5!='') {echo date("d-m-Y", strtotime($b5));} ?></td>
		  <td align="left"><?php echo $b6 ?></td>
	    </tr>
	<?php
	}
	?>
	<tfoot>	
        <tr >
		  <td colspan="4" align="right">Totals:</td>
		  <td align="right"><?php echo number_format($b3_total, 0, '.', ',') ?></td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
	    </tr> 
    </tfoot>      
</table>
<br>
</div>    
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else {  
$_SESSION['denied_return'] = $_SESSION['location'];	
include ("../navigation/store_sidebar.php");
include ('../navigation/side_bar.php');
?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>


</html>