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

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


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

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

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>  

</head>

<body>
<div class="main_frame" style="height:auto; min-height:555px;">
<div class="page_head_frame">
          <table width="690" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="493"><label class="label_page_head">
              Installation order</label></td>
              <td width="197"><label style="font-size:18px; "><?php echo $quote_no ?></label><br /><label style="font-size:18px; "><?php echo $branch ?> branch</label></td>
            </tr>
          </table>
        </div>
        <br />
        <br />
        <br />
<br />
<br />
<form name="form1" id="form1" action="install_order_save.php" method="get" >
      <div class="page_middle_frame">
       <div class="button_inside_frame"> Quotation for:&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;Quoatation date:&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($quotation_date)) ?>  
              <?php 
		include ('../include/customer_block.php');
		echo' <br>';
		?>
       </div>
      
        <div class="button_inside_frame">
        <br>
  Vertex book order no:&nbsp;&nbsp;
  <input type="text" name="book_order_text" id="book_order_text" class="text100" autocomplete="off" onkeyup="ToUpper(this)" >
  <br />
<br />
       Pricing details<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);

?>

Installation of Trusses and loose timbers &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CPLX: <?php echo  $cplx ?>&nbsp;&nbsp;&nbsp;Double storey:&nbsp;<?php echo $storey?>
<table width="650" id="table_details_display">
  <tr>
    <td width="426">Description</td>
    <td width="56">Quantity</td>
    <td width="46">Unit</td>
    <td width="60">Price/Unit</td>
    <td width="58">Total</td>
  </tr>
  <tr>
  <?php
  	$sub_total = 0;
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT quantity, purchase_price, price FROM $table_name WHERE truss_item = 'truss_M2' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $purchase_price;
	?>
    <td>Installation of trusses, inclusive of wall plates, bracing, runners, battens,underlay and valley linings, all as indicated on roof layouts.</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">M2</td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
    <td align="right"><?php echo number_format($purchase_price, 2, '.', ',') ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT quantity, purchase_price, price FROM $table_name WHERE truss_item = 'truss_M1' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $purchase_price;
	?>
    <td>Install fascia and barge boards.</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">M1</td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
    <td align="right"><?php echo number_format($purchase_price, 2, '.', ',') ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT quantity, purchase_price, price FROM $table_name WHERE truss_item = 'truss_No' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $purchase_price;
	?>
    <td>Supply and install truss hangers and rawbolts for trusses fixed to brickwork or concrete.</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">NO</td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
    <td align="right"><?php echo number_format($purchase_price, 2, '.', ',') ?></td>
  </tr>
</table><br>
Installation of concrete roof tiles<br>
<table width="650" id="table_details_display">
  <tr>
    <td width="426">Description</td>
    <td width="56">Quantity</td>
    <td width="46">Unit</td>
    <td width="60">Price/Unit</td>
    <td width="58">Total</td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT quantity, purchase_price, price FROM $table_name WHERE truss_item = 'tiles_M2' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $purchase_price;
	?>
    <td>Installation of concrete roof tiles, incl of cutting for valley- and hip tiles, all as indicated on roof layout</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">M2</td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
    <td align="right"><?php echo number_format($purchase_price, 2, '.', ',') ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT quantity, purchase_price, price FROM $table_name WHERE truss_item = 'tiles_M1' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $purchase_price;
	?>
    <td>Installation of ridge, hip and rake verge tiles (incl. of paint and dpc)</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">M1</td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
    <td align="right"><?php echo number_format($purchase_price, 2, '.', ',') ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT quantity, purchase_price, price FROM $table_name WHERE truss_item = 'tiles_M3' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $purchase_price;
	?>
    <td>Installation of valley gutters</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">M1</td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
    <td align="right"><?php echo number_format($purchase_price, 2, '.', ',') ?></td>
  </tr>
</table><br>

Engineering inspection
<table width="650" id="table_details_display">
  <tr>
    <td width="426">Description</td>
    <td width="56">Quantity</td>
    <td width="46">Unit</td>
    <td width="60">Price/Unit</td>
    <td width="58">Total</td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT quantity, purchase_price, price FROM $table_name WHERE truss_item = 'inspection' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $purchase_price;
	?>
    <td>Engineering inspection</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">NO</td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
    <td align="right"><?php echo number_format($purchase_price, 2, '.', ',') ?></td>
  </tr>
