CREATE PROCEDURE dbo.OnlineAddHallLine @AReferenceNumber INT, @AAdults SMALLINT, @AChildren1 SMALLINT, @AChildren2 SMALLINT, @AStartDate DATETIME, @AStartTime VARCHAR(5), @AEndDate DATETIME, @AEndTime VARCHAR(5), @AHallNumber INT, @ATableSetup INT, @AProductNumber INT, @ALineNumber INT, @ATableBooking INT AS 
SET NOCOUNT ON

--    Created by AV 20060614
-- 2016-08-17/SG: PriceOverWritten logic added. 
-- NLB 20070124: Added segment to reservation
-- Sidst rettet 2006 0711 Added search for HallTypeNumber
-- Sidst rettet 2007 0425 Added GuestNumber
-- @ATableBooking=0: Hallbooking, @ATableBooking=1: Bordbooking
---Sidst rettet 2009 0610 Also fill out the tablestatus column if we are dealing with a tablebooking

DECLARE @TableStatus INT

IF @ATableBooking = 1
  SELECT @TableStatus = Status FROM Reservations WITH (NOLOCK) WHERE ReferenceNumber = @AReferenceNumber  AND GuestNumber = 0
ELSE
  SET @TableStatus = NULL

IF (@ATableSetup=0)
   SET @ATableSetup = NULL

DECLARE @HallTypeNumber INT
SELECT @HallTypeNumber = ConferenceRoomTypeNumber FROM ConferenceRooms WITH (NOLOCK) WHERE ConferenceRoomNumber = @AHallNumber

--PriceOverWrite?
Declare @HotelSetupCheckInAlwaysSetPriceOverwrite char(5);
Declare @ProductAlwaysSetPriceOverride char(5);
Declare @PriceOverwrite int;

SET @HotelSetupCheckInAlwaysSetPriceOverwrite = dbo.GetHotelSetupKeyValue('CheckInAlwaysSetPriceOverwrite', -1);
SELECT @ProductAlwaysSetPriceOverride = ProductExtended.AlwaysSetPriceOverride FROM ProductExtended WHERE FK_ProductNumber = @AProductNumber
IF @HotelSetupCheckInAlwaysSetPriceOverwrite = '1' OR @ProductAlwaysSetPriceOverride = '1'
BEGIN
  SET @PriceOverwrite = 1;
END ELSE
BEGIN
  SET @PriceOverwrite = 0;
END

INSERT INTO ReservationConferenceLine (ReservationConfLineNumber, BookedConferenceRoomTypeNumber, NumberOfRooms, ArrivalDate, ArrivalTime, DepartureDate, DepartureTime, 
        ConferenceRoomSetupNumber, ConferenceRoomNumber, Adults, Children1, Children2, ReferenceNumber, TableBooking, TableStatus, PriceOverWritten)
VALUES (@ALineNumber, @HallTypeNumber, 1, CONVERT(VARCHAR(8),@AStartDate,112), @AStartTime, CONVERT(VARCHAR(8),@AEndDate,112), @AEndTime, 
        @ATableSetup, @AHallNumber, @AAdults, @AChildren1, @AChildren2, @AReferenceNumber, @ATableBooking, @TableStatus, @PriceOverwrite)

-- Update segment
DECLARE @SegmentNumber INT
SELECT @SegmentNumber = KeyValue FROM HotelSetup WITH (NOLOCK) WHERE Upper (SearchKey)=Upper('PicassoOnlineSegmentNumberHalls')
UPDATE RESERVATIONS SET MarketSegment = @SegmentNumber WHERE ReferenceNumber=@AReferenceNumber AND GuestNumber=0 AND ISNULL(@SegmentNumber, 0)>0

-- FOLLOWUP ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

EXEC OnlineUpdateFollowUp @AReferenceNumber

