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

<head>

<?php
include('../include/session.php');

$quote_no = $_GET['quote_no'];

$table_name = $_SESSION['db_prefix']."_quotations";
$qbill_query = "SELECT re_title, project, project_no, project_area, project_place, project_description, quotation_date, seller FROM $table_name WHERE quote_no = '".$quote_no."'  ";
$qbill_result = mySQL_query($qbill_query);
$qbill_num = mysql_num_rows($qbill_result);
$title = mysql_result($qbill_result, 0, "re_title");
$project = mysql_result($qbill_result, 0, "project");
$project_no = mysql_result($qbill_result, 0, "project_no");
$project_area = mysql_result($qbill_result, 0, "project_area");
$project_place = mysql_result($qbill_result, 0, "project_place");
$project_description = mysql_result($qbill_result, 0, "project_description");
$quotation_date = mysql_result($qbill_result, 0, "quotation_date");
$seller = mysql_result($qbill_result, 0, "seller");

$table_name = $_SESSION['db_prefix']."_quotation_notes";	
$notes_query = "SELECT  *   FROM $table_name WHERE quote_number = '".$quote_no."' ";
$notes_result = mySQL_query($notes_query);
$notes_num = mysql_num_rows($notes_result);

?>

<script type="text/javascript">
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>

<body>
<?php
include ("../navigation/header.php");
$page_name = "Sales-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/sales_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
    <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Bill of quantity </label><label class="label_page_head_2"><?php echo $title?></label></td>
            <td><label class="label_quote_no"><?php echo $quote_no ?></label></td>
      </tr>
    </table>
</div>

<div class="page_middle_frame">
<div class="page_inside_frame">
  <table width="680" align="center" id="table_display" >
    <tr>
      <td align="left" valign="top">Title:</td>
      <td colspan="3" align="left" valign="top"><?php echo $title ?>&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top">Date:</td>
      <td colspan="3" align="left" valign="top"><?php echo date("d-m-Y", strtotime($quotation_date)) ?>&nbsp;</td>
      </tr>
    <tr>
      <td >Project:</td>
      <td colspan="3" align="left" valign="top"><?php echo $project ?>&nbsp;</td>
      </tr>
    <tr>
      <td width="144" >Project or plot no:&nbsp;</td>
      <td colspan="3" align="left" valign="top"><?php echo $project_no.', '.$project_area.', '.$project_place ?>&nbsp;</td>
    </tr>
    <tr>
      <td valign="top">Project description:</td>
      <td colspan="3" align="left" valign="top"><?php echo $project_description ?>&nbsp;</td>
      </tr>
    <tr>
      <td align="left" valign="top">Sales representative:
        &nbsp;&nbsp;</td>
      <td colspan="3" align="left" valign="top"><?php echo $seller ?>&nbsp;</td>
      </tr>
    <tr>
      <td colspan="4" align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="left" valign="top"><b>Companies quoted</b></td>
      <td width="130" align="left" valign="top">Reference</td>
      <td width="210" align="left" valign="top">Value</td>
    </tr>
    <?php
			  	$table_name = $_SESSION['db_prefix']."_qbill_lines_temp";
				$bill_query = "SELECT * FROM $table_name WHERE user_name = '".$_SESSION['username']."' ";
				$bill_result = mySQL_query($bill_query);
				$bill_num = mysql_num_rows($bill_result);
				
			  $i=0;
			  while ($i<$bill_num) { 
			    $cust_id = mysql_result($bill_result, $i, "cust_id");
				$reference = mysql_result($bill_result, $i, "reference");
				$amount = mysql_result($bill_result, $i, "amount");
				
				$cust_id = mysql_result($bill_result, $i, "cust_id");
			 	$table_name = $_SESSION['db_prefix']."_customer";
				$name_query = "SELECT comp_name FROM $table_name WHERE cust_id = '".$cust_id."' ";
				$name_result = mySQL_query($name_query);
				$comp_name = mysql_result($name_result, 0, "comp_name");?>
    <tr>
      <td colspan="2" align="left" valign="top"><?php echo $comp_name ?></td>
      <td align="left" valign="top"><?php echo $reference ?>&nbsp;</td>
      <td align="left" valign="top">P <?php echo number_format($amount, 2, '.', ',') ?>&nbsp;</td>
    </tr>
    <?php
			  $i++;
			  }
			  ?>
  </table>
</div>
<div class="page_inside_frame"> Notes:
          <table width="650" id="table_details_display">
            <tr>
              <td width="81" height="25">Date:</td>
              <td width="86">&nbsp;Entry by:</td>
              <td width="475">Note:&nbsp;</td>
            </tr>
            <?php
			   $i=0;
			   while ($i<$notes_num) {
				   $c1 = mysql_result($notes_result, $i, "note_date");  
				   $c2 = mysql_result($notes_result, $i, "note_text");  
				   $c3 = mysql_result($notes_result, $i, "seller"); 
				   ?>
            <tr>
              <td height="25"><?php echo date("d-m-Y", strtotime($c1))?></td>
              <td><?php echo $c3 ?></td>
              <td><?php echo $c2 ?></td>
            </tr>
            <?php 
				  $i++;
			   }?>
          </table>
        </div>
</div>
</div>
<?php } else {
$_SESSION['denied_return'] = "sales/sales_main.php";	
include ("../navigation/sales_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</body>
</html>