<!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');
include('../include/period_select_date.php');	
	
	
$table_name2 = $_SESSION['db_prefix']."_tracking_store";
$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" />

<!--jscript-->

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

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

<?php include ('../include/tooltip.php'); ?>

<div class="main_frame">
<div class="page_head_frame">
        
        <table width="825" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="523"><label class="label_page_head">Stores tracking</label></td>
            <td width="287">&nbsp;</td>
          </tr>
        </table>
  </div>

<div class="page_middle_frame">	
  <?php
$page='tracking_stores.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": [[ 0, "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="371" >details</th>
    <th width="55" >&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 70:
        $action = 'New store item';
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a>';
        break;
    case 71:
        $action = 'Receive stock';
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$sup_name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$d2."' ";
		$sup_name_result = mySQL_query($sup_name_query);
		$sup_name = mysql_result($sup_name_result, 0, "account_name");
		
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'><b>'.$item_name.'</b></a> from <a href=../store/supplier_details.php?supplier_id='.$d2.'><b>'.$sup_name.'</b></a> on del note: <a href=../store/receive_note.php?receive_id='.$d3.'><b>'.$d4.'</b></a>';
        break;
  
	case 72:
        $action = 'Deliver job (store items)';
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		$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");
		
		$table_name = $_SESSION['db_prefix']."_supply_customer";
		$supply_query = "SELECT supply_id FROM $table_name WHERE delivery_note= '".$d3."' ";
		$supply_result = mySQL_query($supply_query);
		$supply_id = mysql_result($supply_result, 0, "supply_id");
		
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a> for <a href=../production/captured_job.php?job_no='.$d4.'>'.$d4.'</a> of: <a href=../sales/customer_details.php?cust_id='.$d2.'>'.$cust_name.'</a> del no:	<a href=../store/customer_supplied.php?del_note='.$d3.'&supply_id='.$supply_id.'&pr_option=copy>'.$d3.'</a>';
		
        break;
	case 73:
        $action = 'Cash sale';
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		$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");
		
		$table_name = $_SESSION['db_prefix']."_supply_customer";
		$supply_query = "SELECT supply_id FROM $table_name WHERE delivery_note= '".$d3."' ";
		$supply_result = mySQL_query($supply_query);
		$supply_id = mysql_result($supply_result, 0, "supply_id");
		
		if ($d4==0) {
			$job_link = 'cash to';
		}
		else {
			$job_link = 'cash on <a href=../production/captured_job.php?job_no='.$d4.'>'.$d4.'</a> of'; 
		}
		
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a> for '.$job_link.' <a href=../sales/customer_details.php?cust_id='.$d2.'>'.$cust_name.'</a> del no:	<a href=../store/customer_supplied.php?del_note='.$d3.'&supply_id='.$supply_id.'&pr_option=copy>'.$d3.'</a>';
				
        break;
	case 74:
        $action = 'Supply department';
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a> to '.$d2;
		
        break;
	case 75:
        $action = 'Supply employee';
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		$table_name = $_SESSION['db_prefix']."_employee";
		$emp_name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id= '".$d2."' ";
		$emp_name_result = mySQL_query($emp_name_query);
		$emp_name = mysql_result($emp_name_result, 0, "emp_first_name").' '.mysql_result($emp_name_result, 0, "emp_last_name");
		
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a> to <a href=../hr_module/employee-details.php?emp_id='.$d2.'>'.$emp_name;
		
        break;
	case 76:
        $action = 'New supplier';
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$sup_name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$d2."' ";
		$sup_name_result = mySQL_query($sup_name_query);
		$sup_name = mysql_result($sup_name_result, 0, "account_name");
		$details = '<a href=../store/supplier_details.php?supplier_id='.$d2.'>'.$sup_name.'</a>';
		
		
        break;
	case 77:
        $action = 'Stock count';
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		$details = '<b><a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a></b>, counted: <b>'.$d2.'</b>, difference: <b>'.$d3.'</b>';
		break;
	case 78:
        $action = 'Price adjustment';
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_num = mysql_num_rows($item_result);
		if ($item_num!=0)  {
		       $item_name = mysql_result($item_result, 0, "item_name");
			   $details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a> old:'.number_format($d3, 2, '.', ',').' new: '.number_format($d4, 2, '.', ',');
		}
		else {
			$item_name='something';
			if ($d3=='') {$d3=0;}
			$details = $d1.' old:'.number_format($d3, 2, '.', ',').' new: '.number_format($d4, 2, '.', ',');
	}
		break;
	case 79:
        $action = 'Receive special stock';
				
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$sup_name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$d2."' ";
		$sup_name_result = mySQL_query($sup_name_query);
		$sup_name = mysql_result($sup_name_result, 0, "account_name");
		
		$details = $d1.' from <a href=../store/supplier_details.php?supplier_id='.$d2.'>'.$sup_name.'</a> on del note: <a href=../store/receive_note.php?receive_id='.$d3.'>'.$d4.'</a>';
        break;
	case 80:
        $action = 'Edit supplier';
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "account_name");
		$details = '<b>'.$d4.'</b> for <b><a href=../store/supplier_details.php?supplier_id='.$d1.'>'.$name.'</a></b> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>';
		break;	
   case 81:
        $action = 'Edit store item';
		if ($d4=='Price') {
			$d2='P'.$d2;
			$d3='P'.number_format($d3, 2, '.', ',');
		}
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		
		$details = '<b>'.$d4.'</b> for <b><a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a></b> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>';
		break;	
	case 82:
        $action = 'Supply employee';
		$table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d2."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		
		$details = '<b><a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a></b> supplied to <b><a href=../hr_module/employee_details.php?emp_id='.$d2.'>'.$emp_name.'</a></b> . (supply note: <b><a href=../store/employee_supply.php?emp_supply_id='.$d3.'>'.$d3.'</a></b>)';
		break;
	case 83:
        $action = 'Register entry';
				$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."'  ";
				$name_result = mySQL_query($name_query);
				$item_name = mysql_result($name_result, 0, "item_name");			
		
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'><b>'.$item_name.'</b></a> were registered.';
		break;		
	case 84:
        $action = 'Supply job card';
		
		$table_name = $_SESSION['db_prefix']."_supply_job";
		$supply_job_no_query = "SELECT supply_job_no FROM $table_name WHERE job_card_no = '".$d2."'  ";
		$supply_job_no_result = mySQL_query($supply_job_no_query);
		$supply_job_no = mysql_result($supply_job_no_result, 0, "supply_job_no");
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$d1."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="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 = 'Job card <b><a href=../store/supply_job.php?job_card_no='.$d2.'&supply_job_no='.$supply_job_no.'>'.$d2.'</a></b> for <b>'.$cust_name.'</b> supplied to <b>'.$d3.'</b>';
		break;	
	case 85:
        $action = 'Purchase order';
		
		$table_name2 = $_SESSION['db_prefix']."_suppliers";
		$account_name_query = "SELECT account_name FROM $table_name2 WHERE supplier_id ='".$d2."' ";
		$account_name_result = mySQL_query($account_name_query);
		$account_name_num = mysql_num_rows($account_name_result);	
		$account_name = mysql_result($account_name_result, 0, "account_name");
		
		$table_name = $_SESSION['db_prefix']."_purchase";
		$purchase_query = "SELECT purchase_order FROM $table_name WHERE purchase_id = '".$d1."' ";
		$purchase_result = mySQL_query($purchase_query);
		$purchase_order = mysql_result($purchase_result, 0, "purchase_order"); 	
		
		$details = 'Purchase order <b><a href=../store/purchase_order.php?purchase_id='.$d1.'&message=0>'.$purchase_order.'</a></b> for <a href=../store/supplier_details.php?supplier_id='.$d2.'&message=0><b>'.$account_name.'</b></a>. Value: <b>P'.$d3.'</b> made by <b>'.$d4.'</b>';
		break;	
	case 86:
        $action = 'Purchase order authorisation';
		
		$table_name2 = $_SESSION['db_prefix']."_suppliers";
		$account_name_query = "SELECT account_name FROM $table_name2 WHERE supplier_id ='".$d2."' ";
		$account_name_result = mySQL_query($account_name_query);
		$account_name_num = mysql_num_rows($account_name_result);	
		$account_name = mysql_result($account_name_result, 0, "account_name"); 
		
		$table_name = $_SESSION['db_prefix']."_purchase";
		$purchase_query = "SELECT purchase_order FROM $table_name WHERE purchase_id = '".$d1."' ";
		$purchase_result = mySQL_query($purchase_query);
		$purchase_order = mysql_result($purchase_result, 0, "purchase_order"); 		
		
		$details = 'Purchase order <b><a href=../store/purchase_order.php?purchase_id='.$d1.'&message=0>'.$purchase_order.'</a></b> for <a href=../store/supplier_details.php?supplier_id='.$d2.'&message=0><b>'.$account_name.'</b></a> was authorised by <b>'.$d3.'</b>';
		break;
	case 87:
        $action = 'Additional supply';
		
		$table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id FROM $table_name WHERE job_card_no = '".$d2."' ";
		$job_result = mySQL_query($job_query);
		$job_num = mysql_num_rows($job_result);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="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 = 'Additional supply <a href=../store/additional_supply.php?additional_supply_no='.$d1.'&job_card_no='.$d2.'><b>'.$d1.'</b></a> for job card <b><a href=../orders/job_card.php?job_card_no='.$d2.'&job_supp>'.$d2.'</a></b> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>';
		break;
	case 88:
        $action = 'Return on job';
		
		$table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id FROM $table_name WHERE job_card_no = '".$d2."' ";
		$job_result = mySQL_query($job_query);
		$job_num = mysql_num_rows($job_result);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="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 = 'Return <b><a href=../store/job_return.php?job_return_no='.$d1.'&job_card_no='.$d2.'>'.$d1.'</b> for job card <b><a href=../orders/job_card.php?job_card_no='.$d2.'&job_supp>'.$d2.'</a></b> for <a href=../sales/customer_details.php?cust_id='.$cust_id.'><b>'.$cust_name.'</b></a>.';
		break;	
	case 89:
        $action = 'Supply M-works job card';
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$d1."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="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 = 'Job card <b><a href=../store/m_supply_job.php?job_card_no='.$d2.'&supply_job_no='.$d4.'>'.$d2.'</a></b> for <b>'.$cust_name.'</b> supplied to <b>'.$d3.'</b>';
		break;
	case 180:
        $action = 'Return from employee';
				
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		$table_name2 = $_SESSION['db_prefix']."_employee";
		$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$d2."' ";
		$employee_result = mySQL_query($employee_query);
		$employee_num = mysql_num_rows($employee_result);	
		$emp_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
				
		$details = '<a href=../store/store_item_display.php?store_item_id='.$d1.'><b>'.$item_name.'</b></a> was returned from <a href=../hr_module/employee_details.php?emp_id='.$d2.'><b>'.$emp_name.'</b></a> on supply note <a href=../store/employee_supply.php?emp_supply_id='.$d3.'><b>'.$d3.'</b></a>';
		break;		
	case 181:
        $action = 'Supply team';
				
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$item_name = mysql_result($item_result, 0, "item_name");
		
		
		$details = '<b><a href=../store/store_item_display.php?store_item_id='.$d1.'>'.$item_name.'</a></b> supplied to <b>'.$d2.'</a></b> . (team supply note: <b><a href=../store/employee_supply.php?emp_supply_id='.$d4.'>'.$d4.'</a></b>)';
		break;
	case 183:
        $action = 'Edit purchase order';
		$table_name = $_SESSION['db_prefix']."_purchase";
		$purchase_query = "SELECT purchase_order, supplier_id FROM $table_name WHERE purchase_id = '".$d1."' ";
		$purchase_result = mySQL_query($purchase_query);
		$purchase_num = mysql_num_rows($purchase_result);
		$purchase_order = mysql_result($purchase_result, 0, "purchase_order");
		$supplier_id = mysql_result($purchase_result, 0, "supplier_id");
			
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "account_name");
		
		$details = '<b>'.$d4.'</b> on order <b>'.$purchase_order.'</b> for <b><a href=../store/supplier_details.php?supplier_id='.$supplier_id.'>'.$name.'</a></b> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>';
		break;	
	case 184:
        $action = 'Edit purchase order';
		$table_name = $_SESSION['db_prefix']."_purchase";
		$purchase_query = "SELECT purchase_order, supplier_id FROM $table_name WHERE purchase_id = '".$d1."' ";
		$purchase_result = mySQL_query($purchase_query);
		$purchase_num = mysql_num_rows($purchase_result);
		$purchase_order = mysql_result($purchase_result, 0, "purchase_order");
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$d2."' ";
		$name_result = mySQL_query($name_query);
		$supplier_1 = mysql_result($name_result, 0, "account_name");
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$d3."' ";
		$name_result = mySQL_query($name_query);
		$supplier_2 = mysql_result($name_result, 0, "account_name");
				
		$details = '<b>'.$d4.'</b> on order <b>'.$purchase_order.'</b> changed from <b>'.$supplier_1.'</b> to <b>'.$supplier_2.'</b>';
		break;		
	case 185:
        $action = 'Edit purchase order';
		$table_name = $_SESSION['db_prefix']."_purchase";
		$purchase_query = "SELECT purchase_order, supplier_id FROM $table_name WHERE purchase_id = '".$d1."' ";
		$purchase_result = mySQL_query($purchase_query);
		$purchase_num = mysql_num_rows($purchase_result);
		$purchase_order = mysql_result($purchase_result, 0, "purchase_order");
		$supplier_id = mysql_result($purchase_result, 0, "supplier_id");
			
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "account_name");
		
		$details = '<b>'.$d4.'</b> on order <b>'.$purchase_order.'</b> for <b><a href=../store/supplier_details.php?supplier_id='.$supplier_id.'>'.$name.'</a></b> deleted';
		break;	
	case 186:
        $action = 'Edit purchase order';
		$table_name = $_SESSION['db_prefix']."_purchase";
		$purchase_query = "SELECT purchase_order, supplier_id FROM $table_name WHERE purchase_id = '".$d1."' ";
		$purchase_result = mySQL_query($purchase_query);
		$purchase_num = mysql_num_rows($purchase_result);
		$purchase_order = mysql_result($purchase_result, 0, "purchase_order");
		$supplier_id = mysql_result($purchase_result, 0, "supplier_id");
				
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "account_name");
		
		$details = '<b>'.$d4.'</b> on order <b>'.$purchase_order.'</b> for <b><a href=../store/supplier_details.php?supplier_id='.$supplier_id.'>'.$name.'</a></b> added';
		break;	
	case 187:
        $action = 'Status purchase order';
		$table_name = $_SESSION['db_prefix']."_purchase";
		$purchase_query = "SELECT purchase_order, supplier_id FROM $table_name WHERE purchase_id = '".$d1."' ";
		$purchase_result = mySQL_query($purchase_query);
		$purchase_num = mysql_num_rows($purchase_result);
		$purchase_order = mysql_result($purchase_result, 0, "purchase_order");
		$supplier_id = mysql_result($purchase_result, 0, "supplier_id");
			
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "account_name");
		
		$details = 'Status purchase order <b><a href=../store/purchase_order.php?purchase_id='.$d1.'&message=0>'.$purchase_order.'</a></b> for <b><a href=../store/supplier_details.php?supplier_id='.$supplier_id.'>'.$name.'</a></b> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>.';
		break;
	case 188:
        $action = 'Maintenance additional supply';
		
		$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
		$job_query = "SELECT cust_id FROM $table_name WHERE maintenance_card_no = '".$d2."' ";
		$job_result = mySQL_query($job_query);
		$job_num = mysql_num_rows($job_result);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="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 = 'Additional supply <b>'.$d1.'</b> for maintenance job card <b><a href=../store/supply_maintenance.php?maintenance_card_no='.$d2.'>'.$d2.'</a></b> for <b>'.$cust_name.'</b>.';
		break;			
	case 189:
        $action = 'Maintenance return';
		
		$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
		$job_query = "SELECT cust_id FROM $table_name WHERE maintenance_card_no = '".$d2."' ";
		$job_result = mySQL_query($job_query);
		$job_num = mysql_num_rows($job_result);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="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 = 'Return <b>'.$d1.'</b> from maintenance job card <b><a href=../store/supply_maintenance.php?maintenance_card_no='.$d2.'>'.$d2.'</a></b> for <b>'.$cust_name.'</b>.';
		break;
	case 190:
        $action = 'Edit receive note';
		$table_name = $_SESSION['db_prefix']."_receive_store";
		$receive_query = "SELECT delivery_note, supplier_id FROM $table_name WHERE receive_id = '".$d1."' ";
		$receive_result = mySQL_query($receive_query);
		$receive_num = mysql_num_rows($receive_result);
		$delivery_note = mysql_result($receive_result, 0, "delivery_note");
		$supplier_id = mysql_result($receive_result, 0, "supplier_id");
			
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "account_name");
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d4."'  ";
		$name_result = mySQL_query($name_query);
		$item_name = mysql_result($name_result, 0, "item_name");
		
		$details = 'Quantity on receive note for delivery no <b><a href=../store/receive_note.php?receive_id='.$d1.'>'.$delivery_note.'</b> from <b><a href=../store/supplier_details.php?supplier_id='.$supplier_id.'>'.$name.'</a></b> for<b> '.$item_name.'</b> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>';
		break;	
	case 191:
        $action = 'Edit receive note';
		$table_name = $_SESSION['db_prefix']."_receive_store";
		$receive_query = "SELECT delivery_note, supplier_id FROM $table_name WHERE receive_id = '".$d1."' ";
		$receive_result = mySQL_query($receive_query);
		$receive_num = mysql_num_rows($receive_result);
		$delivery_note = mysql_result($receive_result, 0, "delivery_note");
		$supplier_id = mysql_result($receive_result, 0, "supplier_id");
			
		
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
		$name_result = mySQL_query($name_query);
		$name = mysql_result($name_result, 0, "account_name");
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$d4."'  ";
		$name_result = mySQL_query($name_query);
		$item_name = mysql_result($name_result, 0, "item_name");
		
		$details = 'Price on receive note for delivery no <b><a href=../store/receive_note.php?receive_id='.$d1.'>'.$delivery_note.'</b> from <b><a href=../store/supplier_details.php?supplier_id='.$supplier_id.'>'.$name.'</a></b> for<b> '.$item_name.'</b> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>';
		break;	
	case 192:
        $action = 'Direct return';
		
		$table_name = $_SESSION['db_prefix']."_direct_return";
		$return_query = "SELECT return_from, returned_by FROM $table_name WHERE direct_return_no = '".$d1."' ";
		$return_result = mySQL_query($return_query);
		$return_from = mysql_result($return_result, 0, "return_from");
		$returned_by = mysql_result($return_result, 0, "returned_by");
		
		//$table_name = $_SESSION['db_prefix']."_direct_return_lines";
//		$item_query = "SELECT store_item_id, item_name FROM $table_name WHERE direct_return_no = '".$d2."' ";
//		$item_result = mySQL_query($item_query);
//		$return_from = mysql_result($item_result, 0, "return_from");
//		$returned_by = mysql_result($item_result, 0, "returned_by");
 			
		
		$details = 'Direct return <b><a href=../store/direct_return.php?direct_return_no='.$d1.'>'.$d1.'</a></b> from '.$d2.' by '.$returned_by.'.';
		break;																
}
	
	?>
  
  
  <tr>
    <td width="54" align="left"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="38" align="left"><?php echo date("H:i", strtotime($b1 ))  ?></td>
    <td width="50" align="left"><?php echo $b2 ?></td>
    <td width="87" 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>