<?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");	
	
	$table_name = $_SESSION['db_prefix']."_presets";
	$follow_up_query = "SELECT  preset_value FROM $table_name WHERE preset_name = 'follow_up' ";
	$follow_up_result = mySQL_query($follow_up_query);
	$follow_up = mysql_result($follow_up_result, 0, "preset_value");
		
	$check_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($entry_date)) . " +".$follow_up." day"));
	
	if (date("l", strtotime($check_date)) == "Sunday") {$check_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($check_date)) . " +1 day")); }
	if (date("l", strtotime($check_date)) == "Saturday") {$check_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($check_date)) . " +2 day")); }
	
		
	$value = $_SESSION['quote_price_1'] + $_SESSION['quote_price_2'] + $_SESSION['quote_price_3'];
	
	$table_name = $_SESSION['db_prefix']."_quotations";
	$quotation_query = "UPDATE $table_name SET `status` = 'quoted', `quotation_date` = '".$_SESSION['quotation_date']."', `check_date` = '".$check_date."',  `designer` = '".$_SESSION['designer']."', `designer` = '".$_SESSION['seller']."', `value` = '".$value."' WHERE quote_no = '".$_SESSION['quote_no']."' ";
	 execsql($quotation_query);	
	//echo $quotation_query;
	
	
	if ($_SESSION['quote_line_1']!="") {
	$table_name = $_SESSION['db_prefix']."_quotation_lines";
    $line_query = "INSERT INTO $table_name (`quote_number`, `quote_item_text`, `quote_item_price`) VALUES ('".$_SESSION['quote_no']."', '".$_SESSION['quote_line_1']."', '".$_SESSION['quote_price_1']."')";
    execsql($line_query);
	}
	
	if ($_SESSION['quote_line_2']!="") {
	$table_name = $_SESSION['db_prefix']."_quotation_lines";
    $line_query = "INSERT INTO $table_name (`quote_number`, `quote_item_text`, `quote_item_price`) VALUES ('".$_SESSION['quote_no']."', '".$_SESSION['quote_line_2']."', '".$_SESSION['quote_price_2']."')";
    execsql($line_query);
	}
	
	if ($_SESSION['quote_line_3']!="") {
	$table_name = $_SESSION['db_prefix']."_quotation_lines";
    $line_query = "INSERT INTO $table_name (`quote_number`, `quote_item_text`, `quote_item_price`) VALUES ('".$_SESSION['quote_no']."', '".$_SESSION['quote_line_3']."', '".$_SESSION['quote_price_3']."')";
    execsql($line_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']."', '41', '".$_SESSION['quote_no']."' ,'".$_SESSION['cust_id']."','','' )";
	$trackingResult = mySQL_query($trackingQuery);
	
	
	
	include('../include/quotation_alert.php');
	
    if (isset($_GET['new_button']) )
	   {
		 $action='quoteWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='quotation.php?quote_no='.$_SESSION['quote_no'] ;
	  }
	  
	  
	  
	$_SESSION['company_name'] ="";
	 $_SESSION['name'] ="";
	 $_SESSION['id'] = "";
     $_SESSION['type'] ="";
     $_SESSION['contact'] = "";
	 $_SESSION['cell'] = "";
	 $_SESSION['bag_box'] = "";
	 $_SESSION['box_number'] = "";
	 $_SESSION['post_place'] = "";
	 $_SESSION['phone'] = "";
	 $_SESSION['fax'] = "";
	 $_SESSION['email'] = "";
	 $_SESSION['reference'] = "";
	 
	 $_SESSION['quote_line_1'] = "";
	 $_SESSION['quote_line_2'] = "";
	 $_SESSION['quote_line_3'] = "";
	 $_SESSION['quote_price_1'] = "";
	 $_SESSION['quote_price_2'] = "";
	 $_SESSION['quote_price_3'] = "";
	 
	 $_SESSION['designer'] = "";
	 $_SESSION['seller'] = "";
	 
	 
	 $_SESSION['quotation_date'] = date('Y-m-d');
	 $_SESSION['validity'] = "";
	 $_SESSION['price'] = "";
	 $_SESSION['quote_amount'] = "";
	 
	 	 
	 $_SESSION['notes'] ="";	   
	  
	 
?>

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



