<!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('../include/session.php');
?>
<?php

include('../include/period_select_date.php');	
	
	
$table_name2 = $_SESSION['db_prefix']."_tracking_sales";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date >= '".$start."' AND entry_date <= '".$end."' 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" />

</head>

<body>
<?php
include ("../navigation/header.php");
$page_name = "AD-tracking";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<div class="main_frame" style="height:auto;">
<div  class="page_head_frame"> <label class="label_page_head">Sales tracking</label></td>
</div>
       

<div class="page_middle_frame" >	
  <?php
$page='tracking_sales.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
  
<div  class="page_inside_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": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 5, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
<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_name");
	$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 50:
        $action = 'Request quotation';
		
		$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_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = '<a href=../sales/quotation_request.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> for <b>'.$d3.'</b>';
        break;
    case 51:
        $action = 'Capture quotation';
		$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_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> for <b>'.$d3.'</b>';
        break;
    case 52:
        $action = 'Note entry quotation';
		$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_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num!=0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> '.$d3;
        break;
	case 53:
        $action = 'Accept quotation';
		$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 = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> '.$d3.', job card no: <b>'.$d4.'</b>';
        break;
	case 54:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, option <b>'.$d2.'</b> changed from <b>'.number_format($d3, 2, '.', ','). '</b> to <b>'.number_format($d4, 2, '.', ',').'</b>';
        break;
	case 55:
        $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 56:
        $action = 'New customer';
		$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_num = mysql_num_rows($cust_name_result);
		if ($cust_name_num>0) {
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		}
		else {
			$cust_name='';
		}
		
		$details = '<a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a>' ;
        break;		
	case 57:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, '.$d2.'  changed from <b>'.$d3.'</b> to <b>'.$d4.'</b>';
        break;	
		case 58:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, option <b>'.$d4.'</b> was changed from <b>'.$d3. '</b>';
        break;	
		case 59:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, date was changed from <b>'.date("d-m-Y", strtotime($d3)). '</b> to <b>'.date("d-m-Y", strtotime($d4)).'</b>';
        break;	
		case 60:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, terms were changed from <b>'.$d3.'</b> to <b>'.$d4.'</b>';
        break;
		case 61:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, VAT was changed from <b>'.$d3.'</b> to <b>'.$d4.'</b>';
        break;
		case 62:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, validity was changed from <b>'.$d3.'</b> days to <b>'.$d4.'</b> days';
        break;
		case 63:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, delivery period was changed from <b>'.$d3.'</b> days to <b>'.$d4.'</b> days';
        break;
		case 64:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, price for <b>'.$d2.'</b> was changed from <b>P'.$d3.'</b>  to <b>P'.$d4.'</b>';
        break;
		case 65:
        $action = 'Edit quotation';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' LIMIT 1 ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		$details = '<a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, description for <b>'.$d2.'</b> was changed from <b>'.$d3.'</b>  to <b>'.$d4.'</b>';
        break;	
		case 66:
        $action = 'Bill of quantity';
		$details = '<a href=../sales/qbill.php?quote_no='.$d1.'><b>'.$d1.'</b></a> <b>'.$d3.'</b> for <b>'.$d4.'</b>, amount: <b>P'.number_format($d2, 2, '.', ',').'</b>';
        break;	
		case 67:
        $action = 'Edit enquiry';
		$table_name = $_SESSION['db_prefix']."_quotations";
		$quote_name_query = "SELECT cust_id FROM $table_name WHERE quote_no= '".$d1."' ";
		$quote_name_result = mySQL_query($quote_name_query);
		$cust_id = mysql_result($quote_name_result, 0, "cust_id");		
		$table_name = $_SESSION['db_prefix']."_customer";
		$cust_name_query = "SELECT comp_name FROM $table_name WHERE cust_id= '".$cust_id."' ";
		$cust_name_result = mySQL_query($cust_name_query);
		$cust_name = mysql_result($cust_name_result, 0, "comp_name");
		
		$details = '<a href=../sales/quotation_request.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>, option <b>'.$d4.'</b> changed from <b>'.$d2. '</b> to <b>'.$d3.'</b>';
        break;
		case 68:
        $action = 'Void job';
		$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 = 'On <a href=../sales/quotation.php?quote_no='.$d1.'><b>Q'.$d1.'</b></a> for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> job card no: <b>'.$d4.'</b> was voided';
        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>
</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>