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

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


$job_no = $_GET['job_no'];
$quote='no';
$table_name = $_SESSION['db_prefix']."_captured_cash_sale";
$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");
 			}

?>

<?php

$table_name = $_SESSION['db_prefix']."_captured_mitek";
$mitek_check_query = "SELECT  cap_mitek_id FROM $table_name WHERE cap_job = '".$job_no."'  ";
$mitek_check_result = mySQL_query($mitek_check_query);
$mitek_check_num = mysql_num_rows($mitek_check_result);
if ($mitek_check_num!=0) { 
$table_name = $_SESSION['db_prefix']."_captured_mitek";
}
else {
$table_name = $_SESSION['db_prefix']."_captured_mitek_done";
}
$mitek_query = "SELECT cap_item_id, cap_quantity, auth_quantity FROM $table_name WHERE cap_job = '".$job_no."' ";
$mitek_result = mySQL_query($mitek_query);
$mitek_num = mysql_num_rows($mitek_result);


$table_name = $_SESSION['db_prefix']."_authorised_timber";
$timber_check_query = "SELECT  auth_id FROM $table_name WHERE auth_timber_group = 'Cash sale' AND job_no = '".$job_no."'  ";
$timber_check_result = mySQL_query($timber_check_query);
$timber_check_num = mysql_num_rows($timber_check_result);
if ($timber_check_num!=0) { 
$table_name = $_SESSION['db_prefix']."_authorised_timber";
}
else {
$table_name = $_SESSION['db_prefix']."_authorised_timber_done";
}
$timber_query = "SELECT * FROM $table_name WHERE auth_timber_group = 'Cash sale' AND job_no = '".$job_no."' GROUP BY auth_timber_name  ";
$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);


$table_name = $_SESSION['db_prefix']."_captured_sundries";
$additional_check_query = "SELECT  cap_sundries_id FROM $table_name WHERE cap_job = '".$job_no."'  ";
$additional_check_result = mySQL_query($additional_check_query);
$additional_check_num = mysql_num_rows($additional_check_result);
if ($additional_check_num!=0) { 
$table_name = $_SESSION['db_prefix']."_captured_sundries";
}
else {
$table_name = $_SESSION['db_prefix']."_captured_sundries_done";
}
$additional_query = "SELECT * FROM $table_name WHERE cap_job = '".$job_no."' ";
$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_result);

?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

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

</head>

<body>

<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">Cash sale authorisation</label>&nbsp;&nbsp;&nbsp;<label class="label_page_head_2"><?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/cash_sale_job_block.php')
		?>
    <br />
  </div>
  <div class="page_middle_frame">
  <table width="646" id="table_details_display" >
              <tr>
                <td align="left" valign="top"><label class="label_std">Timber</label></td>
                <td colspan="2" align="center" valign="top">Quoted</td>
                <td colspan="2" align="center" valign="top">Authorised</td>
              </tr>
               <?php 
				  $i=0;
				   while ($i<$timber_num) { 
					    $item_id = mysql_result($timber_result, $i, "store_item_id");
						//$_SESSION['quantity_'.$i] = mysql_result($mitek_result, $i, "cap_quantity");
						$timber_quantity = mysql_result($timber_result, $i, "reserved");
						$timber_auth_quantity = mysql_result($timber_result, $i, "reserved");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$item_id."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 	
				 ?>
             <tr>
               <td width="380"><?php echo $item_name ?></td>
               <td width="70" align="right" style="border-right:hidden"><?php echo $timber_quantity ?></td>
               <td width="36">&nbsp;<?php echo $unit?></td>
               <td width="96" align="right" style="border-right:hidden"><?php echo $timber_auth_quantity ?></td>
               <td width="40">&nbsp;&nbsp;<?php echo $unit?></td>
             </tr>
              <?php
						
			  $i++;
             }
             ?>
        </table><br />

  
 <table width="646" id="table_details_display" >
              <tr>
                <td align="left" valign="top"><label class="label_std">Mitek products:</label></td>
                <td colspan="2" align="center" valign="top">Quoted</td>
                <td colspan="2" align="center" valign="top">Authorised</td>
              </tr>
               <?php 
				  $i=0;
				   while ($i<$mitek_num) { 
					    $item_id = mysql_result($mitek_result, $i, "cap_item_id");
						//$_SESSION['quantity_'.$i] = mysql_result($mitek_result, $i, "cap_quantity");
						$mitek_quantity = mysql_result($mitek_result, $i, "cap_quantity");
						$mitek_auth_quantity = mysql_result($mitek_result, $i, "auth_quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$item_id."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 	
				 ?>
             <tr>
               <td width="380"><?php echo $item_name ?></td>
               <td width="70" align="right" style="border-right:hidden"><?php echo $mitek_quantity ?></td>
               <td width="36">&nbsp;<?php echo $unit?></td>
               <td width="96" align="right" style="border-right:hidden"><?php echo $mitek_auth_quantity ?></td>
               <td width="40">&nbsp;&nbsp;<?php echo $unit?></td>
             </tr>
              <?php
						
			  $i++;
             }
             ?>
        </table><br />

 <table width="646" id="table_details_display" > 
             <tr>
               <td><label class="label_std">Additional Sundries</label></td>
               <td colspan="2" align="center">Quoted</td>
               <td colspan="2" align="center">Authorised</td>
             </tr>
             <?php 
				  $m=0;
				  while ($m<$additional_num) { 
					    $additional_item_id = mysql_result($additional_result, $m, "cap_item_id");
						$_additional_quantity = mysql_result($additional_result, $m, "cap_quantity");
						$_additional_auth_quantity = mysql_result($additional_result, $m, "auth_quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$additional_item_id. "' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name_num = mysql_num_rows($item_name_result);
						if ($item_name_num!=0) {
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						}
				 ?>
             <tr>
               <td width="380"><?php echo $item_name ?></td>
               <td width="70" align="right" style="border-right:hidden" ><?php echo $_additional_quantity?></td>
               <td width="36">&nbsp;<?php echo $unit ?></td>
               <td width="96" align="right" style="border-right:hidden"><?php echo $_additional_auth_quantity ?></td>
               <td width="40">&nbsp;<?php echo $unit ?></td>
             </tr>
              <?php
					
			  $m++;
             }
				
             ?>
    </table>
  </div>
  </td>
</tr>

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

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



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