CREATE PROCEDURE dbo.ReservationAddressCreate @AFirstName VARCHAR(50), @ALastName VARCHAR(50), @AAddress1 VARCHAR(50), @AAddress2 VARCHAR(50), @AAddress3 VARCHAR(50),
  @ACountryCode VARCHAR(3), @AZipCode VARCHAR(10), @ACity VARCHAR(40), @AEmail VARCHAR(96), @AOrderId INT, @AAddressNumber INT OUTPUT AS
SET NOCOUNT ON

/*
  Created by Kent Johansen June 2012
  Changes:
  
*/

DECLARE @CountryNumber INT
DECLARE @PaymentHotelSetting VARCHAR(10)
DECLARE @PaymentAfterMonth INT
DECLARE @PaymentAfterDays INT

SELECT @PaymentHotelSetting = ISNULL(KeyValue, 0) FROM HotelSetup WITH (NOLOCK) WHERE SearchKey = 'DAYSTOPAYAFTERCHECKOUT'

IF ISNULL(@PaymentAfterMonth, 0) = 0
  SELECT @PaymentAfterMonth = Number FROM DBO.iter_intlist_to_table_No_Dummy(@PaymentHotelSetting) WHERE ListPos = 1
IF ISNULL(@PaymentAfterMonth, 0) = 0
  SET @PaymentAfterMonth = 0

IF ISNULL(@PaymentAfterDays, 0) = 0
  SELECT @PaymentAfterDays = Number FROM DBO.iter_intlist_to_table_No_Dummy(@PaymentHotelSetting) WHERE ListPos = 2
IF ISNULL(@PaymentAfterDays, 0) = 0
  SET @PaymentAfterDays = 0

SELECT @CountryNumber = CountryNumber FROM Countries WITH (NOLOCK) WHERE CountryCode = @ACountryCode

EXEC GetNextNumber 'ReservationAddressIdentity', 1, @AAddressNumber OUTPUT

INSERT INTO ReservationAddress (AddressNumber, AddressType, Title, FirstName, LastName, Address1, Address2, Address3, CountryCode, ZipCode, City, Phone, Fax, Email, AttentionName, PaymentAfterMonth, PaymentAfterDays, CountryNumber)
VALUES (@AAddressNumber, 1, '', @AFirstName, @ALastName, @AAddress1, @AAddress2, @AAddress3, @ACountryCode, @AZipCode, @ACity, '', @AOrderId, @AEmail, '', @PaymentAfterMonth, @PaymentAfterDays, @CountryNumber)