<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include('../include/session.php');

include('../include/period_select_date.php');	
	
$table_name2 = $_SESSION['db_prefix']."_maintenance_quotations";
$quotation_query = "SELECT quote_no, status, cust_id, type, project, quotation_date, required_date, company_contact, contact_phone, project_no, project_area, project_place, seller,  value, vat_text FROM $table_name2 WHERE quotation_date BETWEEN '".$start."' AND '".$end."' ORDER BY quote_no DESC ";
$quotation_result = mySQL_query($quotation_query);
$quotation_num = mysql_num_rows($quotation_result);	

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

<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></script>
<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="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="385"><label class="label_page_head">Maintenance quotations</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
        <br />
        <br />
        <br />
        <br />
        <div class="page_middle_frame">
        <?php
$page='maintenance_quotations_list.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>

        
        <div  class="page_inside_frame">
          <div align="right">
            <label class="label_end"><img src="../images/round_green.png" width="8" height="8" />: succes&nbsp;&nbsp;<img src="../images/round_orange.png" width="8" height="8" />: pending&nbsp;&nbsp;<img src="../images/round_red.png" width="8" height="8" />:unsuccesful</label>
          </div>
          <script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "490px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"iDataSort": 8},
								{"bSortable": true},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>

          <table width="650" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th width="18" >&nbsp;</th>
              <th >Number</th>
              <th >Quote Date</th>
              <th >Project</th>
              <th >Name</th>
              <th >Project no</th>
              <th >Value</th>
              <th >Sales rep</th>
              <th>&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;

