<!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 = mySQL_query($mix_query);
$mix_num = mysql_num_rows($mix_result);
$mix_design = mysql_result($mix_result, 0, "mix_design");
$est_qty = mysql_result($mix_result, 0, "est_qty");
$packaging_design = mysql_result($mix_result, 0, "packaging_design");


$table_name = $_SESSION['db_prefix']."_mix_design_lines";
$mix_line_query = "SELECT store_item_id, quantity FROM $table_name WHERE mix_design = '".$mix_design."' ";
$mix_line_result = mySQL_query($mix_line_query);
$mix_line_num = mysql_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 = mySQL_query($packaging_query);
$packaging_name = mysql_result($packaging_result, 0, "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">Mix design <?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">Mix cost</td>
    </tr>
    <?php
$total=0;
$i=0;
while ($i<$mix_line_num) {
		$store_item_id = mysql_result($mix_line_result, $i, "store_item_id");
		$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 = mySQL_query($name_query);
		$item_name = mysql_result($name_result, 0, "item_name");
		$unit = mysql_result($name_result, 0, "unit");
		$price = mysql_result($name_result, 0, "price");
		$quantity = mysql_result($mix_line_result, $i, "quantity");
		$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
  $i++;
}
?>
    <tr>
      <td colspan="4" align="right">Total mix design cost:&nbsp;&nbsp;</td>
      <td align="right"><?php echo number_format($total, 2, '.', ',') ?></td>
    </tr>
  </table>
  <br />
  
  <br />
  Estimated number of products to be made with this mix design: &nbsp;&nbsp;<?php echo $est_qty ?><br /><br />

Estimated single product cost:&nbsp;&nbsp;<?php if($est_qty!=0) { $single_cost=$total/$est_qty; echo number_format($single_cost, 4, '.', ','); }?><br /><br />
Selected packaging design: <?php echo $packaging_name ?>
  <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>
