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

$today = date("Y-m-d");
$yesterday = strtotime(date("Y-m-d", strtotime($today)) . " -1 day");
$period = $_GET['period'];
$seller = $_GET['seller_select'];

$table_name = $_SESSION['db_prefix']."_quotations";
$red_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date < '".date("Y-m-d", strtotime(date("Y-m-d", strtotime($today)) . " -3 day"))."' ORDER BY quote_no DESC ";
$red_result = mySQL_query($red_query);
$red_num = mysql_num_rows($red_result);


$table_name = $_SESSION['db_prefix']."_quotations";
$orange_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date < '".$today."' AND check_date >='".date("Y-m-d", strtotime(date("Y-m-d", strtotime($today)) . " -3 day"))."' ORDER BY quote_no DESC ";
$orange_result = mySQL_query($orange_query);
$orange_num = mysql_num_rows($orange_result);


$table_name = $_SESSION['db_prefix']."_quotations";
$green_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date = '".$today."' ORDER BY quote_no DESC ";
$green_result = mySQL_query($green_query);
$green_num = mysql_num_rows($green_result);


$table_name = $_SESSION['db_prefix']."_quotations";
$green2_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date > '".$today."' ORDER BY quote_no DESC ";
$green2_result = mySQL_query($green2_query);
$green2_num = mysql_num_rows($green2_result);


if ($seller=='All') {	
$table_name = $_SESSION['db_prefix']."_quotations";
if ($period=='red') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date < '".date("Y-m-d", strtotime(date("Y-m-d", strtotime($today)) . " -3 day"))."' ORDER BY quote_no DESC ";
}
if ($period=='orange') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date < '".$today."' AND check_date >='".date("Y-m-d", strtotime(date("Y-m-d", strtotime($today)) . " -3 day"))."' ORDER BY quote_no DESC ";
}
if ($period=='green') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date = '".$today."' ORDER BY quote_no DESC ";
}
if ($period=='green2') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date > '".$today."' ORDER BY quote_no DESC ";
}
}
else {
$table_name = $_SESSION['db_prefix']."_quotations";
if ($period=='red') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date < '".date("Y-m-d", strtotime(date("Y-m-d", strtotime($today)) . " -3 day"))."' AND seller = '".$seller."' ORDER BY quote_no DESC ";
}
if ($period=='orange') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date < '".$today."' AND check_date >='".date("Y-m-d", strtotime(date("Y-m-d", strtotime($today)) . " -3 day"))."' AND seller = '".$seller."'  ORDER BY quote_no DESC ";
}
if ($period=='green') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date = '".$today."'  AND seller = '".$seller."'  ORDER BY quote_no DESC ";
}
if ($period=='green2') {
$quote_query = "SELECT quote_no, cust_id, required_date, quote_type, project_no, project_place, project_description, `value`, designer, seller, check_date FROM $table_name WHERE  status = 'quoted' AND check_date > '".$today."'  AND seller = '".$seller."'  ORDER BY quote_no DESC ";
}
}
$quote_result = mySQL_query($quote_query);
$quote_num = mysql_num_rows($quote_result);


$table_name = $_SESSION['db_prefix']."_list_sellers";
$suppliersQuery = "SELECT item_name FROM $table_name  ORDER BY item_name ASC";
	$suppliersResult = execsql($suppliersQuery);
	$suppliersNum = mysql_num_rows($suppliersResult);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $suppliersNum) {
		$arrId2[$w] = mysql_result($suppliersResult, $w, "item_name");
		$arrName2[$w] = mysql_result($suppliersResult, $w, "item_name");
		$w++;
	}
?>

<!--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> 
<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": [[ 6, <?php if (($period=='red') OR ($period=='orange')) { ?> "desc" <?php } else { ?> "asc" <?php } ?> ]],
					"aoColumns": [
								{"bSortable": false},
								{"iDataSort": 8},
								{"bSortable": true},
								{"iDataSort": 9},
								{"iDataSort": 10},
								{"bSortable": true},
								{"iDataSort": 11},
								{"bSortable": true},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false}								
								 ]
				} );
			} );
		</script>

</head>
<body>

