CREATE PROCEDURE [dbo].[OnlineFindMaxpaxAll]  @CountryInt INT, @HotelNumber INT  AS
SET NOCOUNT ON
-- =============================================
-- Author:		Troels Buch
-- Create date: August 2007
-- Description:	
-- Changes:
/*
   KS 20160617: If HotelNumber is less than zero, it will be ignored.
   TBU 20160826: Added @UseDominoAvailability
*/
-- =============================================

DECLARE @UseDominoAvailability SMALLINT
SELECT @UseDominoAvailability= ISNULL(CONVERT(SMALLINT, KeyValue), 0) FROM HotelSetup WITH (NOLOCK) WHERE SearchKey='onlineusedominoavailability'

IF @UseDominoAvailability = 1
	SET @HotelNumber = -1

IF @HotelNumber < 0
BEGIN
	Select MaxAdultPax, MaxChildren1Pax, MaxChildren2Pax, DefAdultPax, DefChildren1Pax, DefChildren2Pax, MaxPaxTotal, OnlineRoomTypes.OnlineRoomTypeNumber 
	FROM OnlineRoomTypes WITH (nolock)
	INNER JOIN OnlineRoomTypesTranslated WITH (NOLOCK) ON OnlineRoomTypes.OnlineRoomTypeNumber = OnlineRoomTypesTranslated.OnlineRoomTypeNumber
	WHERE (CountryNumber = @CountryInt) AND OnlineRoomTypes.OnlineRoomTypeNumber IN 
	(SELECT Roomtypes.OnlineRoomTypenumber
	FROM Onlineroomtypes WITH (NOLOCK) INNER JOIN Roomtypes WITH (NOLOCK) ON Onlineroomtypes.Onlineroomtypenumber = Roomtypes.onlineroomtypenumber) 
	ORDER BY MaxPaxTotal DESC
END
ELSE
BEGIN
	Select MaxAdultPax, MaxChildren1Pax, MaxChildren2Pax, DefAdultPax, DefChildren1Pax, DefChildren2Pax, MaxPaxTotal, OnlineRoomTypes.OnlineRoomTypeNumber 
	FROM OnlineRoomTypes WITH (nolock)
	INNER JOIN OnlineRoomTypesTranslated WITH (NOLOCK) ON OnlineRoomTypes.OnlineRoomTypeNumber = OnlineRoomTypesTranslated.OnlineRoomTypeNumber
	WHERE (CountryNumber = @CountryInt) AND OnlineRoomTypes.OnlineRoomTypeNumber IN (SELECT Roomtypes.OnlineRoomTypenumber
	FROM Onlineroomtypes WITH (NOLOCK) INNER JOIN Roomtypes WITH (NOLOCK) ON Onlineroomtypes.Onlineroomtypenumber = Roomtypes.onlineroomtypenumber 
	WHERE IsNull(Roomtypes.Hotelnumber, 0) = @HotelNumber) 
	ORDER BY MaxPaxTotal DESC
END


