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

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

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

$table_name2 = $_SESSION['db_prefix']."_quotations";
$quotation_query = "SELECT quote_no, cust_id, type, request_date, company_contact, contact_phone, project, project_no, project_area, project_place, seller, value, result FROM $table_name2  WHERE request_date BETWEEN '".$start."' AND '".$end."' ORDER BY quote_no DESC ";
$quotation_result = mySQL_query($quotation_query);
$quotation_num = mysql_num_rows($quotation_result);	

$table_name = $_SESSION['db_prefix']."_quotations";
$request_query = "SELECT status  FROM $table_name WHERE status = 'request' AND request_date BETWEEN '".$start."' AND '".$end."'  ";
$request_result = mySQL_query($request_query);
$request_num = mysql_num_rows($request_result);

$table_name = $_SESSION['db_prefix']."_quotations";
$quoted_query = "SELECT status  FROM $table_name WHERE status = 'quoted' AND request_date BETWEEN '".$start."' AND '".$end."'  ";
$quoted_result = mySQL_query($quoted_query);
$quoted_num = mysql_num_rows($quoted_result);

$table_name = $_SESSION['db_prefix']."_quotations";
$accepted_query = "SELECT status  FROM $table_name WHERE status = 'accepted' AND request_date BETWEEN '".$start."' AND '".$end."'  ";
$accepted_result = mySQL_query($accepted_query);
$accepted_num = mysql_num_rows($accepted_result);

$table_name = $_SESSION['db_prefix']."_quotations";
$unsuccessful_query = "SELECT status  FROM $table_name WHERE status = 'unsuccessful' AND request_date BETWEEN '".$start."' AND '".$end."'  ";
$unsuccessful_result = mySQL_query($unsuccessful_query);
$unsuccessful_num = mysql_num_rows($unsuccessful_result);

$breakdownTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Enquiries:</td><td width=175>".$request_num."</td></tr><tr><td>Quoted:</td><td>".$quoted_num."</td></tr><tr><td>Accepted:</td><td>".$accepted_num."</td></tr><tr><td>Unsuccessful:</td><td>".$unsuccessful_num."</td></tr></table>";


?>
<!--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">
  <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": "485px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 8},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>

    <table width="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="385"><label class="label_page_head">Sales enquiries</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
 <div class="page_middle_frame">        
       <?php
$page='request_list.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
       
       <div align="right"><label class="label_end"><img src="../images/round_green.png" width="8" height="8" />: succes&nbsp;&nbsp;<img src="../images/round_red.png" width="8" height="8" />: unsuccessful&nbsp;&nbsp;<img src="../images/round_orange.png" width="8" height="8" />:quoted&nbsp;&nbsp;<img src="../images/round_purple.png" width="8" height="8" />:request</label></div>
        &nbsp;&nbsp;There are <a href=" " onMouseover="ddrivetip('<?php echo $breakdownTT ?>', 150)"; onMouseout="hideddrivetip()"><?php echo $quotation_num ?></a> enquiries in this list.
        <table width="678"  id="scroll_table" class="data_display" >
          <thead>
            <tr>
              <th width="18" align="center" >&nbsp;</th>
              <th width="68" >No</th>
              <th >Enq-Date</th>
              <th >Project </th>
              <th >Place</th>
              <th >Name</th>
              <th >Contact</th>
              <th >Sales<br />
                person</th>
              <th >&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;
$a7tot=0;
$dot='';
while ($i<$quotation_num) {
	$a1 = mysql_result($quotation_result, $i, "quote_no");
	
	
	     $a2 = mysql_result($quotation_result, $i, "cust_id");
		 
		 if ($a2!='0') {
	     $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);
         $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");
		 } 
		 else {
			 $a2a='';
		 }
		 
	
	
	$a5 = mysql_result($quotation_result, $i, "request_date");
	$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, "result");
	$a12 = mysql_result($quotation_result, $i, "project_no");
	$a13 = mysql_result($quotation_result, $i, "project_place");
	$a14 = mysql_result($quotation_result, $i, "project_area");
	$a15 = mysql_result($quotation_result, $i, "project");
	$a16 = mysql_result($quotation_result, $i, "value");
	
	
	$table_name = $_SESSION['db_prefix']."_quotations";
	$status_query = "SELECT status FROM $table_name WHERE quote_no = '".$a1."' ";
	$status_result = mySQL_query($status_query);
	$status_num = mysql_num_rows($status_result);
	if ($status_num==0) {
		  $dot='red';
	}
	else {
	  $status = mysql_result($status_result, 0, "status");
	  if ($status=='request') {
		  $dot='purple';
		}
	  if ($status=='quoted') {
		  $dot='orange';
		}
	 if ($status=='accepted') {
		  $dot='green';
		}
	 if ($status=='unsuccessful') {
		  $dot='red';
		}	
	}
	
	if ($status=='request') {	
	$quoteTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Quote no:</td><td width=175>".$a1."</td></tr><tr><td>Company:</td><td>".$a2a."</td></tr><tr><td>Project:</td><td>".$a15."</td></tr><tr><td>Value:</td><td>Not quoted yet</td></tr></table><br><b>Click to view enquiry</b>";
	} else {
	$quoteTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Quote no:</td><td width=175>".$a1."</td></tr><tr><td>Company:</td><td>".$a2a."</td></tr><tr><td>Project:</td><td>".$a15."</td></tr><tr><td>Value:</td><td>P ".$a16."</td></tr></table><br><b>Click to view quotation</b>";
	}
	
	//$productsTT ="<img src=../images/view.png  width=20 height=16><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>";
	
	$placeTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Plot no:</td><td width=175>".$a14.", ".$a13."</td></tr><tr><td>Place:</td><td>".$a13."</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  style="padding-left:0px;" align="center">
			  <?php if ($dot=='red') { ?><img src="../images/round_red.png" width="12" height="12"><?php } ?>
              <?php if ($dot=='orange') { ?><img src="../images/round_orange.png" width="12" height="12"><?php } ?>
              <?php if ($dot=='green') { ?><img src="../images/round_green.png" width="12" height="12"><?php } ?>
              <?php if ($dot=='purple') { ?><img src="../images/round_purple.png" width="12" height="12"><?php } ?>
              </td>
              <td  style="padding-left:0px;" align="left">
              <?php if ($status=='request') { ?>
              <a href="quotation_request.php?quote_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $quoteTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a>
              <?php } else { ?>
              <a href="quotation.php?quote_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $quoteTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a>
              <?php } ?>
			  </td>
              <td width="66" align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td width="105" align="left"><?php echo $a15 ?></td>
              <td width="89" align="left"><a href="quotation_request.php?quote_no=<?php echo $a1 ?>" onmouseover="ddrivetip('<?php echo $placeTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a13 ?></a></td>
              <td width="90" align="left"><a href="customer_details.php?cust_id=<?php echo $a2 ?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a ?></a></td>
              <td width="86" align="left"><?php echo $a9."<br>".$a10 ?>&nbsp;</td>
              <td width="79" align="left"><?php echo $a8 ?>&nbsp;</td>
              <td width="37" align="left"><?php echo $a5?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="10"; height="5">&nbsp;</td>
              
              </tr>
            </tfoot>
          </table>
          
        </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>