<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--design only--><link rel="stylesheet" type="text/css" href="../css/main.css" />
<?php
include('../include/session.php');

$quote_no = $_GET['quote_no'];
	
$table_name2 = $_SESSION['db_prefix']."_maintenance_quotations";
$quote_query = "SELECT * FROM $table_name2 WHERE quote_no ='".$quote_no."' ";
$quote_result = mySQL_query($quote_query);
$quote_num = mysql_num_rows($quote_result);
$cust_id  = mysql_result($quote_result, 0, "cust_id");
$quotation_date  = mysql_result($quote_result, 0, "quotation_date");
//$job_card_no  = mysql_result($quote_result, 0, "job_card_no");
$valid_days   = mysql_result($quote_result, 0, "valid_days");
$delivery_days   = mysql_result($quote_result, 0, "delivery_days");
$terms   = mysql_result($quote_result, 0, "terms");
$project   = mysql_result($quote_result, 0, "project");
$re_title   = mysql_result($quote_result, 0, "re_title");
$vat = mysql_result($quote_result, 0, "vat_text");


if ($cust_id!='0') {
$table_name3 = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT account_type, comp_name, name_2, title, bag_box, box_no, postal_place, phone, contact_1, email_1, cell_1, status FROM $table_name3 WHERE cust_id = '".$cust_id."' ";

$customer_result = mySQL_query($customer_query);
$c0 = mysql_result($customer_result, 0, "account_type");
if ($c0=="corporate") { $c1 = mysql_result($customer_result, 0, "comp_name"); } else { $c1 = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name"); }

$c2 = mysql_result($customer_result, 0, "bag_box");
$c3 = mysql_result($customer_result, 0, "box_no");
$c4 = mysql_result($customer_result, 0, "postal_place");
$c5 = mysql_result($customer_result, 0, "phone");
$c6 = mysql_result($customer_result, 0, "contact_1");
$c7 = mysql_result($customer_result, 0, "email_1");
$c8 = mysql_result($customer_result, 0, "status");
$c9 = mysql_result($customer_result, 0, "cell_1");
$customerTT = "<label class=tip_text_label>".$c1."<br>".$c2." ".$c3."<br>".$c4."<br>".$c5."<br>".$c6."<br><label class=tip_click_label>Click for details</label>";
}

$table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
$line2_query = "SELECT quote_option_text, quote_item_text, quote_item_price  FROM $table_name WHERE quote_number = '".$quote_no."' ";
$line2_result = mySQL_query($line2_query);
$line2_num = mysql_num_rows($line2_result);
$re_text = mysql_result($line2_result, 0, "quote_option_text");




//$table_name = $_SESSION['db_prefix']."_quotation_accept";
//$accept_query = "SELECT accept_value, receipt_no, order_no FROM $table_name WHERE quote_no = '".$quote_no."' ORDER BY accept_id DESC LIMIT 1 ";
//$accept_result = mySQL_query($accept_query);
//$accept_num = mysql_num_rows($accept_result);
//if ($accept_num!=0) {
//		$value = mysql_result($accept_result, 0, "accept_value");
//		$receipt_no = mysql_result($accept_result, 0, "receipt_no");
//		$order_no = mysql_result($accept_result, 0, "order_no");
//		
//}
//else {
//	$value = '';
//}
?>
<!--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>
<?php
include ("../navigation/header.php");
$page_name = "Maintenance-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/maintenance_sidebar.php");
	?>
<div class="main_frame">
<div class="page_head_frame">
          <table width="690" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="556"><label class="label_page_head">Quotation</label><label class="label_page_head_2"> <b><?php echo $c1 ?></b></label></td>
              <td width="124"><label class="label_quote_no"><?php echo $quote_no ?></label></td>
            </tr>
          </table>
