CREATE PROCEDURE dbo.OnlineCalcHallPrices @AProductNumber INT, @AStartDateTime datetime, @AEndDateTime Datetime,  @AAdults INT, @AChild1 INT, @AChild2 INT, @ANumberOfDays INT, @ANumberOfHalls INT,  @CalcArrivalPrice REAL OUTPUT, @CalcTotalPrice REAL OUTPUT, @HallTypeNumber INT   AS 
SET NOCOUNT ON

--    Created by Troels 20060630
-- 2017-08-30, SG: When departuretime is past midnight, but before Arr24HoursStart, subtract 1 day in order to avoid price for two days.

Declare @DayStartHour int
Declare @DepartureHour int
Declare @DateDiff int

--HotelSetup -> Basic -> "Arrangement 24 hours start at"
Select @DayStartHour = dbo.GetHotelSetupKeyValue('Arr24HoursStart', -1)
Set @DayStartHour = IsNull(@DayStartHour, 5)

Set @DepartureHour = DatePart(hour, @AEndDateTime);
Set @DateDiff = Datediff(day, @AStartDateTime, @AEndDateTime)

If @Datediff > @ANumberOfDays - 1 And @DepartureHour < @DayStartHour
Begin
  Set @AEndDateTime = DateAdd(day, -1, @AEndDateTime)
End


EXEC ProductPrices @AProductNumber, @AStartDateTime, @AEndDateTime, @HallTypeNumber, @ANumberOfHalls, @AAdults, @AChild1, @AChild2, @CalcTotalPrice OUTPUT, @CalcArrivalPrice OUTPUT


