<?php
include("../include/session.php");
	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	$active="1";
		
	$account_name = $_SESSION['account_name'];
	$credit_cash =$_SESSION['credit_cash'] ;
	$Address1 = $_SESSION['AddressText1'];
	$Address2 = $_SESSION['AddressText2'];
	$post_address = $Address1." ".$Address2;
	$post_place = $_SESSION['PlaceText'];
	$phys_address = $_SESSION['AddressText3'];
	$phys_place = $_SESSION['PlaceText2'];
	$country = $_SESSION['CountryText'];
	$phone = $_SESSION['PhoneText'];
	$fax = $_SESSION['FaxText'];
	$contact1 =$_SESSION['ContactText1'];
	$cell1 =$_SESSION['CellText1'];
	$email1 = $_SESSION['emailText1'];
	$contact2 =$_SESSION['ContactText2'];
	$cell2 = $_SESSION['CellText2'];
	$email2 = $_SESSION['emailText2'];
	$VAT_no = $_SESSION['VATText'];
	$web_site = $_SESSION['WebText'];
	$notes = $_SESSION['RemarksText'];
	$created_by = $_SESSION['username'];
	date_default_timezone_set('Africa/Khartoum');
	$entryDate = date("Y-m-d H:i:s",time()-3600); 
	
	
	
	$table_name = $_SESSION['db_prefix']."_suppliers";
	$supplierQuery = "INSERT INTO $table_name (
											entry_date,  
											account_name, 
											credit_cash, 
											phys_address, 
											phys_place,
											post_address,
											post_place, 
											country, 
											phone, 
											fax, 
											contact1, 
											cell1, 
											email1, 
											contact2,
											cell2, 
											email2, 
											VAT_no, 
											web_site, 
											notes, 
											entered_by)
	                                        VALUES (
													trim('".$entryDate."') , 
													trim('".$account_name."') , 
													trim('".$credit_cash."') , 
													trim('".$phys_address."') , 
													trim('".$phys_place."') , 
													trim('".$post_address."') ,
													trim('".$post_place."') , 
													trim('".$country."') , 
													trim('".$phone."') , 
													trim('".$fax."') , 
													trim('".$contact1."') , 
													trim('".$cell1."') , 
													trim('".$email1."') ,
													trim('".$contact2."') , 
													trim('".$cell2."') , 
													trim('".$email2."') , 
													trim('".$VAT_no."') ,
													trim('".$web_site."') , 
													trim('".$notes."') , 
													trim('".$created_by."')
													)";
	$supplier_result = $con->query($supplierQuery);
	
    $table_name = $_SESSION['db_prefix']."_suppliers";
    $id_query = "SELECT supplier_id FROM $table_name ORDER BY supplier_id DESC LIMIT 1  ";
	$id_result = $con->query($id_query);
	while($row = $id_result->fetch_assoc()) {
		$supplier_id = $row["supplier_id"]; 
	}

	$table_name = $_SESSION['db_prefix']."_tracking_store";
	$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '20', '', '".$supplier_id."' ,'','' )";
	$tracking_result = $con->query($trackingQuery);	
	
	if (isset($_GET['new_button']) )
	   {
		 $action='supplierWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='supplier_details.php?supplier_id='.$supplier_id;
	  }
	
?>
<?php
     $_SESSION['account_name'] ="";
	 $_SESSION['credit_cash'] ="";
     $_SESSION['AddressText1'] = "";
	 $_SESSION['AddressText2'] = "";
	 $_SESSION['PlaceText'] = "";
	 $_SESSION['AddressText3'] = "";
	 $_SESSION['PlaceText2'] = "";
	 $_SESSION['CountryText'] = "";
	 $_SESSION['ContactText'] = "";
	 $_SESSION['PhoneText'] = "";
	 $_SESSION['FaxText'] = "";
	 $_SESSION['VATText'] = "";
	 $_SESSION['ContactText1'] ="";
	 $_SESSION['CellText1'] = "";
	 $_SESSION['emailText1'] = "";
	 $_SESSION['ContactText2'] ="";
	 $_SESSION['CellText2'] = "";
	 $_SESSION['emailText2'] = "";
	 $_SESSION['RemarksText'] = "";
	 
?>
<script language="javascript" type="text/javascript">
        
		  window.location="<?php echo $action ?> ";
        
       </script>