<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

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

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

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

<?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);
$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']."_cutting_supplies";
$supply_id_query = "SELECT cutting_supply_id, date FROM $table_name6 WHERE job_no = '".$job_no."' ";

$supply_id_result = mySQL_query($supply_id_query);
$supply_id_num = mysql_num_rows($supply_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");

?>
</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="452"><label class="label_page_head">Direct materials supply</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2">&nbsp;&nbsp;&nbsp;<?php echo $name; ?></label></td>
            <td width="228"><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><br>
<br>

  <?php 
$k=0;
while ($k<$supply_id_num) {
	$cutting_supply_id = mysql_result($supply_id_result, $k, "cutting_supply_id");
	$supply_date = mysql_result($supply_id_result, $k, "date");
	?>
  <div class="page_middle_frame">
    <label class="label_std" style="font-size:14px">
      
      Supplied on: <?php echo date("d-m-Y", strtotime($supply_date))?></label><br />
    <label class="label_std" style="font-size:12px">Timber</label>
    <table width="473"  id="table_list">
    <?php
	$table_name = $_SESSION['db_prefix']."_cutting_supplies_lines";
	$check_query = "SELECT cutting_line_id FROM $table_name WHERE cutting_supply_id = '".$cutting_supply_id."' ";
	$check_result = mySQL_query($check_query);
	$check_num = mysql_num_rows($check_result);
	
	if ($check_num>0) {
	       $table_name3 = $_SESSION['db_prefix']."_cutting_supplies_lines";
	}
	else {
		   $table_name3 = $_SESSION['db_prefix']."_cutting_supplies_lines_done";
	}
	
	$timber_query = "SELECT * FROM $table_name3 WHERE cutting_supply_id = '".$cutting_supply_id."' AND type='timber' ";
	$timber_result = mySQL_query($timber_query);
	$timber_num = mysql_num_rows($timber_result);
    $i=0;
    while ($i<$timber_num) {
		$a1=  mysql_result($timber_result, $i, "store_item_id");
			$table_name = $_SESSION['db_prefix']."_store_items";
			$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$a1."'  ";
			$item_result = mySQL_query($item_query);
			$a1a = mysql_result($item_result, 0, "item_name");
		$a2=  mysql_result($timber_result, $i, "quantity");
		?>
  <tr>
    <td width="238"><?php echo $a1a ?></td>
    <td width="223"><?php echo $a2 ?></td>
  </tr>
  <?php
	$i++;
	}
	?>
</table>
    <label class="label_std" style="font-size:12px">Plates</label>
    <table width="473" id="table_list">
    <?php
	$table_name = $_SESSION['db_prefix']."_cutting_supplies_lines";
	$check_query = "SELECT cutting_line_id FROM $table_name WHERE cutting_supply_id = '".$cutting_supply_id."' ";
	$check_result = mySQL_query($check_query);
	$check_num = mysql_num_rows($check_result);
	
	if ($check_num>0) {
	       $table_name3 = $_SESSION['db_prefix']."_cutting_supplies_lines";
	}
	else {
		   $table_name3 = $_SESSION['db_prefix']."_cutting_supplies_lines_done";
	}
	
	$plates_query = "SELECT * FROM $table_name WHERE cutting_supply_id = '".$cutting_supply_id."' AND type='plate' ";
	$plates_result = mySQL_query($plates_query);
	$plates_num = mysql_num_rows($plates_result);
    $i=0;
    while ($i<$plates_num) {
		$b1=  mysql_result($plates_result, $i, "store_item_id");
		    $table_name = $_SESSION['db_prefix']."_store_items";
			$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$b1."'  ";
			$item_result = mySQL_query($item_query);
			$b1a = mysql_result($item_result, 0, "item_name");
		$b2=  mysql_result($plates_result, $i, "quantity");
		?>
  <tr>
    <td width="238"><?php echo $b1a ?></td>
    <td width="223"><?php echo $b2 ?></td>
  </tr>
  <?php
	$i++;
	}
	?>
</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>