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

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

$project = $_GET['project'];
$date1 = $_GET['date1'];
$date2 = $_GET['date2'];

include('../include/period_select_date.php');	


	
$table_name2 = $_SESSION['db_prefix']."_quotations";
$quotation_query = "SELECT quote_no, status, cust_id, type, project, quotation_date, required_date, company_contact, contact_phone, project_no, seller, value, vat_text FROM $table_name2 WHERE project = '$project' AND request_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 = "Sales-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/sales_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">Sales 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='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": false},
                             	{"bSortable": true},
								{"iDataSort": 8},
								{"bSortable": true},
								{"bSortable": true},
                              	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>

          <table width="745" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th align="center" >&nbsp;</th>
              <th width="77" >Number</th>
              <th >Quote Date</th>
              <th >Project</th>
              <th >Name</th>
              <th >Contact</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_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
         $customer_result = mySQL_query($customer_query);
		 $customer_num = mysql_num_rows($customer_result);
		 if ($customer_num!=0) {
         $a2a = 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, "contact_1");
		 $a3 = mysql_result($customer_result, 0, "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");
	$a13 = mysql_result($quotation_result, $i, "project");
	$a16 = mysql_result($quotation_result, $i, "vat_text");
	
	
	$table_name = $_SESSION['db_prefix']."_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><tr><td>Notes:</td><td></td></tr>".$notes_text."</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 width="27" align="center"><?php if ($a11=="quoted") { ?>
                <img src="../images/round_orange.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="accepted") { ?>
                <img src="../images/round_green.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="unsuccessful") { ?>
                <img src="../images/round_red.png" width="12" height="12"   />
                <?php } ?></td>
              <td align="left"  style="padding-left:0px;"><?php if ($a2==0) {?> <a href="qbill.php?quote_no=<?php echo $a1 ?> " onMouseover="ddrivetip('Bill of quantity', 100)"; onMouseout="hideddrivetip()"><?php } else { ?><a href="quotation.php?quote_no=<?php echo $a1 ?> " onMouseover="ddrivetip('<?php echo $quoteTT ?>', 450)"; onMouseout="hideddrivetip()"><?php } ?><?php if ($a2==0) { echo '<font color=green>'.$a1.'</font>'; } else { echo $a1; } ?></a></td>
              <td width="66" align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td width="146" align="left"><?php echo $a13 ?><br><?php echo $a12 ?></td>
              <td width="106" align="left"><?php if ($a2==0) { echo $a2a; } else { ?>
                <a href="customer_details.php?cust_id=<?php echo $a2 ?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a?></a>
              <?php } ?></td>
              <td width="106" align="left"><?php echo $a9."<br>".$a10 ?>&nbsp;</td>
              <td width="86" align="right"><?php if ($a16=='inclusive') { $a7=$a7/1.12; echo '*&nbsp;&nbsp;';} echo number_format($a7, 2, '.', ',') ?></td>
              <td width="68" align="left"><?php echo $a8 ?>&nbsp;</td>
              <td width="23" align="left"><?php echo $a5 ?>&nbsp;</td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="5" align="left" valign="bottom">&nbsp;</td>
                <td 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'] = "sales/sales_main.php";	
include ("../navigation/sales_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>
</html>