</table>
<br>
Additional work<br>
<table width="650" id="table_details_display">
  <tr>
    <td width="426">Description</td>
    <td width="56">Quantity</td>
    <td width="46">Unit</td>
    <td width="60">Price/Unit</td>
    <td width="58">Total</td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT additional_text, quantity, purchase_price, price FROM $table_name WHERE truss_item = 'add_1' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$additional_text = mysql_result($data_result, 0, "additional_text");
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $price;
	?>
    <td><?php echo $additional_text ?></td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">.</td>
    <td align="right"><?php if ($purchase_price!=0) {echo $purchase_price; } ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$data_query = "SELECT additional_text, quantity, purchase_price, price FROM $table_name WHERE truss_item = 'add_2' and quote_no = '".$quote_no."'" ;
	$data_result = mySQL_query($data_query);
	$additional_text = mysql_result($data_result, 0, "additional_text");
	$quantity = mysql_result($data_result, 0, "quantity");
	$purchase_price = mysql_result($data_result, 0, "purchase_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $price;
	?>
    <td><?php echo $additional_text ?></td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">.</td>
    <td align="right"><?php if ($purchase_price!=0) {echo $purchase_price; } ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
  </tr>
</table>
<br />
<table width="650" id="table_details_display">
  <tr>
    <td width="386">&nbsp;</td>
    <td width="104">Sub total:</td>
    <td width="144" align="right"><?php echo number_format($sub_total, 2, '.', ',') ?>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;<?php $discount_amount = $sub_total * ($quote_discount/100) ?></td>
    <td>Discount: <?php echo $quote_discount ?>%</td>
    <td align="right"><?php echo number_format($discount_amount, 2, '.', ',') ?></td>
  </tr>
  <tr>
    <td>&nbsp;<?php $sub_total2 = $sub_total - $discount_amount ?></td>
    <td>Sub total:</td>
    <td align="right"><?php echo number_format($sub_total2, 2, '.', ',') ?></td>
  </tr>
  <tr>
    <td>&nbsp;<?php $vat_amount = $sub_total2 * ($quote_vat/100) ?></td>
    <td>VAT @ <?php echo $quote_vat ?>%</td>
    <td align="right"><?php echo number_format($vat_amount, 2, '.', ',') ?></td>
  </tr>
  <tr>
    <td>&nbsp;<?php $all_total = $sub_total2 + $vat_amount ?></td>
    <td>Total:</td>
    <td align="right"><?php echo number_format($all_total, 2, '.', ',') ?></td>
  </tr>
</table>

          
        </div>
<table width="642" height="50" align="left" id="table_button_bar">
        <tr>
          <td width="117">&nbsp;</td>
          <td width="115">
          <input type="hidden" name="quote_no_text" id="quote_no_text" value = <?php echo $quote_no ?> />
          <input type="hidden" name="cust_id_text" id="cust_id_text" value = <?php echo $cust_id ?> />
          <input type="hidden" name="branch_text" id="branch_text" value = <?php echo $branch ?> />
          <input type="hidden" name="value_text" id="value_text" value = <?php echo $sub_total ?> />
          <input type="hidden" name="discount_text" id="discount_text" value = <?php echo $quote_discount ?> />
          <input type="hidden" name="vat_text" id="vat_text" value = <?php echo $quote_vat ?> />
          
          </td>
          <td width="99">
            </span></td>
          <td width="125" align="right"><input name="cancel_button" type="button" class="imagebutton" id="cancel_button" onClick="needToConfirm = false; cancel_confirmation(6, '../sales/sales_main.php?date=&branch=')" value="Cancel" tabindex="3"/></td>
          <td width="162" align="right"><input type="submit" name="next_button" id="next_button" class="imagebutton" value="Save order" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" tabindex="1"/></td>
        </tr>
      </table>        
        
  </div>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("book_order_text","req","- Vertex order book number.");
</script>
  
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "sales/sales_main.php?date=&branch=";	
include ("../navigation/sales_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>