<?php
include("../include/session.php");
include("../include/db.php");
	
	$query = "SELECT CustNo FROM nam_customer ORDER BY CustNo DESC LIMIT 1 ";
	$result = mySQL_query($query) or die ("Error in query:   $Query . * ". mySQL_error());
	$CustNo = mysql_result($result, 0, "CustNo");
	$CustNo= $CustNo+1;
	
	if (isset($_GET['new_button']) )
	   {
		 $action='customerWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='displayCustomer.php?CustNo='.$CustNo ;
	  }
	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	$modDate=date('Y-m-d');
	$active="1";
		
	$Comp = $_SESSION['customer_name'];
	$Contact = $_SESSION['ContactText'];
	$Address1 = $_SESSION['AddressText1'];
	$Address2 = $_SESSION['AddressText2'];
	$Address = $Address1." ".$Address2;
	$Place = $_SESSION['PlaceText'];
	$Address3 = $_SESSION['AddressText3'];
	$Place2 = $_SESSION['PlaceText2'];
	$Country = $_SESSION['CountryText'];
	$Phone = $_SESSION['PhoneText'];
	$Fax = $_SESSION['FaxText'];
	$Cell = $_SESSION['CellText'];
	$email = $_SESSION['emailText'];
	$VAT = $_SESSION['VATText'];
	$Remarks = $_SESSION['RemarksText'];
	$created_by = $_SESSION['username'];
	
	date_default_timezone_set('Africa/Khartoum');
	$entryDate = date("Y-m-d H:i:s",time()-3600); 
	
	$custQuery = "INSERT INTO nam_customer (EntryDate, ModDate, CustNo, active, CompanyName, ContactName, PostalAddress, PostalPlace, PhysicalAddress, PhysicalPlace, Country, Phone, Fax, Cell, email, VATNo,  Remarks, created_by) VALUES ('".$entryDate."' ,'".$modDate."','".$CustNo."' ,'".$active."' , '".$Comp."','".$Contact."', '".$Address."','".$Place."', '".$Address3."','".$Place2."' ,'".$Country."' , '".$Phone."','".$Fax."', '".$Cell."', '".$email."', '".$VAT."',  '".$Remarks."', '".$created_by."')";
	execsql($custQuery);
	
	$actionQuery = "INSERT INTO nam_action_tracking (entry_date, user, action, details) VALUES ('".$entryDate."' ,'".$created_by."','New Customer account' ,'".$Comp."' )";
	execsql($actionQuery);
	

    $_SESSION['customer_name'] ="";
     $_SESSION['AddressText1'] = "";
	 $_SESSION['AddressText2'] = "";
	 $_SESSION['PlaceText'] = "";
	 $_SESSION['AddressText3'] = "";
	 $_SESSION['PlaceText2'] = "";
	 $_SESSION['CountryText'] = "";
	 $_SESSION['ContactText'] = "";
	 $_SESSION['CellText'] = "";
	 $_SESSION['PhoneText'] = "";
	 $_SESSION['FaxText'] = "";
	 $_SESSION['emailText'] = "";
	 $_SESSION['VATText'] = "";
	 $_SESSION['RemarksText'] = "";
	 
?>

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



