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

	
		
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	
	$user_id = $_SESSION['username'];
	date_default_timezone_set('Africa/Gaborone');
	$entry_date = date("Y-m-d H:i:s", time()); 
	$read_date = date("Y-m-d");	
	$status = 'pending';
	
	$table_name = $_SESSION['db_prefix']."_quotation_notes";
    $notes_query = "INSERT INTO $table_name (quote_number, note_date, note_text, seller ) VALUES ( '".trim($_SESSION['quote_no'])."', '".trim($_SESSION['entry_date'])."', '".trim($_SESSION['notes'])."', '".trim($_SESSION['seller'])."' ) ";
    execsql($notes_query);
	
	if ($_SESSION['status']=="unsuccessful") {
		$table_name = $_SESSION['db_prefix']."_quotations";
		$status_query = "UPDATE $table_name SET status = 'unsuccessful' WHERE quote_no = '".$_SESSION['quote_no']."' ";
		$status = 'unsuccessful';
		execsql($status_query);
		
		
		$table_name = $_SESSION['db_prefix']."_captured_timber";
		$delete_query = "DELETE FROM $table_name WHERE cap_job = '".$_SESSION['quote_no']."' "; 
		execsql($delete_query);
		
		$table_name = $_SESSION['db_prefix']."_captured_mitek";
		$delete_query = "DELETE FROM $table_name WHERE cap_job = '".$_SESSION['quote_no']."' "; 
		execsql($delete_query);
		
		$table_name = $_SESSION['db_prefix']."_captured_sundries";
		$delete_query = "DELETE FROM $table_name WHERE cap_job = '".$_SESSION['quote_no']."' "; 
		execsql($delete_query);
		
				
	}
	
	
	

	$table_name = $_SESSION['db_prefix']."_tracking_sales";
	$trackingQuery = "INSERT INTO $table_name (entry_date, user, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '42', '".$_SESSION['quote_no']."' ,'".$_SESSION['cust_id']."','".$status."','' )";
	$trackingResult = mySQL_query($trackingQuery);
	
    if (isset($_GET['new_button']) )
	   {
		 $action='quote_updateWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='quotation.php?quote_no='.$_SESSION['quote_no'] ;
	  }
	  
 
?>

<script language="javascript" type="text/javascript">
        <!--
		  window.location="<?php echo $action ?> ";
        -->
       </script>



