<?php
include('../include/session.php');

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$production_date = $_GET['production_date'];
$production_no = $_GET['production_no'];

$table_name = $_SESSION['db_prefix']."_production_plan";
$mix_query = "SELECT mix_design_name FROM $table_name WHERE production_no = '".$production_no."' ";
$mix_result = mySQL_query($mix_query);
$mix_design_name = mysql_result($mix_result, 0, "mix_design_name");


$table_name = $_SESSION['db_prefix']."_production_plan";
$update_query = "UPDATE $table_name SET cancelled = 'yes' WHERE production_no = '".$production_no."' ";
execsql($update_query);

$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$delete_query = "DELETE FROM $table_name WHERE production_no = '".$production_no."' AND action = 'skip' "; 
execsql($delete_query);

$table_name = $_SESSION['db_prefix']."_production_plan_lines";
$delete_query = "DELETE FROM $table_name WHERE production_no = '".$production_no."' AND action = 'estimated' "; 
execsql($delete_query);

$table_name = $_SESSION['db_prefix']."_tracking_production";
$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '73', '".$production_no."' , '".$mix_design_name."', '', '' )";
execsql($trackingQuery);

?>

<script>
	      window.location="edit_production_plan.php?production_date=<?php echo $production_date?>&e=";
	   </script>