<!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 = "DF-Production-main";
include ("../navigation/access.php");

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

$table_name = $_SESSION['db_prefix']."_mix_design";
$mix_query = "SELECT design_no, mix_design, design_cost, est_qty FROM $table_name WHERE product_type = 'Dry feed product' ";
$mix_result = $con->query($mix_query);
$mix_num = mysqli_num_rows($mix_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><label class="label_page_head">Dry feed Production packing designs</label></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">Mix design</th>
              <th align="center">Estimated<br />
                no of products</th>
              <th align="center">Design cost per batch</th>
              <th align="center">Estimated single<br />
product cost</th>
              <th align="center">&nbsp;</th>
            </tr>
          </thead>
            <?php
$tip_line='';
while($row = $mix_result->fetch_assoc()) {
	$a0 = $row["design_no"];
	$a1 = $row["mix_design"];
	$est_qty = $row["est_qty"];
	
	$table_name = $_SESSION['db_prefix']."_mix_design_lines";
	$line_query = "SELECT store_item_id, quantity FROM $table_name WHERE mix_design = '".$a1."' ";
	$line_result = $con->query($line_query);;
	$line_num = mysqli_num_rows($line_result);
	$tip_line = '';
	$design_cost = ''; 
	while($row = $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'];
	  
	  $cost = $quantity * $price;
	  $design_cost = $design_cost + $cost;
	  
	  $tip_line = $tip_line.'<tr><td>'.$item_name.'</td><td>'.$quantity.' '.$unit.'</td></tr>';
	}


	
	$tip_head = '<table><tr><td width=300px;>item</td><td width=100px;>quantity</td></tr>';
	$tip_foot = '</table><br>Click for details.';
	$mix_tool_tip = $tip_head.$tip_line.$tip_foot;
    ?> 
           <tr>
              <td width="129" align="left" valign="top"><a href="dry_feed_mix_design_display.php?design_no=<?php echo $a0 ?>" onmouseover="ddrivetip('<?php echo $mix_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
}
?>
          </table>
          
        </div>
  
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "dry_feed/dry_feed_main_main.php";
include ("../navigation/production_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>