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

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<?php
	
$table_name2 = $_SESSION['db_prefix']."_tracking_production";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date >= '".$start."' AND entry_date <= ('".$end."'+ INTERVAL 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": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
</head>

<body>


<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">Production tracking</label></td>
            <td width="287">&nbsp;</td>
          </tr>
        </table>
  </div>
        <br />
<br />

<div class="page_middle_frame">	
<?php
$page='tracking_production.php';
$reference_name='';
$reference='';
$reference_name_2='';
$reference_2='';
$reference_name_3='';
$reference_3='';
include('../include/period_select_block_small.php');
?>
</div>


<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="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 60: 
		$action = 'Production plan';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE production_no='".$d2."'  ";
		$production_result = mySQL_query($production_query);
		$production_num = mysql_num_rows($production_result);
		if ($production_num!=0) {
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		}
		else {
			$mix_design_name = 'canceled';
		}
		
		
     	$details = 'Production plan no <a href=../production/day_production_display.php?production_date='.$d1.'&production_no='.$d2.'><b>'.$d2.'</b></a> on '.date("d-m-Y", strtotime($d1)).': '.$mix_design_name.'.';
        break;
	case 61:
		$action = 'Wet count';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE production_no='".$d2."'  ";
		$production_result = mySQL_query($production_query);
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		
     	$details = 'Production plan no <a href=../production/day_production_display.php?production_date='.$d1.'&production_no='.$d2.'><b>'.$d2.'</b></a> on '.date("d-m-Y", strtotime($d1)).': '.$mix_design_name.'.<br> Skips: '.$d3.'. Wet count: '.$d4.'.';
        break;	
	case 62:
		$action = 'Dry count';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE production_no='".$d2."'  ";
		$production_result = mySQL_query($production_query);
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		
     	$details = 'Production plan no <a href=../production/day_production_display.php?production_date='.$d1.'&production_no='.$d2.'><b>'.$d2.'</b></a> on '.date("d-m-Y", strtotime($d1)).': '.$mix_design_name.'.<br> Dry count: '.$d4.'.';
        break;	
	case 63:
		$action = 'Depalleted';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$production_query = "SELECT mix_design_name FROM $table_name WHERE production_no='".$d2."'  ";
		$production_result = mySQL_query($production_query);
		$mix_design_name = mysql_result($production_result, 0, "mix_design_name");
		
     	$details = 'Production plan no <a href=../production/day_production_display.php?production_date='.$d1.'&production_no='.$d2.'><b>'.$d2.'</b></a> on '.date("d-m-Y", strtotime($d1)).': '.$mix_design_name.'. Pallets: '.$d3.'. Depalleted: '.$d4.'.';
        break;		
			
	case 64:
        $action = 'New mix design';
		$table_name = $_SESSION['db_prefix']."_mix_design_lines";
		$item_query = "SELECT mix_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "mix_design");
						
		$details = 'New mix design <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a>.';
        break;	
		
    case 65:
        $action = 'Edit mix design';
		$table_name = $_SESSION['db_prefix']."_mix_design_lines";
		$item_query = "SELECT mix_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "mix_design");
		
		$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>'.$d2a.'</b> in <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a> changed to <b>'.$d3a.'</b>.';
        break;
		
	case 66:
        $action = 'Edit mix design';
		$table_name = $_SESSION['db_prefix']."_mix_design_lines";
		$item_query = "SELECT mix_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "mix_design");
		
		$details = '<b>'.$d4.'</b> in <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a> changed from <b>'.$d2.'<?b> to <b>'.$d3.'</b>';
        break;
		
	case 67:
        $action = 'Edit mix design';
		$table_name = $_SESSION['db_prefix']."_mix_design_lines";
		$item_query = "SELECT mix_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "mix_design");
		
		$details = '<b>'.$d4.'</b> in <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a> removed.';
        break;		
		
	case 68:
        $action = 'Edit mix design';
		$table_name = $_SESSION['db_prefix']."_mix_design_lines";
		$item_query = "SELECT mix_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "mix_design");
		
		$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>'.$d2a.'</b> in <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a> added with a quantity of <b>'.$d4.'</b>.';
        break;	
	
	case 69:
        $action = 'Edit mix design';
		$table_name = $_SESSION['db_prefix']."_mix_design_lines";
		$item_query = "SELECT mix_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "mix_design");
		
		$details = 'Estimated production quantity in <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>.';
        break;	
		
	case 70:
        $action = 'Edit production plan';
							
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$item_query = "SELECT production_date FROM $table_name WHERE production_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$production_date = mysql_result($item_result, 0, "production_date");
		
		
		$details = '<b>'.$d3.'</b> added to production of <a href=../production/production_plan_display.php?production_no='.$d1.'><b>'.date("d-m-Y", strtotime($production_date)).'</b></a> with a quantity of <b>'.$d4.'</b> skips.';
        break;
		
	case 71:
        $action = 'Edit production plan';
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE mix_design_id = '".$d2."' ";
		$item_result = mySQL_query($item_query);
		$d2a = mysql_result($item_result, 0, "item_name");
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT item_name FROM $table_name WHERE mix_design_id = '".$d3."' ";
		$item_result = mySQL_query($item_query);
		$d3a = mysql_result($item_result, 0, "item_name");
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$item_query = "SELECT production_date FROM $table_name WHERE production_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$production_date = mysql_result($item_result, 0, "production_date");
		
		
		$details = '<b>'.$d2a.'</b> in production of <a href=../production/production_plan_display.php?production_no='.$d1.'><b>'.date("d-m-Y", strtotime($production_date)).'</b></a> changed to  <b>'.$d3a.'</b>.';
        break;
		
	case 72:
        $action = 'Edit production plan';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$item_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$production_date = mysql_result($item_result, 0, "production_date");
		$mix_design_name = mysql_result($item_result, 0, "mix_design_name");
		
				
		$details = 'Skip quantity for <b>'.$mix_design_name.'</b> in production of <a href=../production/production_plan.php?production_no='.$d1.'><b>'.$d1.'</b></a> on '.date("d-m-Y", strtotime($production_date )).' changed from <b>'.$d3.'</b> to <b>'.$d4.'</b>.';
        break;	
		
	case 73:
        $action = 'Cancel production';
		
					
		$details = 'Production of <b>'.$d2.'</b> in production of <b>'.$d1.'</b> canceled';
        break;	
		
	case 74:
        $action = 'Edit skip count';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$item_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$production_date = mysql_result($item_result, 0, "production_date");
		$mix_design_name = mysql_result($item_result, 0, "mix_design_name");
		
				
		$details = 'Counted skip for <b>'.$mix_design_name.'</b> in production of <a href=../production/production_plan.php?production_no='.$d1.'><b>'.$d1.'</b></a> on '.date("d-m-Y", strtotime($production_date )).' changed from <b>'.number_format($d3, 1, '.', ',').'</b> to <b>'.number_format($d4, 1, '.', ',').'</b>.';
        break;
		
	case 75:
        $action = 'Edit wet count';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$item_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$production_date = mysql_result($item_result, 0, "production_date");
		$mix_design_name = mysql_result($item_result, 0, "mix_design_name");
		
				
		$details = 'Counted quantity for <b>'.$mix_design_name.'</b> in production of <a href=../production/production_plan.php?production_no='.$d1.'><b>'.$d1.'</b></a> on '.date("d-m-Y", strtotime($production_date )).' changed from <b>'.number_format($d3, 0, '.', ',').'</b> to <b>'.number_format($d4, 0, '.', ',').'</b>.';
        break;
		
		case 76:
        $action = 'Edit depallet count';
				
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$date_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$date_result = mySQL_query($date_query);
		$production_date = mysql_result($date_result, 0, "production_date");
		$mix_design_name = mysql_result($date_result, 0, "mix_design_name");
		
								
		$details = 'Depallet count on <b>'.$mix_design_name.'</b> production on <a href=../production/day_production_display.php?production_no='.$d1.'><b>'.date("d-m-Y", strtotime($production_date)).'</b></a>, counted on '.date("d-m-Y", strtotime($d2)).' changed from <b>'.number_format($d3, 0, '.', ',').'</b> to <b>'.number_format($d4, 0, '.', ',').'</b>.';
        break;		
		
		case 77:
        $action = 'New packaging design';
		$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
		$item_query = "SELECT packaging_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$packaging_design = mysql_result($item_result, 0, "packaging_design");
						
		$details = 'New packaging design <a href=../production/packaging_design_display.php?design_no='.$d1.'><b>'.$packaging_design.'</b></a>.';
        break;	
		
    case 78:
        $action = 'Edit packaging design';
		$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
		$item_query = "SELECT packaging_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$packaging_design = mysql_result($item_result, 0, "packaging_design");
		
		$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>'.$d2a.'</b> in <a href=../production/packaging_design_display.php?design_no='.$d1.'><b>'.$packaging_design.'</b></a> changed to <b>'.$d3a.'</b>.';
        break;
		
	case 79:
        $action = 'Edit packaging design';
		$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
		$item_query = "SELECT packaging_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$packaging_design = mysql_result($item_result, 0, "packaging_design");
		
		$details = '<b>'.$d4.'</b> in <a href=../production/packaging_design_display.php?design_no='.$d1.'><b>'.$packaging_design.'</b></a> changed from <b>'.$d2.'<?b> to <b>'.$d3.'</b>';
        break;
		
	case 80:
        $action = 'Edit packaging design';
		$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
		$item_query = "SELECT packaging_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$packaging_design = mysql_result($item_result, 0, "packaging_design");
		
		$details = '<b>'.$d4.'</b> in <a href=../production/packaging_design_display.php?design_no='.$d1.'><b>'.$packaging_design.'</b></a> removed.';
        break;		
		
	case 81:
        $action = 'Edit packaging design';
		$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
		$item_query = "SELECT packaging_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$packaging_design = mysql_result($item_result, 0, "packaging_design");
		
		$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>'.$d2a.'</b> in <a href=../production/packaging_design_display.php?design_no='.$d1.'><b>'.$packaging_design.'</b></a> added with a quantity of <b>'.$d4.'</b>.';
        break;	
	
	case 82:
        $action = 'Edit package design';
		$table_name = $_SESSION['db_prefix']."_packaging_design_lines";
		$item_query = "SELECT packaging_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "packaging_design");
		
		$details = 'Estimated packing quantity in <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>.';
        break;	
		
	case 83:
        $action = 'Edit dry count';
				
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$date_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$date_result = mySQL_query($date_query);
		$production_date = mysql_result($date_result, 0, "production_date");
		$mix_design_name = mysql_result($date_result, 0, "mix_design_name");
		
								
		$details = 'Dry count on <b>'.$mix_design_name.'</b> production on <a href=../production/day_production_display.php?production_no='.$d1.'><b>'.date("d-m-Y", strtotime($production_date)).'</b></a>, counted on '.date("d-m-Y", strtotime($d2)).' changed from <b>'.$d3.'</b> to <b>'.$d4.'</b>.';
        break;
		
	case 84:
        $action = 'Edit pallet count';
				
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$date_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$date_result = mySQL_query($date_query);
		$production_date = mysql_result($date_result, 0, "production_date");
		$mix_design_name = mysql_result($date_result, 0, "mix_design_name");
		
								
		$details = 'Pallet count on <b>'.$mix_design_name.'</b> production on <a href=../production/day_production_display.php?production_no='.$d1.'><b>'.date("d-m-Y", strtotime($production_date)).'</b></a>, counted on '.date("d-m-Y", strtotime($d2)).' changed from <b>'.$d3.'</b> to <b>'.$d4.'</b>.';
        break;	
							
	case 85:
        $action = 'Edit mix design';
		$table_name = $_SESSION['db_prefix']."_mix_design_lines";
		$item_query = "SELECT mix_design FROM $table_name WHERE design_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$mix_design = mysql_result($item_result, 0, "mix_design");
		
		$details = 'Packaging design in <a href=../production/mix_design_display.php?design_no='.$d1.'><b>'.$mix_design.'</b></a> changed from <b>'.$d2.'</b> to <b>'.$d3.'</b>.';
        break;
		
	
	case 86:
        $action = 'Edit wet count';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$item_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$production_date = mysql_result($item_result, 0, "production_date");
		$mix_design_name = mysql_result($item_result, 0, "mix_design_name");
		
				
		$details = 'In production of <a href=../production/production_plan.php?production_no='.$d1.'><b>'.$d1.'</b></a> on '.date("d-m-Y", strtotime($production_date )).' is the edited quantity of '.$d4.' >2%  <b><font color="#FF0000">'.$d3.'</font></b> than the estimated quantity for the '.$d2.' recorded skips';
        break;
		
		case 87:
        $action = 'Wet count';
		
		$table_name = $_SESSION['db_prefix']."_production_plan";
		$item_query = "SELECT production_date, mix_design_name FROM $table_name WHERE production_no = '".$d1."' ";
		$item_result = mySQL_query($item_query);
		$production_date = mysql_result($item_result, 0, "production_date");
		$mix_design_name = mysql_result($item_result, 0, "mix_design_name");
		
				
		$details = 'In production of <a href=../production/production_plan.php?production_no='.$d1.'><b>'.$d1.'</b></a> on '.date("d-m-Y", strtotime($production_date )).' is the counted quantity of '.$d4.' >2%  <b><font color="#FF0000">'.$d3.'</font></b> than the estimated quantity for the '.$d2.' recorded skips';
        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>
</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>