$a7tot=0;
$price=0;
while ($i<$quotation_num) {
	$a1 = mysql_result($quotation_result, $i, "quote_no");
	
	$a2 = mysql_result($quotation_result, $i, "cust_id");
		 if ($a2==0) {
			    $a2a = 'Bill of quantity';
		 		$a2b = '';
		 		$a2c = '';
		 		$a2d = '';
		 		$a2e = '';
		 		$a2f = '';
		 		$a3 = '';
		 }
		 else {			 
	     $table_name = $_SESSION['db_prefix']."_customer";
			$customer_query = "SELECT status, account_type, comp_name, name_2, title, bag_box, box_no, postal_place, phone, cell_1  FROM $table_name WHERE cust_id = '".$a2."' ";
			$customer_result = mySQL_query($customer_query);
			$customer_num = mysql_num_rows($customer_result);
			if ($customer_num!=0) {
			$type = mysql_result($customer_result, 0, "account_type");
			if ($type=="corporate") { 
				$a2a = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$a2a = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}	
			$a2b = mysql_result($customer_result, 0, "bag_box");
			$a2c = mysql_result($customer_result, 0, "box_no");
			$a2d = mysql_result($customer_result, 0, "postal_place");
			$a2e = mysql_result($customer_result, 0, "phone");
			$a2f = mysql_result($customer_result, 0, "cell_1");
			$a2g = mysql_result($customer_result, 0, "status");
			$a2h="";
			}
			else {
			$a2a='';
			}
		 }
		
	$a3 = mysql_result($quotation_result, $i, "status");
	
	$a5 = mysql_result($quotation_result, $i, "quotation_date");
	$a6 = mysql_result($quotation_result, $i, "required_date");
	$a7 = mysql_result($quotation_result, $i, "value");	
	
	$a8 = mysql_result($quotation_result, $i, "seller");
	$a9 = mysql_result($quotation_result, $i, "company_contact");
	$a10 = mysql_result($quotation_result, $i, "contact_phone");
	$a11 = mysql_result($quotation_result, $i, "status");
	$a12 = mysql_result($quotation_result, $i, "project_no");
	$a18= mysql_result($quotation_result, $i, "project_area");
	$a17= mysql_result($quotation_result, $i, "project_place");
	$a13 = mysql_result($quotation_result, $i, "project");
	$a16 = mysql_result($quotation_result, $i, "vat_text");
	
	
	$table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
	$line_query = "SELECT  quote_item_text, quote_item_price   FROM $table_name WHERE quote_number = '".$a1."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	
	$l=0;
	$a14=0;
	$line_text="";
	//$products=mysql_result($line_result, 0, "quote_item_text");
		
	while($l<$line_num) {
	   $price=mysql_result($line_result, $l, "quote_item_price");
	   $a14=$price+$a14;	
	  
	   $line = mysql_result($line_result, $l, "quote_item_text");
	   $line_text = $line_text."&nbsp;-&nbsp;".$line." @ P ".number_format($price, 2, '.', ',')."<br>";
	   $l++;
	   
	}
	
	$a7tot = $a7tot + $a7;
	
	//$table_name = $_SESSION['db_prefix']."_quotation_notes";
//	$notes_query = "SELECT  note_date, note_text, seller   FROM $table_name WHERE quote_number = '".$a1."' ORDER BY note_date DESC";
//	$notes_result = mySQL_query($notes_query);
//	$notes_num = mysql_num_rows($notes_result);
//	$notes_text='';
//	$m=0;
//	while ($m<$notes_num) {
//		$notes1 = date("d-m-Y", strtotime(mysql_result($notes_result, $m, "note_date")))." ".mysql_result($notes_result, $m, "seller").": ";
//		$notes2 = mysql_result($notes_result, $m, "note_text");
//		$notes_text=$notes_text.'<tr><td valign=top>'.$notes1.'</td><td valign=top>'.$notes2.'</td><tr>';
//		$m++;
//	}
	
	
	$quoteTT ="<table id=table_tool_tip width=450 ><tr><td  width=75>Quote no:</td><td width=175>".$a1."</td></tr></tr><tr><td valign=top>Items quoted:</td><td valign=top>".$line_text."</td></tr><tr><td valign=top>Total quote value:</td><td valign=top>P".number_format($a7, 2, '.', ',')."</td></tr></table><br><b>Click for details</b>";
	
	$productsTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Products quoted:</td><td width=175>".$line_text."</td></tr></table><br><b>Click for details</b>";
	$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
	?>
            <tr>
              <td align="center"  style="padding-left:0px;">
			  <?php if ( ($a3=='accepted') OR($a3=='invoiced') OR ($a3=='contract')) { ?><img src="../images/round_green.png" width="12" height="12"><?php } ?>
              <?php if (($a3=='quoted') ) { ?><img src="../images/round_orange.png" width="12" height="12"><?php } ?>
              <?php if (($a3=='declined') ) { ?><img src="../images/round_red.png" width="12" height="12"><?php } ?>
              </td>
              <td width="76" align="left"><span style="padding-left:0px;"><a href="maintenance_quotation.php?quote_no=<?php echo $a1 ?> " onMouseOver="ddrivetip('<?php echo $quoteTT ?>', 450)"; onMouseOut="hideddrivetip()"><?php echo $a1 ?></a></span></td>
              <td width="76" align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td width="126" align="left"><?php echo $a13 ?></td>
              <td width="126" align="left"><?php if ($a2==0) { echo $a2a; } else { ?>
                <a href="../sales/customer_details.php?cust_id=<?php echo $a2 ?>" onMouseOver="ddrivetip('<?php echo $customerTT?>', 250)"; onMouseOut="hideddrivetip()"><?php echo $a2a?></a>
              <?php } ?></td>
              <td width="186" align="left">&nbsp;<?php echo $a12.' '.$a18.' '.$a17 ?></td>
              <td width="66" align="right"><?php if ($a16=='inclusive') { $a7=$a7/1.12; echo '*&nbsp;&nbsp;';} echo number_format($a7, 2, '.', ',') ?></td>
              <td width="70" align="left"><?php echo $a8 ?>&nbsp;</td>
              <td width="33" align="left"><?php echo $a5 ?>&nbsp;</td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="6" align="right" valign="bottom">Total:</td>
                <td align="right" valign="bottom"><?php echo number_format($a7tot, 2, '.', ',') ?>&nbsp;</td>
                <td colspan="2" align="right" valign="bottom">&nbsp;</td>
              </tr>
            </tfoot>
          </table>
          
        </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>