<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">Follow up quotations</label></td>
              <td width="253">&nbsp;</td>
              <td width="171" align="right">&nbsp;</td>
            </tr>
          </table>
        </div>
        
        <div class="page_middle_frame">
        <form action="" method="get" name="dateform" class="today" id="dateform">
         
<div style="width:700px;">
  <div style="float:left; width:200px; text-align:center; "> <<<< </div>
<div style="float:left; width:100px; text-align:center; "> 3 days << </div>
<div style="float:left; width:100px; text-align:center; "> <?php echo date("d-m-Y", strtotime($today)) ?> </div>
<div style="float:left; width:200px; text-align:center; "> >>>> </div>
<div style="float:left; width:100px; text-align:center; "> sales rep </div>

<div style="float:left; width:200px; height:25px; text-align:center; padding-top:5px; background-color:#F33; color:#FFF;">
<a href="follow_up_list.php?period=red&seller_select=<?php echo $seller ?>" onMouseover="ddrivetip(document.getElementById('seller_text').value, 150)"; onMouseout="hideddrivetip()"><?php echo $red_num ?></a>

</div>
<div style="float:left; width:100px; height:25px; text-align:center; padding-top:5px; padding-top:5px; background-color:#F90; color:#FFF;"><a href="follow_up_list.php?period=orange&seller_select=<?php echo $seller ?>" onMouseover="ddrivetip('Display these records', 150)"; onMouseout="hideddrivetip()"><?php echo $orange_num ?></a></div>
<div style="float:left; width:100px; height:25px; text-align:center; padding-top:5px; background-color:#390; color:#FFF;"><a href="follow_up_list.php?period=green&seller_select=<?php echo $seller ?>" onMouseover="ddrivetip('Display these records', 150)"; onMouseout="hideddrivetip()"><?php echo $green_num ?></a></div>
<div style="float:left; width:200px; height:25px; text-align:center; padding-top:5px; background-color:#3C0; color:#FFF;"><a href="follow_up_list.php?period=green2&seller_select=<?php echo $seller ?>" onMouseover="ddrivetip('Display these records', 150)"; onMouseout="hideddrivetip()"><?php echo $green2_num ?></a></div>
<div style="float:left; width:100px; height:25px; text-align:center; padding-top:5px; background-color:inherit;">

  <select name="seller_select" id="seller_select" class="select80" onchange="window.location.href= this.form.seller_select.options[this.form.seller_select.selectedIndex].value">
    <option value="<?php echo $seller ?>" selected="selected"><?php echo $seller ?></option>
    <option value="<?php echo 'follow_up_list.php?seller_select=All&period='.$period ?>">All</option>
    <?php 
    	for ($w = 0; $w < count($arrId2); $w++) {
	?>	<option value="<?php echo 'follow_up_list.php?seller_select='.$arrId2[$w].'&period='.$period ?>"><?php echo $arrName2[$w]?></option>
    <?php
	    }
     ?>
  </select>
