<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

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

<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_production";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date >= '".$start."' AND entry_date <= '".$end."' ";
$tracking_result = mySQL_query($tracking_query);
$tracking_num = mysql_num_rows($tracking_result);
?>

</head>

<body>
<?php 
include ("../navigation/header.php");
$page_name = "AD-tracking";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
include('../include/tooltip.php');?>
<div class="main_frame">
  <div class="page_head_frame">
     <label class="label_page_head">Production tracking</label></td>
  </div>
        <br />
<br />
<br />
<br />
<div class="page_middle_frame">
<?php
$page='tracking_production.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
<div class="page_inside_frame">
<!--jscript-->
<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="659" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th>date</th>
    <th>time</th>
    <th>user</th>
    <th>action</th>
    <th>details</th>
    <th>&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 100:
	    $action = 'Order compiled';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$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='M-works job card no <a href="../production/m_job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$d2.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> compiled.';
        break;
		
	case 91:
	    $action = 'Order delivered';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$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='Job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$d2.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> delivered.';
        break;	
		
	case 102:
	    $action = 'Job produced';
        $table_name = $_SESSION['db_prefix']."_mworks_jobs";
		$job_query = "SELECT cust_id FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$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='M-works job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$d2.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> produced and inspected by <b>'.$d3.'</b>';
        break;	
		
	case 93:
	    $action = 'Job invoiced';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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='Job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$project.'</b></a> for '.$d2.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> invoiced by <b>'.$d3.'</b>, invoice no: <b>'.$d4.'</b>.';
        break;		
		
	case 103:
	    $action = 'Mworks job completed';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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='M-works job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$d2.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> completed by <b>'.$d3.'</b>.';
        break;	
		
		case 96:
	    $action = 'Job planning edited';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$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");
 			}
			
		if ($d4!='Foreman') {	
		$details=$d4.' on job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> changed from <b>'.date("d-m-Y", strtotime($d2)).'</b> to <b>'.date("d-m-Y", strtotime($d3)).'</b>.';
		}
		
		if ($d4=='Foreman') {
		$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);	
		$name1 = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name");
		
		$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$d3."' ";
		$employee_result = mySQL_query($employee_query);
		$employee_num = mysql_num_rows($employee_result);	
		$name2 = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name");
		 	
		$details=$d4.' on job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> changed from <b>'.$name1.'</b> to <b>'.$name2.'</b>.';
		}	
		
        break;		
	
				
		case 105:
	    $action = 'Jod edited';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project, forman FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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");
				
		
		$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='Qty for '.$item_name.' on job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> has been changed from <b>'.$d2.'</b> to <b> '.$d3.'</b>.';
        break;			
	
	    case 106:
	    $action = 'Jod edited';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project, forman FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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);
		$name_num = mysql_num_rows($name_result);
		if ($name_num!=0) {
		      $item_name = mysql_result($name_result, 0, "item_name");
		}
		else {
			$item_name = 'Special order';
		}
				
		
		$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=$item_name.' on job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> has been deleted';
        break;	
		
		case 107:
	    $action = 'Jod edited';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project, forman FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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");
				
		
		$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=$item_name.' on job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> has been added with a quantity of <b>'.$d3.'</b>.';
        break;
		case 109:
        $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 = 'M-works job card '.$d4.' for <a href=../sales/customer_details.php?cust_id='.$d2.'><b>'.$cust_name.'</b></a> was voided';
        break;	
		
		case 108:
	    $action = 'Job edited';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project, forman FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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=$d4.' on job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'" ><b> '.$cust_name.'</b></a> has been changed from <b>'.$d2.'</b> to <b> '.$d3.'</b>.';
        break;	
		
		case 110:
	    $action = 'Job edited';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project, forman FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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='New item <b>'.$d2.'</b> has been added on job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'"><b> '.$cust_name.'</b></a>, quantity <b>'.$d3.'</b>.';
        break;	
		
		case 111:
	    $action = 'Job edited';
        $table_name = $_SESSION['db_prefix']."_compiled_jobs";
		$job_query = "SELECT cust_id, project, forman FROM $table_name WHERE job_card_no = '".$d1."' ";
		$job_result = mySQL_query($job_query);
		$cust_id = mysql_result($job_result, 0, "cust_id");
		$project = mysql_result($job_result, 0, "project");
		
		$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='Item <b>'.$d2.'</b> has been deleted from job card no <a href="../orders/job_card.php?job_card_no='.$d1.'"> <b>'.$d1.'</b></a> for '.$project.' for <a href="../sales/customer_details.php?cust_id='.$cust_id.'"><b> '.$cust_name.'</b></a>, quantity <b>'.$d3.'</b>.';
        break;			
}
?>

  <tr>
    <td width="66" align="left"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="46" align="left"><?php echo date("H:i", strtotime($b1 ))  ?></td>
    <td width="49" align="left"><?php echo $b2 ?></td>
    <td width="71" align="left"><?php echo $action ?></td>
    <td width="376" align="left"><?php echo $details ?></td>
    <td width="23" align="left"><?php echo $b1 ?></td>
    </tr>
  <?php
  $i++;
}
?>

</table>
</div>
</div>
</div>

<?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'); ?>
</body>
</html>