CREATE PROCEDURE dbo.OnlineCreateReservationOrderFolio
(
  @HotelNumber int
 ,@FirstName varchar(50)
 ,@LastName	varchar(50)
 ,@Email varchar(150)
 ,@Phone varchar(255)
)
AS
BEGIN
	DECLARE @AddressNumber int
	DECLARE @FolioNumber int

	EXEC GetNextNumber 'ReservationAddressIdentity', 1, @AddressNumber OUTPUT

	INSERT INTO ReservationAddress (AddressNumber, AddressType,FirstName,LastName, Phone, Email)
	VALUES (@AddressNumber, 1, @FirstName, @LastName, @Phone, @Email)

	INSERT INTO Folios (GuestNumber, ReservationAddressNumber, OpenFolio, Note, HotelCustomerNumber)
	SELECT 0, @AddressNumber, 1, '', C.CustomerNumber
	FROM CUSTOMER C 
	WHERE C.CustomerTypeNumber=7 
	AND C.HotelNumber=@HotelNumber

	SET @FolioNumber = SCOPE_IDENTITY()

	SELECT @FolioNumber FolioNumber
END