</div>
</div></form>
        
        
        <div  class="page_middle_frame" style="width:650px;">
          <div align="left"><img src="../images/round_blue.png" alt="" width="8" height="8" />=project&nbsp;&nbsp;<img src="../images/round_purple.png" alt="" width="8" height="8" />=cash sale</div>
          <div style="width:650px; height:350px;">
          <table width="650" id="scroll_table" class="data_display">
         <thead>
            <tr>
              <th width="44" style="border-right:hidden;">&nbsp;</th>
              <th width="56">Quote no</th>
              <th width="94">Customer</th>
              <th width="52">Value</th>
              <th width="48">Due date:</th>
              <th width="53">Sales rep</th>
              <th width="72" <?php if ($period=='red') { $color="#FF0000";}
              				       if ($period=='orange') { $color="#FF9900";}
								   if ($period=='green') { $color="#390";}
								   if ($period=='green2') { $color="#3C0";} ?> bgcolor="<?php echo $color ?>" >Check date</th>
              <th width="22">&nbsp;</th>
              <th width="39">&nbsp;</th>
              <th width="38">&nbsp;</th>
              <th width="38">&nbsp;</th>
              <th width="42">&nbsp;</th>
            </tr>
          </thead>
            <?php 
	$i=0;
	while ($i<$quote_num) {
		$a1 = mysql_result($quote_result, $i, "quote_no");
		$a2 = mysql_result($quote_result, $i, "cust_id");
			$table_name = $_SESSION['db_prefix']."_customer";
			$customer_query = "SELECT status, comp_name, bag_box, box_no, postal_place, phone, contact_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) {
			$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");
			$a2g = mysql_result($customer_result, 0, "status");
			}
			
		 $a3 = mysql_result($quote_result, $i, "required_date");
		 $a4 = mysql_result($quote_result, $i, "project_no");
		 $a5 = mysql_result($quote_result, $i, "project_place");
		 $a6 = mysql_result($quote_result, $i, "project_description");
		 $a7 = mysql_result($quote_result, $i, "value");
		 $a8 = mysql_result($quote_result, $i, "designer");
		 $a9 = mysql_result($quote_result, $i, "seller");
		 $a14 = mysql_result($quote_result, $i, "quote_type");
		 $a15 = mysql_result($quote_result, $i, "check_date");
		 
		
		$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>";
		
		$jobTT ="<table id=table_tool_tip width=300 ><tr><td  width=100>Quote no:</td><td width=175>".$a1."</td></tr><tr><td valign=top>Project no /place:</td><td>".$a4."&nbsp;".$a5."</td></tr><tr><td>Project description:</td><td>".$a6."</td></tr><tr><td>Designer:</td><td>".$a8."</td></tr><tr><td>Sales assistant:</td><td>".$a9."</td></tr><td>Value:</td><td>".$a7."</td></tr></table><br><b>Click for details</b>";	
	?>
            <tr>
              <td align="right" style="border-right-style:hidden; padding-right:0px;"><?php if ($a14=='Project') { ?>
                <img src="../images/round_blue.png" alt="" width="8" height="8" />
                <?php } ?>
                <?php if ($a14=='Cash sale') { ?>
                <img src="../images/round_purple.png" alt="" width="8" height="8" />
                <?php } ?>
                Q</td>
              <td style="padding-left:0px"><a href="quotation.php?quote_no=<?php echo $a1?>" onmouseover="ddrivetip('<?php echo $jobTT ?>', 300)"; onmouseout="hideddrivetip()" onclick="needToConfirm = false; MM_showHideLayers('wait','','show');"><?php echo $a1?></a></td>
              <td><a href="" onmouseover="ddrivetip('<?php echo $customerTT ?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a?></a></td>
              <td align="right"><?php echo number_format($a7, 2, '.', ',') ?>&nbsp;</td>
              <td><?php if ($a3!='0000-00-00') { echo date("d-m-Y", strtotime($a3)); } ?>
                &nbsp;</td>
              <td><?php echo $a9 ?></td>
              <td><?php if (($a15!='0000-00-00') AND ($a15!='')) { if ($a15<$today) {?> <font color="#FF0000"> <?php echo date("d-m-Y", strtotime($a15)); ?> </font> <?php } else { echo date("d-m-Y", strtotime($a15)); }  } ?></td>
              <td align="center"><a href="quote_updateWizbase.php?quote_no=<?php echo $a1?>&cust_id=<?php echo $a2 ?>&p=2&s=1" onmouseover="ddrivetip('Click to edit status', 100)"; onmouseout="hideddrivetip()" onclick="needToConfirm = false; MM_showHideLayers('wait','','show');"><img src="../images/document_edit.png" width="16" height="16" /></a></td>
              <td><a href="quote_updateWizbase.php?quote_no=<?php echo $a1?>&amp;cust_id=<?php echo $a2 ?>&amp;p=2&amp;s=1" onmouseover="ddrivetip('<?php echo $jobTT ?>', 300)"; onmouseout="hideddrivetip()" onclick="needToConfirm = false; MM_showHideLayers('wait','','show');"><?php echo $a1?></a></td>
              <td><?php echo $a7 ?></td>
              <td><?php echo $a3 ?></td>
              <td><?php echo $a15 ?></td>
            </tr>
            <?php 
	$i++;
	}
	?>
          </table>
          </div>
        </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>