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

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
</head>
<?php
if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");
	
$design_no = $_GET['design_no'];	

$table_name = $_SESSION['db_prefix']."_mix_design";
$mix_query = "SELECT mix_design, est_qty, packaging_design FROM $table_name WHERE design_no = '".$design_no."' ";
$mix_result = $con->query($mix_query);
$row = mysqli_fetch_assoc($mix_result);
$mix_design = $row['mix_design'];
$est_qty = $row['est_qty'];
$packaging_design = $row['packaging_design'];


$table_name = $_SESSION['db_prefix']."_mix_design_lines";
$mix_line_query = "SELECT store_item_id, quantity FROM $table_name WHERE design_no = '".$design_no."' ";
$mix_line_result = $con->query($mix_line_query);
$mix_line_num = mysqli_num_rows($mix_line_result);


//$table_name = $_SESSION['db_prefix']."_packaging_design";
//$packaging_query = "SELECT packaging_design FROM $table_name WHERE packaging_design = '".$packaging_design."' ";
//$packaging_result = $con->query($packaging_query);
//$row = mysqli_fetch_assoc($packaging_result);
//$packaging_name = $row['packaging_design'];

?>
<body>

<div class="main_frame">
<table width="630" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="52" colspan="4" align="left" valign="top"><div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Production packing design<br /><?php echo $mix_design ?></label></td>
            </tr>
        </table>
      </div>
       

<div class="page_middle_frame">
  <table id="table_details_display">
    <tr>
      <td width="316">Ingredient</td>
      <td width="76">Quantity</td>
      <td width="46">Unit</td>
      <td width="96">Unit cost</td>
      <td width="112">Batch cost</td>
    </tr>
    <?php
$total=0;
while($row = $mix_line_result->fetch_assoc()) {
		$store_item_id = $row["store_item_id"];
		$quantity = $row["quantity"];	
			
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name, unit, price FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
		$name_result = $con->query($name_query);
		$row = mysqli_fetch_assoc($name_result);
		$item_name = $row["item_name"];
		$unit = $row["unit"];
		$price = $row["price"];
		
		$line_total = $quantity * $price;
		$total = $total + $line_total;
		?>
    <tr>
      <td><?php echo $item_name ?></td>
      <td><?php echo $quantity ?></td>
      <td><?php echo $unit ?></td>
      <td align="right"><?php echo number_format($price, 2, '.', ',') ?></td>
      <td align="right"><?php echo number_format($line_total, 2, '.', ',') ?></td>
    </tr>
    <?php
}
?>
    <tr>
      <td colspan="4" align="right">Total  design cost:&nbsp;&nbsp;</td>
      <td align="right"><?php echo number_format($total, 2, '.', ',') ?></td>
    </tr>
  </table>
  <br />
  
  <br />
  Estimated number of packed products to be made with this production packing design: &nbsp;&nbsp;<?php echo $est_qty ?><br /><br />

Estimated single packed product cost:&nbsp;&nbsp;<?php if($est_qty!=0) { $single_cost=$total/$est_qty; echo number_format($single_cost, 2, '.', ','); }?><br /><br />
<br />
<br />
<br />

</div>
    </td>
    </tr>
    </table>
</div>

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

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