CREATE PROCEDURE [dbo].[OnlineUpdateHallLine] @AReferenceNumber INT, @AProductNumber INT, @ALineNumber INT, 
      @ATotalPrice Money, @APrice Money,  @AAdults INT, @AChildren1 INT, @AChildren2 INT, @ACardNumber VARCHAR(128), @AExpireDate DATETIME, 
      @AGuestNumber INT= 0, @ConferenceRoomSetupNumber INT = NULL
      AS
SET NOCOUNT ON
/*
Changes: 
    SG 2020-07-02: Changed type of price param from int to money
    SG 2015-09-18: Added @ConferenceRoomSetupNumber (TableSetting, bordopstilling)
    KJ 20131014: ProductPrice Rewrite.
    SG 2013-07-25 CR 062628: Store PackageNumber in ReservationConferenceLine
    AV 2007 1204 updated adults, children1 and 2
    Created by Anders Vindal  2006 0614
Uses
    GenerateArrangement
*/

DECLARE @ArrivalDate VARCHAR(8)
DECLARE @ArrivalDateDT DATETIME
DECLARE @DepartureDate VARCHAR(8)
DECLARE @HotelNumber INT
DECLARE @DominoEnabled BIT
DECLARE @UserIDNumber INT
DECLARE @PacketNumber INT

SELECT @DominoEnabled=CONVERT(SMALLINT,KeyValue) FROM HotelSetup WITH (NOLOCK) WHERE SearchKey='CentralBookingType'
  IF ISNULL(@DominoEnabled, 0) = 0
    SET @DominoEnabled = 0

IF @DominoEnabled = 1
  SELECT @HotelNumber = HotelNumber FROM ReservationMain WITH (NOLOCK) WHERE ReferenceNumber = @AReferenceNumber
ELSE
  SET @HotelNumber = -1

SELECT @ArrivalDate = ArrivalDate, @ArrivalDateDT = CONVERT(DATETIME, ArrivalDate, 112), @DepartureDate = DepartureDate 
FROM ReservationConferenceLine WITH (NOLOCK) WHERE ReservationConfLineNumber = @ALineNumber

--Find pakkenummer
/*
SELECT Top 1 @PacketNumber = ArrivalPacketNumber FROM ProductPrice WITH (NOLOCK)
Where ProductNumber = @AProductNumber 
AND DateStamp = @ArrivalDate 
AND ISNULL(ArrivalPacketNumber,0)<>0
*/
  EXEC GetPackageNumber @AProductNumber, 0, @ArrivalDateDT, @PacketNumber OUTPUT
IF ISNULL(@PacketNumber, -1) = -1
BEGIN
  UPDATE ReservationConferenceLine 
  SET ProductNumber = @AProductNumber, Price = @APrice, TotalPrice = @ATotalPrice, 
      GuestNo=@AGuestNumber, Adults = @AAdults, Children1 = @AChildren1, Children2 = @AChildren2,
      ConferenceRoomSetupNumber = @ConferenceRoomSetupNumber  
  WHERE ReservationConfLineNumber = @ALineNumber
END ELSE
BEGIN
  UPDATE ReservationConferenceLine 
  SET ProductNumber = @AProductNumber, PackageNumber = @PacketNumber, Price = @APrice, TotalPrice = @ATotalPrice, 
      GuestNo=@AGuestNumber, Adults = @AAdults, Children1 = @AChildren1, Children2 = @AChildren2,
      ConferenceRoomSetupNumber = @ConferenceRoomSetupNumber 
  WHERE ReservationConfLineNumber = @ALineNumber
END
EXEC GenerateArrangement -3, @AProductNumber, 0, 0, @ArrivalDate,@ArrivalDate, @DepartureDate,@DepartureDate,@DepartureDate, @Departuredate,@AReferenceNumber, 0, @AAdults, @AAdults,
    @AChildren1, @AChildren1,@AChildren2, @AChildren2, 0, 1, @ALineNumber, 1, 1, 0, @HotelNumber

IF @ACardNumber <> '' 
BEGIN
  UPDATE Reservations SET Creditcardnumber = @ACardNumber, [ExpireDate] = @AExpireDate   WHERE  Referencenumber = @AReferenceNumber
END
