<?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"); 
	$read_date = date("Y-m-d");
	
	
$table_name = $_SESSION['db_prefix']."_presets";
$vat_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'VAT' ";
$vat_result = mySQL_query($vat_query);
$vat = mysql_result($vat_result, 0, "preset_value");	
		
	
	if (($_SESSION['project']=='Maintenance Fence (Residential)') OR ($_SESSION['project']=='Maintenance Fence (Commercial)') OR ($_SESSION['project']=='Maintenance Gate Motor')  OR ($_SESSION['project']=='Maintenance miscellaneous') ) { 
	$total = $_GET['total_amount_text'];
	$value = $total;
	}
	
	if ($_SESSION['project']=='Monthly maintenance') { $value = $_SESSION['amount_text31']; }
	
	
	$table_name = $_SESSION['db_prefix']."_maintenance_quotations";
	$quotation_query = "UPDATE $table_name SET `status` = 'quoted', `quotation_date` = '".$_SESSION['quotation_date']."', `valid_days` = '".$_SESSION['valid_days']."', `delivery_days` = '".$_SESSION['delivery_days']."', `value` = '".$value."', `terms` = '".$_SESSION['terms']."', vat_text = '".$vat."'  WHERE quote_no = '".$_SESSION['quote_no']."' ";
	 execsql($quotation_query);	

	
if (($_SESSION['project']=='Maintenance Fence (Residential)') OR ($_SESSION['project']=='Maintenance Fence (Commercial)') OR ($_SESSION['project']=='Maintenance Gate Motor')  OR ($_SESSION['project']=='Maintenance miscellaneous') ) { 
	
	$j=0;
	while ($j<$_SESSION['line_num3']) {
		$table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
    	$line2_query = "INSERT INTO $table_name (quote_number, quote_option, quote_option_text, quote_item_text, quote_item_price) VALUES ('".$_SESSION['quote_no']."', '11', '".$_SESSION['option1_text']."',  '".$_SESSION['item_text3'.$j]."', '".$_SESSION['amount_text3'.$j]."')";
    	execsql($line2_query);
		$j++;
	}
}

if ($_SESSION['project']=='Monthly maintenance') { 
		$table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
    	$line2_query = "INSERT INTO $table_name (quote_number, quote_option, quote_option_text, quote_item_text, quote_item_price) VALUES ('".$_SESSION['quote_no']."', '11', '".$_SESSION['option1_text']."',  'Monthly rate', '".$_SESSION['amount_text30']."')";
    	execsql($line2_query);
		$table_name = $_SESSION['db_prefix']."_maintenance_quotation_lines";
    	$line2_query = "INSERT INTO $table_name (quote_number, quote_option, quote_option_text, quote_item_text, quote_item_price) VALUES ('".$_SESSION['quote_no']."', '11', '".$_SESSION['option1_text']."',  'Year rate (11 months)', '".$_SESSION['amount_text31']."')";
		execsql($line2_query);
}

	$table_name = $_SESSION['db_prefix']."_tracking_maintenance";
	$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '121', '".$_SESSION['quote_no']."' ,'".$_SESSION['cust_id']."','".$_SESSION['project']."','' )";
	$trackingResult = mySQL_query($trackingQuery);
	

	
	
    if (isset($_GET['new_button']) )
	   {
		 $action='maintenance_quoteWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='maintenance_quotation.php?quote_no='.$_SESSION['quote_no'] ;
	  }
	  
	  
	 $_SESSION['quote_no'] = ""; 
	 $_SESSION['company_name'] ="";
	 $_SESSION['name'] ="";
	 $_SESSION['id'] = "";
	 $_SESSION['cust_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['project'] = "";
	 $_SESSION['VAT']='';

	 $_SESSION['item_text90'] = '';
	 
	 
	$_SESSION['total_amount'] = 0;
	$_SESSION['total_amount2'] = 0; 
	 
	$_SESSION['seller'] = "";
	
	 
	 $_SESSION['quotation_date'] = date('Y-m-d');
	 $_SESSION['terms'] = '';
	 $_SESSION['valid_days'] = '';
	 $_SESSION['delivery_days'] = '';
	 	 
	 $_SESSION['notes'] ="";	 
	  
	 
?>

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



