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

	
		
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	
	$user_id = $_SESSION['username'];
	date_default_timezone_set('Africa/Khartoum');
    $entry_date = date("Y-m-d H:i:s",time()-3600); 
	$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'])." (next check: ".date("d-m-Y", strtotime($_SESSION['check_date'])).")', '".trim($_SESSION['seller'])."' ) ";
	execsql($notes_query);
	
	if ($_SESSION['status']=="quoted") {
		$table_name = $_SESSION['db_prefix']."_quotations";
		$status_query = "UPDATE $table_name SET seller = '".$_SESSION['seller']."',  check_date = '".$_SESSION['check_date']."' WHERE quote_no = '".$_SESSION['quote_no']."' ";
		execsql($status_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']."_quotations";
	$branch_query = "SELECT branch FROM $table_name WHERE quote_no = '".$_SESSION['quote_no']."' ";
	$branch_result = mySQL_query($branch_query);
	$branch = mysql_result($branch_result, 0, "branch");

	$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."','".$branch."' )";
	$trackingResult = mySQL_query($trackingQuery);
	
	$quote_no = $_SESSION['quote_no'];
	
	 $_SESSION['quote_no'] = "";
	 $_SESSION['entry_date'] = date('Y-m-d');
	 $_SESSION['check_date'] = "";
	   
	 $_SESSION['seller'] = "";
	 $_SESSION['notes'] = "";
	 $_SESSION['status'] = "";
	 $_SESSION['name'] = "";
	
    if (isset($_GET['new_button']) )
	   {
		 $action='quote_updateWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='quotation.php?quote_no='.$quote_no.'&authorise=0' ;
	  }
	  
 
?>

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



