<head>

<!--reference to main.css removed-->
<?php
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");

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

$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);
$job_no = mysql_result($job_result, 0, "job_no");
$cust_id = mysql_result($job_result, 0, "cust_id");
$designer = mysql_result($job_result, 0, "designer");
$roof_cover = mysql_result($job_result, 0, "roof_cover");
$roof_pitch = mysql_result($job_result, 0, "roof_pitch");
$max_overhang = mysql_result($job_result, 0, "max_overhang");
$roof_area = mysql_result($job_result, 0, "roof_area");
$floor_area = mysql_result($job_result, 0, "floor_area");
$quote_note = mysql_result($job_result, 0, "quote_note");
$value = mysql_result($job_result, 0, "value");

	
$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") { 
$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");
 }
$a5 = mysql_result($customer_result, 0, "contact_1");
$a6 = mysql_result($customer_result, 0, "status");
$a7 = mysql_result($customer_result, 0, "bag_box");
$a8 = mysql_result($customer_result, 0, "box_no");
$a9 = mysql_result($customer_result, 0, "postal_place");
$a10 = mysql_result($customer_result, 0, "phys_address");
$a11 = mysql_result($customer_result, 0, "phys_place");
$a12 = mysql_result($customer_result, 0, "web_site");
$a13 = mysql_result($customer_result, 0, "vat_no");
$a15 = mysql_result($customer_result, 0, "email_2");
$a23 = mysql_result($customer_result, 0, "fax");
$a24 = mysql_result($customer_result, 0, "phone");
$a26 = mysql_result($customer_result, 0, "country");
$a29 = mysql_result($customer_result, 0, "email_1");
$a30 = mysql_result($customer_result, 0, "cell_1");
$a32 = mysql_result($customer_result, 0, "cell_2");
$a35 = mysql_result($customer_result, 0, "contact_2");
$a36 = mysql_result($customer_result, 0, "notes");

$table_name = $_SESSION['db_prefix']."_cutting_bill_lines";
$check_query = "SELECT bill_line_id FROM $table_name WHERE job_no='".$job_no."'; ";
$check_result = mySQL_query($check_query);
$check_num = mysql_num_rows($check_result);

if ($check_num>0) {
$table_name = $_SESSION['db_prefix']."_cutting_bill_lines";
}
else {
$table_name = $_SESSION['db_prefix']."_cutting_bill_lines_done";
}



$truss_query = "SELECT truss_type, SUM(quantity) AS quantity  FROM $table_name WHERE job_no='".$job_no."' AND truss_type IS NOT NULL GROUP BY truss_type ORDER BY truss_type  ";

$truss_result = mySQL_query($truss_query);
$truss_num = mysql_num_rows($truss_result);
?>
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
</head>
<body>
<?php include ('../include/tooltip.php'); ?>

<div class="main_frame" style="height:auto;">
  <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 stock list:</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2">&nbsp;&nbsp;&nbsp; <?php echo $a0 ?></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>
</td>
</tr>
<tr>
  <td>
  <div class="page_middle_frame">
  <div align="left">
    <label class="label_std">Trusses:</label>
  </div>
    <table width="676" id="table_details_display">
      <tr>
        <th width="261" align="center">Truss type	</th>
        <th width="96" align="center">Ordered</th>
        <th width="86" align="center">Produced</th>
        <th width="86" align="center">Delivered</th>
        <th width="123" align="center">Stock</th>
        <?php 
	if ($truss_num!=0) {
	$i=0;
	while ($i<$truss_num) {
		$a1 = mysql_result($truss_result, $i, "truss_type");
		$a2 = mysql_result($truss_result, $i, "quantity");
				
		$table_name = $_SESSION['db_prefix']."_production_bill_lines";
		$produce_query = "SELECT SUM(quantity) AS summed_quantity, SUM(delivered) AS summed_delivered FROM $table_name WHERE job_no = '".$job_no."' AND truss_type = '".$a1."' ";
		
		$produce_result = mySQL_query($produce_query);
		$produce_num = mysql_num_rows($produce_result);
		
		if ($produce_num != 0) {
			
				$a3 = mysql_result($produce_result, 0, "summed_quantity");
				$a4 = mysql_result($produce_result, 0, "summed_delivered");
				$a5 = $a2 - $a4;
		}
		
		//if ($a3=='') {$a3=0;}	
//		if ($a4=='') {$a4=0;}	
//		if ($a5=='') {$a5=0;}		
		
		$a5 = $a3 - $a4;
	?>
        <tr>
          <td align="left" valign="top"><?php echo $a1 ?></td>
          <td align="center" valign="top"><?php if ($a2!=0) {echo $a2;} ?></td>
          <td align="center" valign="top"><?php if ($a3!=0) {echo $a3;}?></td>
          <td align="center" valign="top"><?php if ($a4!=0) {echo $a4;} ?></td>
          <td align="center" valign="top"><?php if ($a5!=0) {echo $a5;}?></td>
          </tr>
      <?php
	$i++;
	}
	
    }
    else {
    ?>
      <tr>
        <td colspan="3"><label class="label_std">&nbsp;</label>
          <label class="label_std">&nbsp;</label>
          </td>
        <td>
          <label class="label_std">&nbsp;</label>
          </td>
        <td>
          <label class="label_std">&nbsp;</label>
          </td>
        </tr>
      <?php
	}
	?>
      </table>
    <p>&nbsp;</p>
  </div></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>