<!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('../include/session.php');


$quote_no = $_GET['quote_no'];
	
$table_name2 = $_SESSION['db_prefix']."_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");
$quote_type  = mysql_result($quote_result, 0, "quote_type");
$cplx  = mysql_result($quote_result, 0, "cplx");
$storey  = mysql_result($quote_result, 0, "storey");
$quote_discount  = mysql_result($quote_result, 0, "quote_discount");
$quote_vat  = mysql_result($quote_result, 0, "quote_vat");
$branch  = mysql_result($quote_result, 0, "branch");
$project_no = mysql_result($quote_result, 0, "project_no");
$project_place = mysql_result($quote_result, 0, "project_place");
$notes = mysql_result($quote_result, 0, "notes");
$sales_rep = mysql_result($quote_result, 0, "seller");
$transport  = mysql_result($quote_result, 0, "transport");
$pallets  = mysql_result($quote_result, 0, "pallets");
$pallets_price  = mysql_result($quote_result, 0, "pallets_price");

$pallets_total = $pallets * $pallets_price;

$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']."_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 = '';
}


$report_name = 'Quotation';
$report_no = $quote_no;
?>

<!--style sheets-->
<link href="../css/print.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" type="image/x-icon" href="../images/favicon.ico">
<title>Tiles quotation <?php echo $quote_no ?></title>

</head>

<body>

<script>
window.onload = function () {
  window.print();
  setTimeout(function(){window.close();}, 100);
}
</script>


<div class="print_standard_frame">
<?php include('../include/print_header.php'); ?>
<div class="print_main_frame" style="height:auto; margin-left:50px;">
<br>
<br>

<div class="print_standard_frame"> 
<label class="print_header_label_std">Quotation for:</label>&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;&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;
<label class="print_header_label_std">Quoatation date:&nbsp;&nbsp;
<?php echo date("d-m-Y", strtotime($quotation_date)) ?></label><br /><br />

  
              <?php 
		include ('../include/customer_block.php');
		echo' <br>';
		?>
       </div>
<div class="print_standard_frame">
<label class="print_header_label_std">Delivery address:</label>
<br />
<br>
<table width="650" id="table_display" >
  <tr>
    <td width="112">Plot no:</td>
    <td width="132"><?php echo $project_no ?></td>
    <td width="146">Place:;</td>
    <td width="240"><?php echo $project_place ?></td>
  </tr>
  <tr>
    <td>Quotation made by:</td>
    <td><?php echo $branch ?> branch</td>
    <td>Sales representative:</td>
    <td><?php echo $sales_rep ?></td>
    </tr>
</table>
</div>      
    <div class="print_standard_frame"> <label class="print_header_label_std">Pricing details</label>
    :<br />
<br />

<?php

$table_name = $_SESSION['db_prefix']."_quotation_lines";
$line_query = "SELECT *  FROM $table_name WHERE  quote_no =  '".$quote_no."'";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

 ?>
              <table width="650" id="table_display" >
                <tr>
                  <td height="26" align="left" valign="top">Item</td>
                  <td width="116" align="left" valign="top">Group</td>
                  <td width="71" align="center" valign="top">Unit</td>
                  <td width="56" align="center" valign="top">Quantity</td>
                  <td width="85" align="center" valign="top">Unit price</td>
                  <td width="73" align="center" valign="top">Amount</td>
                </tr>
                <?php
				$i=0;
				$sub_tot=0;
				$a5_total=0;
				 while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "quote_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "price");
					 
					$a5=$a2*$a3;
					$a5_total=$a5_total+$a5;
					 
				 ?>
                <tr>
                  <td valign="top"><?php echo $a1a ?></td>
                  <td valign="top"><?php echo $a4a ?></td>
                  <td valign="top"><?php echo $a3a ?></td>
                  <td valign="top"><?php if ($a2!=0) {echo number_format($a2, 0, '.', ',');} ?></td>
                  <td align="right" valign="top"><?php echo $a3. "  /" .$a3a ?>&nbsp;</td>
                  <td align="right" valign="top"><?php if ($a5!=0) {echo number_format($a5, 2, '.', ',');} ?></td>
                </tr>
                <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
                <tr>
                  <td colspan="3" rowspan="8" align="left" valign="top">
                  <?php $discount_amount = $a5_total * ($quote_discount/100) ?>
                  <?php $sub_total = $a5_total - $discount_amount ?>
                  <?php $sub_total3 = $sub_total + $pallets_total + $transport ?> 
                  <?php $vat_amount = $sub_total3 * ($quote_vat/100) ?>
                  <?php $all_total = $sub_total3 + $vat_amount ?>
                  Offloading to be done by customer.<br />
                  Pallets refundable on return.<br />Delivery details:<br />
<?php echo $notes ?></td>
                  <td colspan="2" align="left" valign="top">Sub total:</td>
                  <td align="right" valign="top"><?php echo number_format($a5_total, 2, '.', ',') ?></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" valign="top">Discount: <?php echo $quote_discount ?>%</td>
                  <td align="right" valign="top"><?php echo number_format($discount_amount, 2, '.', ',') ?></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" valign="top">Sub total:</td>
                  <td align="right" valign="top"><?php echo number_format($sub_total, 2, '.', ',') ?></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" valign="top"><?php echo $pallets ?> pallets:</td>
                  <td align="right" valign="top"><?php if ($transport!='') { echo number_format($pallets_total, 2, '.', ','); } else { echo '0.00'; } ?></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" valign="top">Transport:</td>
                  <td align="right" valign="top"><?php if ($transport!='') { echo number_format($transport, 2, '.', ','); } else { echo '0.00'; } ?></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" valign="top">Sub total:</td>
                  <td align="right" valign="top"><?php echo number_format($sub_total3, 2, '.', ',') ?></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" valign="top">VAT @ <?php echo $quote_vat ?>%</td>
                  <td align="right" valign="top"><?php echo number_format($vat_amount, 2, '.', ',') ?></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" valign="top">Total:</td>
                  <td align="right" valign="top"><?php echo number_format($all_total, 2, '.', ',') ?></td>
                </tr>
              </table>
             
<br />
<table width="650" id="table_display" >
  <tr>
    <td width="308">Please note:<br />
    <font size="-2">  The use of underlay is mandatory and should be installed according to manufacturer’s instruction.<br />
Our General Sales conditions are applicable and<br />
available on request.<br />
Upon cancelation of an order, a minimum 20% handling fee will be charged to the client to cover all incurred costs relating to that order.<br />
      This quotation is valid for 30 days.<br />
      Errors &amp; Omissions Excluded. </font></td>
    <td width="330">Customer's Confirmation:<br />
      <br />
      Name: _____________________<br />
      <br />
      Signature: __________________&nbsp;&nbsp;&nbsp;Date:&nbsp;&nbsp;___________<br />
      <br /></td>
  </tr>
</table>
<br />
          
      </div>
        
        
  </div>
  <!--end of tableMain--> 
  
</div>

</body>

</html>