<!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']."_product_store_lines";	 	
$display_query = "SELECT production_no, packing_no, packing_date, product_item_id, quantity_in, batch_code FROM $table_name WHERE packing_date >= '".$start."' AND packing_date <= '".$end."' AND packing_no > 0 ORDER BY packing_no DESC ";
$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">Packing</label></div>
   
<br />
<br /><br />
<br />
<?php
$page='packing_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, "desc" ]],
					"aoColumns": [
								{"iDataSort": 9},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
                         	 ]
				} );
			} );
		</script>    	
<table width="572" id="scroll_table" class="data_display" >
	<thead>
		<tr>
		  <th align="center">Packing<br>
	      no</th>
		  <th align="center">Packing date</th>
		  <th align="center">Product</th>
		  <th align="center">Batch code</th>
		  <th align="center">Packed</th>
		  <th align="center">To recycle</th>
		  <th align="center">Total<br>packing cost</th>
		  <th align="center">Packing cost<br>per unit</th>
		  <th align="center"> Prod<br>
	      no</th>
		  <th align="center">&nbsp;</th>
	    </tr>
	</thead>
	<tbody>
  <?php
  $b3_tot=0;
  	while($row = $display_result->fetch_assoc()) {
		 $b0 = $row["packing_no"];
		 $b1 = $row["packing_date"];
		 $b2 = $row["product_item_id"];
		 $b3 = $row["quantity_in"];
		 $b4 = $row["batch_code"];
		 $b5 = $row["production_no"];
		 
		 $b3_tot = $b3_tot + $b3;

		 
		 $table_name = $_SESSION['db_prefix']."_product_store";
		 $item_name_query = "SELECT item_name FROM $table_name WHERE product_item_id = '".$b2."' ";
		 $item_name_result = $con->query($item_name_query);
		 $row = mysqli_fetch_assoc($item_name_result);
		 $b2a = $row['item_name'];
		 
		 $table_name = $_SESSION['db_prefix']."_production";
		 $cost_query = "SELECT packing_cost, damaged_no FROM $table_name WHERE packing_no = '".$b0."' ";
		 $cost_result = $con->query($cost_query);
		 $row = mysqli_fetch_assoc($cost_result);
		 $b6 = $row['packing_cost'];
		 $b7 = $row['damaged_no'];
		 
		 if ($b3>0) {
		 $b8 = $b6 / $b3;
		 } else {
		 $b8 = 0;
		 }
						
		?>
		<tr >
		  <td align="left"><a href="packing_slip.php?packing_no=<?php echo $b0 ?>"><?php echo $b0 ?></a></td>
		  <td align="left" ><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
		  <td align="left"><?php echo $b2a ?></td>
		  <td align="left"><?php echo $b4 ?></td>
		  <td align="right"><?php echo $b3 ?></td>
		  <td align="center"><?php if ($b7>0) {echo $b7; } ?></td>
		  <td align="right"><?php echo number_format($b6, 2, '.', ',') ?></td>
		  <td align="right"><?php echo number_format($b8, 4, '.', ',') ?></td>
		  <td align="left"><a href="production_slip.php?production_no=<?php echo $b5 ?>"><?php echo $b5 ?></a></td>
		  <td align="left"><?php echo $b0 ?></td>
	    </tr>
	<?php
	}
	?>
	<tfoot>	
        <tr >
		  <td align="right">Totals:</td>
		  <td align="left" >&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right"><?php echo $b3_tot ?></td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
		  <td align="right">&nbsp;</td>
	    </tr> 
    </tfoot>      
</table>
<br>
</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'); ?>