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

$order_no = $_GET['order_no'];
	
$table_name2 = $_SESSION['db_prefix']."_install_orders";
$order_query = "SELECT * FROM $table_name2 WHERE order_no ='".$order_no."' ";
$order_result = mySQL_query($order_query);
$order_num = mysql_num_rows($order_result);
$cust_id  = mysql_result($order_result, 0, "cust_id");
$order_date  = mysql_result($order_result, 0, "order_date");
$cplx  = mysql_result($order_result, 0, "cplx");
$storey  = mysql_result($order_result, 0, "storey");
$order_discount  = mysql_result($order_result, 0, "order_discount");
$order_vat  = mysql_result($order_result, 0, "order_vat");
$branch  = mysql_result($order_result, 0, "branch");
$order_book_no  = mysql_result($order_result, 0, "order_book_no");



$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 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>
</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">
              Edit Installation book order no</label></td>
              <td width="197"><label style="font-size:18px; "><?php echo $order_no ?></label><br /><label style="font-size:18px; "><?php echo $branch ?> branch</label></td>
            </tr>
          </table>
        </div>
        <br />
        <br />
        <br />
<br />
<br />
<form action="install_order_edit_save.php" method="get">  
      <div class="page_middle_frame">
       <div class="button_inside_frame"> Order for:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order date:&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($order_date)) ?>&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;Vertex book order no: &nbsp;
<input type="text" name="order_book_no_text" id="order_book_no_text" class="text100" value="<?php echo $order_book_no ?>" autocomplete="off" onfocus = "this.select();" onkeyup="ToUpper(this)"><input name="order_no_text" type="hidden" value="<?php echo $order_no ?>">
<input type="submit" name="save_button" id="save_button" class="imagebutton" value="Save & Close">

              <br /><br />

              <?php 
		include ('../include/customer_block.php');
		echo' <br>';
		?>
       </div>
 
        <div class="button_inside_frame"> Pricing details<br />

<?php

$table_name = $_SESSION['db_prefix']."_install_order_lines";
$line_query = "SELECT *  FROM $table_name WHERE  order_no =  '".$order_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']."_install_order_lines";
	$data_query = "SELECT quantity, unit_price, price FROM $table_name WHERE truss_item = 'truss_M2' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $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 echo number_format($unit_price, 2, '.', ',') ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_install_order_lines";
	$data_query = "SELECT quantity, unit_price, price FROM $table_name WHERE truss_item = 'truss_M1' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $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 echo number_format($unit_price, 2, '.', ',') ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_install_order_lines";
	$data_query = "SELECT quantity, unit_price, price FROM $table_name WHERE truss_item = 'truss_No' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $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 echo number_format($unit_price, 2, '.', ',') ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></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']."_install_order_lines";
	$data_query = "SELECT quantity, unit_price, price FROM $table_name WHERE truss_item = 'tiles_M2' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $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 echo number_format($unit_price, 2, '.', ',') ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_install_order_lines";
	$data_query = "SELECT quantity, unit_price, price FROM $table_name WHERE truss_item = 'tiles_M1' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $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 echo number_format($unit_price, 2, '.', ',') ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_install_order_lines";
	$data_query = "SELECT quantity, unit_price, price FROM $table_name WHERE truss_item = 'tiles_M3' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $price;
	?>
    <td>Installation of valley gutters</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">M1</td>
    <td align="right"><?php echo number_format($unit_price, 2, '.', ',') ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></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']."_install_order_lines";
	$data_query = "SELECT quantity, unit_price, price FROM $table_name WHERE truss_item = 'inspection' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_price");
	$price = mysql_result($data_result, 0, "price");
	$sub_total = $sub_total + $price;
	?>
    <td>Engineering inspection</td>
    <td><?php if ($quantity!=0) {echo $quantity; } ?></td>
    <td align="center">NO</td>
    <td align="right"><?php echo number_format($unit_price, 2, '.', ',') ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></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']."_install_order_lines";
	$data_query = "SELECT additional_text, quantity, unit_price, price FROM $table_name WHERE truss_item = 'add_1' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$additional_text = mysql_result($data_result, 0, "additional_text");
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_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 ($unit_price!=0) {echo $unit_price; } ?></td>
    <td align="right"><?php if ($price!=0) echo $price ?></td>
  </tr>
  <tr>
  <?php
  	$table_name = $_SESSION['db_prefix']."_install_order_lines";
	$data_query = "SELECT additional_text, quantity, unit_price, price FROM $table_name WHERE truss_item = 'add_2' and order_no = '".$order_no."'" ;
	$data_result = mySQL_query($data_query);
	$additional_text = mysql_result($data_result, 0, "additional_text");
	$quantity = mysql_result($data_result, 0, "quantity");
	$unit_price = mysql_result($data_result, 0, "unit_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 ($unit_price!=0) {echo $unit_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 * ($order_discount/100) ?></td>
    <td>Discount: <?php echo $order_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 * ($order_vat/100) ?></td>
    <td>VAT @ <?php echo $order_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>
<table width="642" height="50" align="left" id="table_button_bar">
  <tr>
    <td width="117"></td>
    <td width="115">&nbsp;</td>
    <td width="99"></span></td>
    <td width="185" align="right">&nbsp;</td>
    <td width="102" align="right"><input type="button" name="close_button" id="close_button" value="Close" class="imagebutton" onclick="MM_goToURL('parent','sales_main.php?date=&amp;branch=');return document.MM_returnValue" /></td>
  </tr>
</table>
<br />
<br />
     
</div>

</div>
</form>
  
</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>