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

<?php
require_once("../include/tc_calendar.php");
	    
	$date = mysql_real_escape_string($_GET['date']);
		
	if ($date==1) {
	$start = mysql_real_escape_string($_GET['date1']);
    $end = mysql_real_escape_string($_GET['date2']);
	}
	else {
	
	$de=31;
	if (date("m")==2) {$de=28;}
	if ( (date("m")==4) OR (date("m")==6) OR (date("m")==9) OR (date("m")==11) ) {$de=30;}
	
	$start = date("Y-m-01");
	$end = date("Y-m-".$de);
	}
			
	if ($date!=1) {
	   $ds = "1"; }
	   else {
		$ds = date("d", strtotime($start) );
	   }
	$ms = date("m", strtotime($start) );
	$ys = date("Y", strtotime($start) );
	
	
	$de = date("d", strtotime($end) );
	$me = date("m", strtotime($end) );
	$ye = date("Y", strtotime($end) );	

	
$table_name2 = $_SESSION['db_prefix']."_quotations";
$table_name3 = $_SESSION['db_prefix']."_captured_jobs";
$success_query = "SELECT job_no, DATE, $table_name3.cust_id, $table_name3.project_no, $table_name3.project_place, $table_name3.value, company_contact, contact_phone, seller FROM $table_name3, $table_name2 WHERE date >= '".$start."' AND date <= '".$end."' AND quote_no=job_no ORDER BY DATE DESC";
$success_result = mySQL_query($success_query);
$success_num = mysql_num_rows($success_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> 
<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": [[ 2, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
                             	{"iDataSort": 9},
								{"iDataSort": 8},
								{"bSortable": true},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"iDataSort": 10},
								{"bSortable": true},
								{"bVisible": false},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
</head>
<body>
<?php include ('../include/tooltip.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">Successful jobs</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">
<form action="success_list.php" method="get" name="dateform" class="today" id="dateform">
    <table width="682"  id='table_calendar'>
      <tr>
        <td height="20" colspan="3" align="left" valign="middle"><label class="label_std">Select time period to display</label></td>
        <td valign="middle">&nbsp;</td>
        <td colspan="2" valign="middle"><input name="date" type="hidden" id="date" value="1" /></td>
        </tr>
      <tr>
        <td width="16" height="25" valign="middle">&nbsp;&nbsp; </td>
        <td width="53" valign="middle"><label class="label_std">  from:</label> </td>
        <td width="256" valign="middle"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
	 	$myCalendar->writeScript();?></td>
        <td width="26" valign="middle"><label class="label_std">to:</label></td>
        <td width="235" valign="middle"><?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
		$myCalendar->writeScript();?></td>
        <td width="68" valign="middle"><input name="button5" type="submit" class="linkbutton"  id="button5" value="Go" /></td>
        </tr>
    </table>
  </form>
</div>      

<div  class="page_middle_frame">
<div align="right"></div>
<table width="685" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th width="12" style="border-right-style:hidden;">&nbsp;</th>
    <th width="58" >Number</th>
    <th >Order Date</th>
    <th >Project</th>
    <th >Name</th>
    <th >Contact</th>
    <th >Value</th>
    <th >Seller</th>
    <th >&nbsp;</th>
    <th >&nbsp;</th>
    <th >&nbsp;</th>
    </tr>
   </thead>
<?php 
$i=0;

$a7tot=0;
$price=0;
while ($i<$success_num) {
	$a1 = mysql_result($success_result, $i, "job_no");
	
	
	     $a2 = mysql_result($success_result, $i, "cust_id");
	     $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");
			 
	
	
	$date = mysql_result($success_result, $i, "date");
	
	$a8 = mysql_result($success_result, $i, "seller");
	$a9 = mysql_result($success_result, $i, "company_contact");
	$a10 = mysql_result($success_result, $i, "contact_phone");
	$a11 = mysql_result($success_result, $i, "value");
	$a12 = mysql_result($success_result, $i, "project_no").' '.mysql_result($success_result, $i, "project_place");
	
	$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;
	$a7=0;
	$line_text="";
	$products=mysql_result($line_result, 0, "quote_item_text");
	$a7tot =$a7tot+$a11;	
		
	
	//$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 valign=top>Job accepted at:</td><td valign=top>P ".number_format($accept_value, 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 align="left" style="border-right-style:hidden; padding-right:0px" >J</td>
    <td align="left"  style="padding-left:0px;"><a href="quotation.php?quote_no=<?php echo $a1 ?> " onmouseover="ddrivetip('Click to view details', 150)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
    <td width="75" align="left"><?php echo date("d-m-Y", strtotime($date))?></td>
    <td width="112" align="left"><?php echo $a12 ?>&nbsp;</td>
    <td width="118" 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="102" align="left"><?php echo $a9."<br>".$a10 ?>&nbsp;</td>
    <td width="78" align="right"><?php echo number_format($a11, 2, '.', ',') ?></td>
    <td width="67" align="left"><?php echo $a8 ?>&nbsp;</td>
    <td width="23" align="left"><?php echo $date ?></td>
    <td width="23" align="left"><?php echo $a1 ?></td>
    <td width="23" align="left"><?php echo $a11 ?></td>
    </tr>
   <?php
  $i++;
}
?>
  <tfoot>
  <tr style="border-top-style:double;">
    <td colspan="5" align="left">&nbsp;</td>
    <td align="right">Total:</td>
    <td align="right"><?php echo number_format($a7tot, 2, '.', ',') ?></td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    </tr>
  </tfoot>
 
</table>
<div align="left"><label class="label_end">end of list</label></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>