<!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" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "AD-tracking";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");

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



$table_name2 = $_SESSION['db_prefix']."_tracking_sales";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date BETWEEN '".$start."' AND '".date('Y-m-d', strtotime(date("Y-m-d", strtotime($end))." +1 day"))."' ORDER BY action_id DESC ";
$tracking_result = mySQL_query($tracking_query);
$tracking_num = mysql_num_rows($tracking_result);


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

<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></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": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 5, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
</head>

<body>
<div class="main_frame" style="height:auto;">
<div  class="page_head_frame"> <label class="label_page_head">Sales tracking</label></td>
</div>
        <br />
<br />
<br />
<br />

<?php
$page='tracking_sales.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>

<div  class="page_middle_frame">
<table width="683" id="scroll_table" class="data_display">
  <thead>
  <tr>
    <th>date</th>
    <th >time</th>
    <th>user</th>
    <th>action</th>
    <th width="322">details</th>
    <th width="51">&nbsp;</th>
    </tr>
   </thead>
<?php 

$i=0;

while ($i<$tracking_num) {
    $b0  =  mysql_result($tracking_result, $i, "action_id");
	$b1 =  mysql_result($tracking_result, $i, "entry_date");
	$b2 =  mysql_result($tracking_result, $i, "user");
	$b3 =  mysql_result($tracking_result, $i, "action");
	$d1 = mysql_result($tracking_result, $i, "details_1");
	$d2 = mysql_result($tracking_result, $i, "details_2");
	$d3 = mysql_result($tracking_result, $i, "details_3");
	$d4 = mysql_result($tracking_result, $i, "details_4");
	
	
	$action='';
	$details='';
	switch ($b3) {
    case 40:
        $action = 'New quotation Tiles & Acc';
		
		 		$table_name2 = $_SESSION['db_prefix']."_customer";
				$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$d2."' ";
				$customer_result = mySQL_query($customer_query);
				$customer_num = mysql_num_rows($customer_result);	
				$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				} 
		
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> ('.$d4.') for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a>';
        break;
    case 41:
        $action = 'Quotation successfull';
		        $table_name2 = $_SESSION['db_prefix']."_customer";
				$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$d2."' ";
				$customer_result = mySQL_query($customer_query);
				$customer_num = mysql_num_rows($customer_result);	
				$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
		
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> ('.$d4.') for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> was set successful'; 
		break;
    case 42:
        $action = 'Note entry quotation';
		        $table_name2 = $_SESSION['db_prefix']."_customer";
				$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$d2."' ";
				$customer_result = mySQL_query($customer_query);
				$customer_num = mysql_num_rows($customer_result);	
				$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
		
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'&authorise=0><b>Q'.$d1.'</b></a> ('.$d4.') for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> '.$d3;
        break;
	case 43:
        $action = 'Order placed';
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d2."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		
		$details = 'Order <a href=../sales/tile_order_display.php?order_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> placed with Radstone';
        break;
	
	case 45:
        $action = 'Edit customer';
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d1."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		
		$details = $d4.' for <a href=../sales/customer_details.php?cust_id='.$d1.'><b>'.$cust_name.'</b></a> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>' ;
        break;
			
	case 46:
        $action = 'Edit install quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_query = "SELECT  cust_id  FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
				
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
		
		$details = '<b>'.$d4.'</b> on install quote <a href=../sales/quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> changed from <b>'.$d2. '</b> to <b>'.$d3.'</b>';
        break;
		
	case 47:
        $action = 'Edit tile quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_query = "SELECT  cust_id  FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
				
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d2."'  ";
		$name_result = mySQL_query($name_query);
		$d2a = mysql_result($name_result, 0, "item_name");	
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d3."'  ";
		$name_result = mySQL_query($name_query);
		$d3a = mysql_result($name_result, 0, "item_name");	
		
		$details = '<b>'.$d4.'</b> on tiles quote <a href=../sales/quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> changed from <b>'.$d2a. '</b> to <b>'.$d3a.'</b>';
        break;
		
	case 48:
        $action = 'Edit tile quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_query = "SELECT  cust_id  FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
				
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
		
				
		$details = '<b>'.$d4.'</b> on tiles quote <a href=../sales/quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> changed from <b>'.$d2. '</b> to <b>'.$d3.'</b>';
        break;		
		
		case 49:
        $action = 'Edit final quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_query = "SELECT  cust_id  FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
				
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
		
				
		$details = '<b>'.$d4.'</b> on tiles quote <a href=../sales/quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> changed from <b>'.$d2. '</b> to <b>'.$d3.'</b>';
        break;	
		
	case 50:
        $action = 'Add product to quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_query = "SELECT  cust_id  FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
				
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
		
				
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d2."'  ";
		$name_result = mySQL_query($name_query);
		$d2a = mysql_result($name_result, 0, "item_name");	
		
		$details = '<b>'.$d4.' '.$d2a.'</b> were added to tiles quote <a href=../sales/quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> ';
        break;				
			
		case 51:
        $action = 'Delete product from quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_query = "SELECT  cust_id  FROM $table_name WHERE quote_no = '".$d1."' ";
		$quote_result = mySQL_query($quote_query);
		$cust_id = mysql_result($quote_result, 0, "cust_id");
				
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT account_type, title, name_2, comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$account_type = mysql_result($customer_result, 0, "account_type");
				if ($account_type=="corporate") { 
					$cust_name = mysql_result($customer_result, 0, "comp_name"); 
				} 
				else {
					$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 				}
				
		$details = '<b>'.$d4.'</b> deleted from tiles quotation <a href=../sales/quotation.php?quote_no='.$d1.'><b>'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a> ';
        break;
		
		case 55:
        $action = 'Edit book order no';
		//$table_name = $_SESSION['db_prefix']."_tile_orders";
//		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$d1."' ";
//		$cust_name_result = mySQL_query($cust_name_query);
//		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		
		$details = 'Book order no on Job no <a href=../sales/tile_order_display.php?order_no='.$d1.'><b>'.$d1.'</b></a> has been changed from '.$d2.' to '.$d3.'.' ;
        break;			
}
	
	?>
  
  
  <tr>
    <td width="67" align="left"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="57" align="left"><?php echo date("H:i", strtotime($b1 ))  ?></td>
    <td width="64" align="left"><?php echo $b2 ?></td>
    <td width="94" align="left"><?php echo $action ?></td>
    <td align="left"><?php echo $details ?></td>
    <td align="left"><?php echo $b1?></td>
    </tr>
  <?php
  $i++;
}
?>

</table>
</div>

</div>
</body>
<?php } else {
$_SESSION['denied_return'] = "admin_module/user_list.php";	
    include ("../navigation/admin_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</html>