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

if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");

$table_name = $_SESSION['db_prefix']."_packaging_design";
$packaging_query = "SELECT design_no, packaging_design, est_qty FROM $table_name ";
$packaging_result = mySQL_query($packaging_query);
$packaging_num = mysql_num_rows($packaging_result);


?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 
<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": "450px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"iDataSort": 4},
								{"bSortable": true},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bVisible": false}
								
								 ]
				} );
			} );
		</script>

</head>

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

<body>

<div class="main_frame"  >
  <div class="page_head_frame" >
          <table width="590" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="385"><label class="label_page_head">Packaging designs</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
       </div></td>
             
        <div class="page_middle_frame" style="height:500px;">
          <table width="668" id="scroll_table" class="data_display"   >
            <thead>
            <tr>
              <th align="center">Packaging design</th>
              <th align="center">Estimated<br />
                no of products</th>
              <th align="center">Design cost</th>
              <th align="center">Estimated                single<br />
product cost</th>
              <th align="center">&nbsp;</th>
            </tr>
          </thead>
            <?php

$i=0;
while ($i<$packaging_num) {
	$a0 =  mysql_result($packaging_result, $i, "design_no");
	$a1 = mysql_result($packaging_result, $i, "packaging_design");
	$est_qty = mysql_result($packaging_result, $i, "est_qty");
	
	$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
	$line_query = "SELECT store_item_id, quantity FROM $table_name WHERE design_no = '".$a0."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	$tip_line = '';
	$design_cost = ''; 
	$k=0;
	while ($k<$line_num) {
	  $store_item_id = mysql_result($line_result, $k, "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($line_result, $k, "quantity");
	  $cost = $quantity * $price;
	  $design_cost = $design_cost + $cost;
	  
	  $tip_line = $tip_line.'<tr><td>'.$item_name.'</td><td>'.$quantity.' '.$unit.'</td></tr>';
	$k++;
	}
	
	$tip_head = '<table><tr><td width=300px;>item</td><td width=100px;>quantity</td></tr>';
	$tip_foot = '</table><br>Click for details.';
	$packaging_tool_tip = $tip_head.$tip_line.$tip_foot;
    ?> 
           <tr>
              <td width="129" align="left" valign="top"><a href="packaging_design_display.php?design_no=<?php echo $a0 ?>" onmouseover="ddrivetip('<?php echo $packaging_tool_tip ?>', 300)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="110" align="left" valign="top"><?php echo number_format($est_qty, 0, '.', ',') ?><br /></td>
              <td width="94" align="right" valign="top"><?php echo number_format($design_cost, 2, '.', ',') ?></td>
              <td width="116" align="right" valign="top"><?php if ($est_qty!=0) { $single_cost=$design_cost/$est_qty; echo number_format($single_cost, 2, '.', ','); }?></td>
              <td width="185" align="left" valign="top"><?php echo $a1 ?></td>
            </tr>
            <?php
  $i++;
}
?>
          </table>
          
        </div>
  
</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");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>