<!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" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "Sales-main";
include ("../navigation/access.php");

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

//$cutting_supply_id = $_GET['cutting_supply_id'];
$job_no = $_GET['job_no'];
$quote='no';

$table_name = $_SESSION['db_prefix']."_captured_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_no = '".$job_no."' ";
$job_result = mySQL_query($job_query);
$cust_id = mysql_result($job_result, 0, "cust_id");	

$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}

$table_name6 = $_SESSION['db_prefix']."_production_bill";
$production_id_query = "SELECT production_bill_id, prod_date FROM $table_name6 WHERE job_no = '".$job_no."' ";
$production_id_result = mySQL_query($production_id_query);
$production_id_num = mysql_num_rows($production_id_result);


$table_name = $_SESSION['db_prefix']."_captured_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_no = '".$job_no."' ";
$job_result = mySQL_query($job_query);
$job_no = mysql_result($job_result, 0, "job_no");
$cust_id = mysql_result($job_result, 0, "cust_id");

$table_name2 = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
$customer_result = mySQL_query($customer_query);
$a1 = mysql_result($customer_result, 0, "account_type");
if ($a1=="corporate") { 
$a0 = mysql_result($customer_result, 0, "comp_name"); 
} 
else {
$a0 = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 }

?>
</head>

<script type="text/javascript" src="../jscript/tablesort.js"></script>

<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php include ('../include/tooltip.php'); ?>

<div class="main_frame" style="height:auto; min-height:550px;">
  <table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="62" valign="top" ><div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="472"><label class="label_page_head">Truss production</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2">&nbsp;&nbsp;&nbsp;<?php echo $name; ?></label></td>
            <td width="208"><label style="font-size:24px; color:#FB6808;"><?php echo "J".$job_no ?></label></td>
            </tr>
        </table>
      </div>
        <br />

<br /></td> <!--center of tableMain-->
</tr>
<tr>
<td height="93"> <!--center of tableMain-->
  <div class="page_middle_frame">
    <?php 
		include ('../include/customer_block.php');
		echo '<br>';
		include ('../include/job_block.php')
		?>
  </div>
  <?php 
$k=0;
while ($k<$production_id_num) {
	$production_bill_id = mysql_result($production_id_result, $k, "production_bill_id");
	$prod_date = mysql_result($production_id_result, $k, "prod_date");
	?>
  <div class="page_middle_frame">
    <label class="label_std" style="font-size:14px">
      Poduced on: <?php echo date("d-m-Y", strtotime($prod_date))?></label>
    <br />
    <table width="483"  id="table_details_display">
    <tr>
        <th align="center">Truss</th>
        <th align="center">Quantity</th>
        <th align="center">FT</th>
        <th align="center">Total FT</th>
      </tr>
      <?php
	$table_name = $_SESSION['db_prefix']."_production_bill_lines";
	$truss_query = "SELECT * FROM $table_name WHERE production_bill_id = '".$production_bill_id."' AND quantity <> 0 ORDER BY truss_type ASC";
	$truss_result = mySQL_query($truss_query);
	$truss_num = mysql_num_rows($truss_result);
    $i=0;
	$a4tot=0;
    while ($i<$truss_num) {
		$a1=  mysql_result($truss_result, $i, "truss_type");
		$a2=  mysql_result($truss_result, $i, "quantity");
		$a3=  mysql_result($truss_result, $i, "press_points");
		$a4=$a2*$a3;
		$a4tot= $a4tot+$a4;
		
		?>
      <tr>
    <td width="99" align="center"><?php echo $a1 ?></td>
    <td width="116" align="center"><?php echo $a2 ?></td>
    <td width="106" align="center"><?php echo $a3 ?></td>
    <td width="142" align="center"><?php echo $a4 ?></td>
      </tr>
  <?php
	$i++;
	}
	?>
    <tfoot>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td align="right">All total:</td>
        <td align="center"><?php echo $a4tot ?></td>
      </tr>
      </tfoot>
</table>
    
  </div>
  <?php

  $k++;
 } 
  ?>
  <br />
</td>
</tr>

</table>  <!--end of tableMain-->
  
</div>

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



</body>
<?php } else {
$_SESSION['denied_return'] = "sales/sales_main.php";	
include ("../navigation/sales_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
</html>