</div>
       
      <div class="page_middle_frame">
 <div class="page_inside_frame"> Quotation details  
              <?php 
			  include ('../include/customer_block.php');
			  ?>
       </div>     
       
      <div class="page_inside_frame">
        <p>Project: &nbsp;&nbsp;<?php echo $project ?>&nbsp;&nbsp;&nbsp;<br>
          <br>
        &nbsp;Re: <?php echo $re_text ?></p>
        <p>Quotation no:&nbsp;&nbsp;<font color="209949">M</font><?php echo $quote_no ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quotation date:&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($quotation_date)) ?></p>
        <p>        Valid for: <?php echo $valid_days?> days&nbsp;&nbsp;<br />
        Delivery: <?php echo $delivery_days?> days
          <br />
        </p>

      </div> 
     <div class="page_inside_frame"> Pricing details<br />
             
       <?php if (($project=='Maintenance Fence (Residential)') OR ($project=='Maintenance Fence (Commercial)') OR ($project=='Maintenance Gate Motor') OR ($project=='Maintenance miscellaneous')) { 
	
	  ?>  
       <table width="650" id="table_details_display">
            
      <?php
	  $sub_total=0;
	  $vat_amount=0;
	  $total=0;
	  $i=0;	
	  while ($i<$line2_num) {
		  $d1 = mysql_result($line2_result, $i, "quote_item_text");
		  $d2 = mysql_result($line2_result, $i, "quote_item_price");
		  $sub_total = $sub_total + $d2;
		   ?>
            <tr>
              <td><?php echo $d1 ?></td>
              <td align="right"><?php echo number_format($d2, 2, '.', ',') ?></td>
            </tr>
            <?php
	  $i++;
	  }
	  ?>
	  <tr>
                    <td align="right">Sub total</td>
                    <td align="right"><?php echo number_format($sub_total, 2, '.', ',') ?></td>
                  </tr>
                  <tr>
                    <td align="right">VAT <?php echo $vat?>% <?php $vat_amount = $sub_total * ($vat/100) ?> </td>
                    <td align="right"><?php echo number_format($vat_amount, 2, '.', ',') ?></td>
                  </tr>
                  <tr>
                    <td align="right">Total Price Supply & Install <?php $total = $sub_total + $vat_amount ?></td>
                    <td align="right"><?php echo number_format($total, 2, '.', ',') ?></td>
                  </tr>	 
      
 </table>
  <?php
	   }
	  ?>
      
 
   <?php if (($project=='Monthly maintenance')) { 
	
	  ?>  
       <table width="650" id="table_details_display">
            
      <?php
	  $sub_total=0;
	  $vat_amount=0;
	  $total=0;
	  	  $table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
		  $line_query = "SELECT * FROM $table_name WHERE quote_number = '".$quote_no."' AND quote_item_text = 'Year rate (11 months)' ";
		  $line_result = mySQL_query($line_query);
		  $line_num = mysql_num_rows($line_result);
		  $d1 = mysql_result($line_result, 0, "quote_item_text");
		  $d2 = mysql_result($line_result, 0, "quote_item_price");
		  $sub_total = $sub_total + $d2;
		   ?>
            <tr>
              <td><?php echo $d1 ?></td>
              <td align="right"><?php echo number_format($d2, 2, '.', ',') ?></td>
            </tr>
           
      
 </table>
  <?php
	   }
	?>
      
 
 </div>     

<?php if (($project=='Maintenance Fence (Residential)') OR ($project=='Maintenance Fence (Commercial)') OR ($project=='Maintenance Gate Motor') OR ($project=='Maintenance miscellaneous')) {$print_file = 'print_maintenance_quotation_co.php?quote_no='.$quote_no;} ?>
<?php if (($project=='Monthly maintenance')) { $print_file = 'print_maintenance_quotation_contract.php?quote_no='.$quote_no;} ?>
        <div class="page_inside_frame">

        <a href="<?php echo $print_file;?>" target="_blank"><input name="print_button" type="button" class="imagebutton" value="Print customers copy" /></a>
        </div>
</div>
</div>  

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