<!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'];
$a = $_GET['a'];
	
$table_name2 = $_SESSION['db_prefix']."_captured_cash_sale";
$quote_query = "SELECT * FROM $table_name2 WHERE job_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, "date");
$sales_rep  = mysql_result($quote_result, 0, "sales_rep");


$sales_discount  = mysql_result($quote_result, 0, "sales_discount");
$sales_vat  = mysql_result($quote_result, 0, "sales_vat");

$project_no = mysql_result($quote_result, 0, "project_no");
$project_place = mysql_result($quote_result, 0, "project_place");
$notes = '';

$transport  = mysql_result($quote_result, 0, "transport");

$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");


$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>Cash sale 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/quote_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">Quotation 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_print" >
  <tr>
    <td width="128">Plot no:</td>
    <td width="116"><?php echo $project_no ?></td>
    <td width="146">Place:;</td>
    <td width="240"><?php echo $project_place ?></td>
  </tr>
  <tr>
    <td>Sales representative:</td>
    <td><?php echo $sales_rep ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table>
</div>      
    <div class="print_standard_frame"> <label class="print_header_label_std">Pricing details</label>
    :<br />
<br />

<?php
if ($a==1) {
$table_name = $_SESSION['db_prefix']."_cash_job_lines_done";
}
else {
$table_name = $_SESSION['db_prefix']."_cash_job_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 width="221" 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="58" align="center" valign="top">Quantity</td>
                  <td width="83" 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_2");
					 
					$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">&nbsp;
                  <?php $discount_amount = $a5_total * ($sales_discount/100) ?>
                  &nbsp;
                  <?php $sub_total = $a5_total - $discount_amount ?>
                  &nbsp;
                  
                  &nbsp;
                  <?php $sub_total3 = $sub_total + $transport ?> 
                  <?php $vat_amount = $sub_total3 * ($sales_vat/100) ?>
                  <?php $all_total = $sub_total3 + $vat_amount ?>
                  <br />
                  </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 $sales_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">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 $sales_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 />
      Our General Sales conditions are applicable and<br />
available on request.<br />
      This quotation is valid for 30 days.<br />
      Errors &amp; Omissions Excluded.</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>