<head>
<?php 
include ("../navigation/header.php");

$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {
include ("../navigation/store_sidebar.php");
	
		$table_name = $_SESSION['db_prefix']."_production_bill_lines";
		$table_name2 = $_SESSION['db_prefix']."_captured_jobs";
		$items_query = "SELECT $table_name.job_no, $table_name2.cust_id, $table_name2.project_no, $table_name2.project_place  FROM $table_name, $table_name2 WHERE $table_name.job_no=$table_name2.job_no AND  ($table_name.quantity - $table_name.delivered) > 0 GROUP BY $table_name.job_no ORDER BY $table_name.job_no DESC ";
		$items_result = mySQL_query($items_query);
		$items_num = mysql_num_rows($items_result);
				
		$items_result = execsql($items_query);
    	$i = 0;
    	$items_num = mysql_num_rows($items_result);
		
		if ($items_num==0) {
		  $message="No records to show";
		  }
		else {
		  $message="End of list";
		  }
		
    	
?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

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

</head>

<body>

<div class="main_frame">
   <div class="page_head_frame">
    <label class="label_page_head">Store Trusses List </label>
  </div>
  <div class="scroll_frame_long" style="height:450px;">
    <table width="662" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "  >
      <thead>
        <tr>
          <th width="108" class="sortable-text">Job no</th>
          <th width="176" class="sortable-text">Customer</th>
          <th width="241" class="sortable-text">Project</th>
          <th width="117" class="sortable-numeric">&nbsp;</th>
        </tr>
      </thead>
      <tbody>
        <?php 
    $i=0;
	$truss_text='';
    while($i < $items_num){
	       $job_no = mysql_result($items_result, $i, "job_no");
		   $project = mysql_result($items_result, $i, "project_no").' '.mysql_result($items_result, $i, "project_place");
		   $cust_id = mysql_result($items_result, $i, "cust_id");
		   		$table_name3 = $_SESSION['db_prefix']."_customer";
         		$customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$cust_id."' ";
		 		$customer_result = mySQL_query($customer_query);
				$customer_num = mysql_num_rows($customer_result);
		 		if ($customer_num!=0) {
         		$a2a = mysql_result($customer_result, 0, "comp_name");
				$a2b = mysql_result($customer_result, 0, "bag_box");
		 		$a2c = mysql_result($customer_result, 0, "box_no");
		 		$a2d = mysql_result($customer_result, 0, "postal_place");
		 		$a2e = mysql_result($customer_result, 0, "phone");
		 		$a2f = mysql_result($customer_result, 0, "contact_1");
		 		$a3 = mysql_result($customer_result, 0, "status");
		 		}
				
				$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
				
				$table_name = $_SESSION['db_prefix']."_production_bill_lines";
				$truss_query = "SELECT truss_type, SUM(quantity) AS quantity, SUM(delivered) AS delivered FROM $table_name WHERE job_no = '".$job_no."' GROUP BY truss_type ORDER BY truss_type ";
				$truss_result = mySQL_query($truss_query);
				$truss_num = mysql_num_rows($truss_result);
				
				
				$j=0;
				$truss_text='';						
				while ($j<$truss_num) {
				$line_text='';	
				$k=0;
				while ($k<4) {				
				
				if ($j<$truss_num) {		
				$b1 = mysql_result($truss_result, $j, "truss_type");
				$b2 = mysql_result($truss_result, $j, "quantity");
				$b3 = mysql_result($truss_result, $j, "delivered");
				$b4 = $b2-$b3;
				}
				else {
					$b1='';
					$b4='';
				}
				$k++;			
				$line_text = $line_text."<td>".$b1."</td><td>".$b4."</td>";

				$j++;
								
				}
				$truss_text=$truss_text."<tr>".$line_text."</tr>";
				}	
				
							
				$trussTT ="<table id=table_tool_tip width=400 ><tr><td width=50>Truss:</td><td width=50>Qty</td><td width=50>Truss:</td><td width=50>Qty</td><td width=50>Truss:</td><td width=50>Qty</td><td width=50>Truss:</td><td width=50>Qty</td></tr>".$truss_text."</table><br><b>Click for details</b>";
		      
    ?>
        <tr class="alt">
          <td align="left"><a href="store_trusses_job_list.php?job_no=<?php echo $job_no?>" onMouseover="ddrivetip('<?php echo $trussTT?>', 400)"; onMouseout="hideddrivetip()"><?php echo $job_no ?></a></td>
          <td align="left"><a href="../sales/customer_details.php?cust_id=<?php echo $cust_id?>" onMouseover="ddrivetip('<?php echo $customerTT?>', 300)"; onMouseout="hideddrivetip()"><?php echo $a2a ?></a></td>
          <td align="left"><?php echo $project?></td>
          <td align="right">&nbsp;</td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
      </tbody>
    </table>
    <div align="left">
      <label class="label_end">
        <?php  echo $message ?>
      </label>
    </div>
  </div>
</div>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "store/store_main.php";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
