CREATE PROCEDURE DBO.CalcAddonPrice @AFirstDayPrice MONEY, @AStartDate DATETIME, @ANumberOfDays SMALLINT, @AdultPax TINYINT, @Child1Pax TINYINT, @Child2Pax TINYINT, @AProductNumber INT, @ARoomTypeNumber INT, @TotalPrice MONEY OUTPUT, @OverrideNameListSetting INT = 0 AS
SET NOCOUNT ON
/*
    Created by Jacob Pedersen 2004-01-26 Most of the calculation logic taken from ProductPrice storedproc. The ideal thing would be to combine these 2 or have ProductPrice use this one, but since there is no pending changes to price logic let us not mess with it now

    Updates:
    20071108 TL: EXT: Added option to override namelist setting
    20060329 JP: BUG: There might be no records for the roomtype for the day which results in a zero price.

    NOTES: This routine is used for calculating AddOn price for overwritten products. It calcs based on the AddOnType setting of the product

*/
SET @TotalPrice = 0

DECLARE @FormatedStartDate CHAR (8)
DECLARE @FormatedEndDate CHAR (8)
SET @FormatedStartDate = Convert (CHAR (8), @AStartDate, 112)
SET @FormatedEndDate = Convert (CHAR (8), @AStartDate+@ANumberOfDays, 112)

DECLARE @AddOnIfPriceOverwritten BIT
SELECT @AddOnIfPriceOverwritten=KeyValue FROM HotelSetup WITH (NOLOCK) WHERE Upper (SearchKey) = Upper ('AddOnIfPriceOverwritten')
IF IsNull (@AddOnIfPriceOverwritten, 0)=0
  SET @AddOnIfPriceOverwritten=0

IF (@AddOnIfPriceOverwritten = 0) OR (@AProductNumber < 1)  -- No need to calc anything
  RETURN

DECLARE @OnePersonPaysForAll Bit
SELECT @OnePersonPaysForAll=KeyValue FROM HotelSetup WITH (NOLOCK) WHERE Upper (SearchKey) = Upper ('OnePersonPaysForAll')
IF IsNull (@OnePersonPaysForAll, 0)=0
  SET @OnePersonPaysForAll=0

DECLARE @AddOnFieldsPerPerson BIT
SELECT @AddOnFieldsPerPerson=KeyValue FROM HotelSetup WITH (NOLOCK) WHERE Upper (SearchKey) = Upper ('AddOnFieldsPerPerson')
IF IsNull (@AddOnFieldsPerPerson, 0)=0
  SET @AddOnFieldsPerPerson=0

DECLARE @HSNameListSetting TINYINT
SELECT @HSNameListSetting=KeyValue FROM HotelSetup WITH (NOLOCK) WHERE Upper (SearchKey) = Upper ('NameListReservationPerPerson')
IF IsNull (@HSNameListSetting, 0)=0
  SET @HSNameListSetting=0

DECLARE @IsDayProduct BIT
DECLARE @IsFixedPrice BIT
DECLARE @AddonType TINYINT  -- 0: addonPerPax  1: addonPerRoomType
DECLARE @NameListSetting TINYINT  -- 0: Follow hotelsetup (@HSNameListSetting)  1: ?  2: ?
SELECT @IsDayProduct = DayProduct, @IsFixedPrice = FixedPrice, @AddonType = AddonType, @NameListSetting = NameListSetting FROM Products WITH (NOLOCK) WHERE ProductNumber = @AProductNumber
IF @@rowcount = 0
  RETURN  -- no product found

SET @OverrideNameListSetting = IsNull(@OverrideNameListSetting, 0)
IF @OverrideNameListSetting = 0
BEGIN
  -- Namelistsetting followhotelsetup
  IF IsNull (@NameListSetting, 0)=0
    SET @NameListSetting=0
  IF @NameListSetting = 0
    SET @NameListSetting = @HSNameListSetting
END
ELSE
  SET @NameListSetting = @OverrideNameListSetting

IF IsNull (@AddOnType, 0)=0
  SET @AddOnType=0

DECLARE @Modifier1 SMALLINT
DECLARE @Modifier2 SMALLINT
IF (@IsDayProduct = 0 AND @AddonType = 0 AND @AddOnFieldsPerPerson = 0) OR (@AddOnFieldsPerPerson = 1)
BEGIN
  SET @Modifier1 = 1
  SET @Modifier2 = 0
END
ELSE
BEGIN
  SET @Modifier1 = 0
  SET @Modifier2 = 1
END

-- Declare VARIABLES for cursor
DECLARE @DateStamp CHAR (8)
Declare @AdultArrivalAddon MONEY
Declare @AdultStayAddon MONEY
Declare @AdultDepartureAddon MONEY
Declare @Children1ArrivalAddon MONEY
Declare @Children1StayAddon MONEY
Declare @Children1DepartureAddon MONEY
Declare @Children2ArrivalAddon MONEY
Declare @Children2StayAddon MONEY
Declare @Children2DepartureAddon MONEY

Declare @AdultArrivalAddon2 Money
Declare @AdultStayAddon2 Money
Declare @AdultDepartureAddon2 Money
Declare @Children1ArrivalAddon2 Money
Declare @Children1StayAddon2 Money
Declare @Children1DepartureAddon2 Money
Declare @Children2ArrivalAddon2 Money
Declare @Children2StayAddon2 Money
Declare @Children2DepartureAddon2 Money
Declare @AdultArrivalAddon3 Money
Declare @AdultStayAddon3 Money
Declare @AdultDepartureAddon3 Money
Declare @Children1ArrivalAddon3 Money
Declare @Children1StayAddon3 Money
Declare @Children1DepartureAddon3 Money
Declare @Children2ArrivalAddon3 Money
Declare @Children2StayAddon3 Money
Declare @Children2DepartureAddon3 Money
Declare @AdultArrivalAddon4 Money
Declare @AdultStayAddon4 Money
Declare @AdultDepartureAddon4 Money
Declare @Children1ArrivalAddon4 Money
Declare @Children1StayAddon4 Money
Declare @Children1DepartureAddon4 Money
Declare @Children2ArrivalAddon4 Money
Declare @Children2StayAddon4 Money
Declare @Children2DepartureAddon4 Money
Declare @AdultArrivalAddon5 Money
Declare @AdultStayAddon5 Money
Declare @AdultDepartureAddon5 Money
Declare @Children1ArrivalAddon5 Money
Declare @Children1StayAddon5 Money
Declare @Children1DepartureAddon5 Money
Declare @Children2ArrivalAddon5 Money
Declare @Children2StayAddon5 Money
Declare @Children2DepartureAddon5 Money
Declare @AdultArrivalAddon6 Money
Declare @AdultStayAddon6 Money
Declare @AdultDepartureAddon6 Money
Declare @Children1ArrivalAddon6 Money
Declare @Children1StayAddon6 Money
Declare @Children1DepartureAddon6 Money
Declare @Children2ArrivalAddon6 Money
Declare @Children2StayAddon6 Money
Declare @Children2DepartureAddon6 Money
Declare @AdultArrivalAddon7 Money
Declare @AdultStayAddon7 Money
Declare @AdultDepartureAddon7 Money
Declare @Children1ArrivalAddon7 Money
Declare @Children1StayAddon7 Money
Declare @Children1DepartureAddon7 Money
Declare @Children2ArrivalAddon7 Money
Declare @Children2StayAddon7 Money
Declare @Children2DepartureAddon7 Money
Declare @AdultArrivalAddon8 Money
Declare @AdultStayAddon8 Money
Declare @AdultDepartureAddon8 Money
Declare @Children1ArrivalAddon8 Money
Declare @Children1StayAddon8 Money
Declare @Children1DepartureAddon8 Money
Declare @Children2ArrivalAddon8 Money
Declare @Children2StayAddon8 Money
Declare @Children2DepartureAddon8 Money
Declare @AdultArrivalAddon9 Money
Declare @AdultStayAddon9 Money
Declare @AdultDepartureAddon9 Money
Declare @Children1ArrivalAddon9 Money
Declare @Children1StayAddon9 Money
Declare @Children1DepartureAddon9 Money
Declare @Children2ArrivalAddon9 Money
Declare @Children2StayAddon9 Money
Declare @Children2DepartureAddon9 Money
DECLARE
@CurrentDate DATETIME,
@CurrentDateStr CHAR(8)

/*
-- ProductPrice Cursor
DECLARE AddonCursor CURSOR READ_ONLY FAST_FORWARD FOR

SELECT DateStamp, AdultArrivalAddon, AdultStayAddon, AdultDepartureAddon, Children1ArrivalAddon,Children1StayAddon, Children1DepartureAddon, Children2ArrivalAddon, Children2StayAddon, Children2DepartureAddon,
AdultArrivalAddon2, AdultStayAddon2, AdultDepartureAddon2, Children1ArrivalAddon2, Children1StayAddon2, Children1DepartureAddon2, Children2ArrivalAddon2, Children2StayAddon2, Children2DepartureAddon2,
AdultArrivalAddon3, AdultStayAddon3, AdultDepartureAddon3, Children1ArrivalAddon3, Children1StayAddon3, Children1DepartureAddon3, Children2ArrivalAddon3, Children2StayAddon3, Children2DepartureAddon3,
AdultArrivalAddon4, AdultStayAddon4, AdultDepartureAddon4, Children1ArrivalAddon4, Children1StayAddon4, Children1DepartureAddon4, Children2ArrivalAddon4, Children2StayAddon4, Children2DepartureAddon4,
AdultArrivalAddon5, AdultStayAddon5, AdultDepartureAddon5, Children1ArrivalAddon5, Children1StayAddon5, Children1DepartureAddon5, Children2ArrivalAddon5, Children2StayAddon5, Children2DepartureAddon5,
AdultArrivalAddon6, AdultStayAddon6, AdultDepartureAddon6, Children1ArrivalAddon6, Children1StayAddon6, Children1DepartureAddon6, Children2ArrivalAddon6, Children2StayAddon6, Children2DepartureAddon6,
AdultArrivalAddon7, AdultStayAddon7, AdultDepartureAddon7, Children1ArrivalAddon7, Children1StayAddon7, Children1DepartureAddon7, Children2ArrivalAddon7, Children2StayAddon7, Children2DepartureAddon7,
AdultArrivalAddon8, AdultStayAddon8, AdultDepartureAddon8, Children1ArrivalAddon8, Children1StayAddon8, Children1DepartureAddon8, Children2ArrivalAddon8, Children2StayAddon8, Children2DepartureAddon8,
AdultArrivalAddon9, AdultStayAddon9, AdultDepartureAddon9, Children1ArrivalAddon9, Children1StayAddon9, Children1DepartureAddon9, Children2ArrivalAddon9, Children2StayAddon9, Children2DepartureAddon9 FROM ProductPrice (NOLOCK) WHERE ProductNumber=@AProductNumber AND RoomTypeNumber=@ARoomTypeNumber AND DateStamp>=@FormatedStartDate AND DateStamp<=@FormatedEndDate

OPEN AddonCursor
FETCH NEXT FROM AddonCursor
INTO @DateStamp,
@AdultArrivalAddon, @AdultStayAddon, @AdultDepartureAddon, @Children1ArrivalAddon,@Children1StayAddon, @Children1DepartureAddon, @Children2ArrivalAddon, @Children2StayAddon, @Children2DepartureAddon,
@AdultArrivalAddon2, @AdultStayAddon2, @AdultDepartureAddon2, @Children1ArrivalAddon2, @Children1StayAddon2, @Children1DepartureAddon2, @Children2ArrivalAddon2, @Children2StayAddon2, @Children2DepartureAddon2,
@AdultArrivalAddon3, @AdultStayAddon3, @AdultDepartureAddon3, @Children1ArrivalAddon3, @Children1StayAddon3, @Children1DepartureAddon3, @Children2ArrivalAddon3, @Children2StayAddon3, @Children2DepartureAddon3,
@AdultArrivalAddon4, @AdultStayAddon4, @AdultDepartureAddon4, @Children1ArrivalAddon4, @Children1StayAddon4, @Children1DepartureAddon4, @Children2ArrivalAddon4, @Children2StayAddon4, @Children2DepartureAddon4,
@AdultArrivalAddon5, @AdultStayAddon5, @AdultDepartureAddon5, @Children1ArrivalAddon5, @Children1StayAddon5, @Children1DepartureAddon5, @Children2ArrivalAddon5, @Children2StayAddon5, @Children2DepartureAddon5,
@AdultArrivalAddon6, @AdultStayAddon6, @AdultDepartureAddon6, @Children1ArrivalAddon6, @Children1StayAddon6, @Children1DepartureAddon6, @Children2ArrivalAddon6, @Children2StayAddon6, @Children2DepartureAddon6,
@AdultArrivalAddon7, @AdultStayAddon7, @AdultDepartureAddon7, @Children1ArrivalAddon7, @Children1StayAddon7, @Children1DepartureAddon7, @Children2ArrivalAddon7, @Children2StayAddon7, @Children2DepartureAddon7,
@AdultArrivalAddon8, @AdultStayAddon8, @AdultDepartureAddon8, @Children1ArrivalAddon8, @Children1StayAddon8, @Children1DepartureAddon8, @Children2ArrivalAddon8, @Children2StayAddon8, @Children2DepartureAddon8,
@AdultArrivalAddon9, @AdultStayAddon9, @AdultDepartureAddon9, @Children1ArrivalAddon9, @Children1StayAddon9, @Children1DepartureAddon9, @Children2ArrivalAddon9, @Children2StayAddon9, @Children2DepartureAddon9

WHILE (@@FETCH_STATUS <> -1)
*/

/* cursor approach does not work because there might not be any rows for the roomtype! hence look through days and select data per datestamp. if not found then use just price  */
SET @CurrentDate = @AStartDate
SET @CurrentDateStr = @FormatedStartDate
WHILE @CurrentDateStr<=@FormatedEndDate
BEGIN
  SELECT @DateStamp=DateStamp, 
  @AdultArrivalAddon=ISNULL(AdultArrivalAddon, 0), @AdultStayAddon=ISNULL(AdultStayAddon, 0), @AdultDepartureAddon=ISNULL(AdultDepartureAddon, 0), @Children1ArrivalAddon=ISNULL(Children1ArrivalAddon, 0),@Children1StayAddon=ISNULL(Children1StayAddon, 0), @Children1DepartureAddon=ISNULL(Children1DepartureAddon, 0), @Children2ArrivalAddon=ISNULL(Children2ArrivalAddon, 0), @Children2StayAddon=ISNULL(Children2StayAddon, 0), @Children2DepartureAddon=ISNULL(Children2DepartureAddon, 0),
  @AdultArrivalAddon2=ISNULL(AdultArrivalAddon2, 0), @AdultStayAddon2=ISNULL(AdultStayAddon2, 0), @AdultDepartureAddon2=ISNULL(AdultDepartureAddon2, 0), @Children1ArrivalAddon2=ISNULL(Children1ArrivalAddon2, 0), @Children1StayAddon2=ISNULL(Children1StayAddon2, 0), @Children1DepartureAddon2=ISNULL(Children1DepartureAddon2, 0), @Children2ArrivalAddon2=ISNULL(Children2ArrivalAddon2, 0), @Children2StayAddon2=ISNULL(Children2StayAddon2, 0), @Children2DepartureAddon2=ISNULL(Children2DepartureAddon2, 0),
  @AdultArrivalAddon3=ISNULL(AdultArrivalAddon3, 0), @AdultStayAddon3=ISNULL(AdultStayAddon3, 0), @AdultDepartureAddon3=ISNULL(AdultDepartureAddon3, 0), @Children1ArrivalAddon3=ISNULL(Children1ArrivalAddon3, 0), @Children1StayAddon3=ISNULL(Children1StayAddon3, 0), @Children1DepartureAddon3=ISNULL(Children1DepartureAddon3, 0), @Children2ArrivalAddon3=ISNULL(Children2ArrivalAddon3, 0), @Children2StayAddon3=ISNULL(Children2StayAddon3, 0), @Children2DepartureAddon3=ISNULL(Children2DepartureAddon3, 0),
  @AdultArrivalAddon4=ISNULL(AdultArrivalAddon4, 0), @AdultStayAddon4=ISNULL(AdultStayAddon4, 0), @AdultDepartureAddon4=ISNULL(AdultDepartureAddon4, 0), @Children1ArrivalAddon4=ISNULL(Children1ArrivalAddon4, 0), @Children1StayAddon4=ISNULL(Children1StayAddon4, 0), @Children1DepartureAddon4=ISNULL(Children1DepartureAddon4, 0), @Children2ArrivalAddon4=ISNULL(Children2ArrivalAddon4, 0), @Children2StayAddon4=ISNULL(Children2StayAddon4, 0), @Children2DepartureAddon4=ISNULL(Children2DepartureAddon4, 0),
  @AdultArrivalAddon5=ISNULL(AdultArrivalAddon5, 0), @AdultStayAddon5=ISNULL(AdultStayAddon5, 0), @AdultDepartureAddon5=ISNULL(AdultDepartureAddon5, 0), @Children1ArrivalAddon5=ISNULL(Children1ArrivalAddon5, 0), @Children1StayAddon5=ISNULL(Children1StayAddon5, 0), @Children1DepartureAddon5=ISNULL(Children1DepartureAddon5, 0), @Children2ArrivalAddon5=ISNULL(Children2ArrivalAddon5, 0), @Children2StayAddon5=ISNULL(Children2StayAddon5, 0), @Children2DepartureAddon5=ISNULL(Children2DepartureAddon5, 0),
  @AdultArrivalAddon6=ISNULL(AdultArrivalAddon6, 0), @AdultStayAddon6=ISNULL(AdultStayAddon6, 0), @AdultDepartureAddon6=ISNULL(AdultDepartureAddon6, 0), @Children1ArrivalAddon6=ISNULL(Children1ArrivalAddon6, 0), @Children1StayAddon6=ISNULL(Children1StayAddon6, 0), @Children1DepartureAddon6=ISNULL(Children1DepartureAddon6, 0), @Children2ArrivalAddon6=ISNULL(Children2ArrivalAddon6, 0), @Children2StayAddon6=ISNULL(Children2StayAddon6, 0), @Children2DepartureAddon6=ISNULL(Children2DepartureAddon6, 0),
  @AdultArrivalAddon7=ISNULL(AdultArrivalAddon7, 0), @AdultStayAddon7=ISNULL(AdultStayAddon7, 0), @AdultDepartureAddon7=ISNULL(AdultDepartureAddon7, 0), @Children1ArrivalAddon7=ISNULL(Children1ArrivalAddon7, 0), @Children1StayAddon7=ISNULL(Children1StayAddon7, 0), @Children1DepartureAddon7=ISNULL(Children1DepartureAddon7, 0), @Children2ArrivalAddon7=ISNULL(Children2ArrivalAddon7, 0), @Children2StayAddon7=ISNULL(Children2StayAddon7, 0), @Children2DepartureAddon7=ISNULL(Children2DepartureAddon7, 0),
  @AdultArrivalAddon8=ISNULL(AdultArrivalAddon8, 0), @AdultStayAddon8=ISNULL(AdultStayAddon8, 0), @AdultDepartureAddon8=ISNULL(AdultDepartureAddon8, 0), @Children1ArrivalAddon8=ISNULL(Children1ArrivalAddon8, 0), @Children1StayAddon8=ISNULL(Children1StayAddon8, 0), @Children1DepartureAddon8=ISNULL(Children1DepartureAddon8, 0), @Children2ArrivalAddon8=ISNULL(Children2ArrivalAddon8, 0), @Children2StayAddon8=ISNULL(Children2StayAddon8, 0), @Children2DepartureAddon8=ISNULL(Children2DepartureAddon8, 0),
  @AdultArrivalAddon9=ISNULL(AdultArrivalAddon9, 0), @AdultStayAddon9=ISNULL(AdultStayAddon9, 0), @AdultDepartureAddon9=ISNULL(AdultDepartureAddon9, 0), @Children1ArrivalAddon9=ISNULL(Children1ArrivalAddon9, 0), @Children1StayAddon9=ISNULL(Children1StayAddon9, 0), @Children1DepartureAddon9=ISNULL(Children1DepartureAddon9, 0), @Children2ArrivalAddon9=ISNULL(Children2ArrivalAddon9, 0), @Children2StayAddon9=ISNULL(Children2StayAddon9, 0), @Children2DepartureAddon9=ISNULL(Children2DepartureAddon9, 0)
  FROM ProductPrice WITH (NOLOCK) WHERE ProductNumber=@AProductNumber AND RoomTypeNumber=@ARoomTypeNumber AND DateStamp=@CurrentDateStr
  IF @@rowcount = 0  -- record not found
  BEGIN
  SELECT @DateStamp=@CurrentDateStr, 
    @AdultArrivalAddon=0, @AdultStayAddon=0, @AdultDepartureAddon=0, @Children1ArrivalAddon=0,@Children1StayAddon=0, @Children1DepartureAddon=0, @Children2ArrivalAddon=0, @Children2StayAddon=0, @Children2DepartureAddon=0,
    @AdultArrivalAddon2=0, @AdultStayAddon2=0, @AdultDepartureAddon2=0, @Children1ArrivalAddon2=0, @Children1StayAddon2=0, @Children1DepartureAddon2=0, @Children2ArrivalAddon2=0, @Children2StayAddon2=0, @Children2DepartureAddon2=0,
    @AdultArrivalAddon3=0, @AdultStayAddon3=0, @AdultDepartureAddon3=0, @Children1ArrivalAddon3=0, @Children1StayAddon3=0, @Children1DepartureAddon3=0, @Children2ArrivalAddon3=0, @Children2StayAddon3=0, @Children2DepartureAddon3=0,
    @AdultArrivalAddon4=0, @AdultStayAddon4=0, @AdultDepartureAddon4=0, @Children1ArrivalAddon4=0, @Children1StayAddon4=0, @Children1DepartureAddon4=0, @Children2ArrivalAddon4=0, @Children2StayAddon4=0, @Children2DepartureAddon4=0,
    @AdultArrivalAddon5=0, @AdultStayAddon5=0, @AdultDepartureAddon5=0, @Children1ArrivalAddon5=0, @Children1StayAddon5=0, @Children1DepartureAddon5=0, @Children2ArrivalAddon5=0, @Children2StayAddon5=0, @Children2DepartureAddon5=0,
    @AdultArrivalAddon6=0, @AdultStayAddon6=0, @AdultDepartureAddon6=0, @Children1ArrivalAddon6=0, @Children1StayAddon6=0, @Children1DepartureAddon6=0, @Children2ArrivalAddon6=0, @Children2StayAddon6=0, @Children2DepartureAddon6=0,
    @AdultArrivalAddon7=0, @AdultStayAddon7=0, @AdultDepartureAddon7=0, @Children1ArrivalAddon7=0, @Children1StayAddon7=0, @Children1DepartureAddon7=0, @Children2ArrivalAddon7=0, @Children2StayAddon7=0, @Children2DepartureAddon7=0,
    @AdultArrivalAddon8=0, @AdultStayAddon8=0, @AdultDepartureAddon8=0, @Children1ArrivalAddon8=0, @Children1StayAddon8=0, @Children1DepartureAddon8=0, @Children2ArrivalAddon8=0, @Children2StayAddon8=0, @Children2DepartureAddon8=0,
    @AdultArrivalAddon9=0, @AdultStayAddon9=0, @AdultDepartureAddon9=0, @Children1ArrivalAddon9=0, @Children1StayAddon9=0, @Children1DepartureAddon9=0, @Children2ArrivalAddon9=0, @Children2StayAddon9=0, @Children2DepartureAddon9=0
  END

  IF @AddOnFieldsPerPerson = 0  -- following code was made to make the calculation code below more simple!
  BEGIN
    SET @AdultArrivalAddon2 = @AdultArrivalAddon
    SET @AdultArrivalAddon3 = @AdultArrivalAddon
    SET @AdultArrivalAddon4 = @AdultArrivalAddon
    SET @AdultArrivalAddon5 = @AdultArrivalAddon
    SET @AdultArrivalAddon6 = @AdultArrivalAddon
    SET @AdultArrivalAddon7 = @AdultArrivalAddon
    SET @AdultArrivalAddon8 = @AdultArrivalAddon
    SET @AdultArrivalAddon9 = @AdultArrivalAddon

    SET @Children1ArrivalAddon2 = @Children1ArrivalAddon
    SET @Children1ArrivalAddon3 = @Children1ArrivalAddon
    SET @Children1ArrivalAddon4 = @Children1ArrivalAddon
    SET @Children1ArrivalAddon5 = @Children1ArrivalAddon
    SET @Children1ArrivalAddon6 = @Children1ArrivalAddon
    SET @Children1ArrivalAddon7 = @Children1ArrivalAddon
    SET @Children1ArrivalAddon8 = @Children1ArrivalAddon
    SET @Children1ArrivalAddon9 = @Children1ArrivalAddon

    SET @Children2ArrivalAddon2 = @Children2ArrivalAddon
    SET @Children2ArrivalAddon3 = @Children2ArrivalAddon
    SET @Children2ArrivalAddon4 = @Children2ArrivalAddon
    SET @Children2ArrivalAddon5 = @Children2ArrivalAddon
    SET @Children2ArrivalAddon6 = @Children2ArrivalAddon
    SET @Children2ArrivalAddon7 = @Children2ArrivalAddon
    SET @Children2ArrivalAddon8 = @Children2ArrivalAddon
    SET @Children2ArrivalAddon9 = @Children2ArrivalAddon

    SET @AdultStayAddon2 = @AdultStayAddon
    SET @AdultStayAddon3 = @AdultStayAddon
    SET @AdultStayAddon4 = @AdultStayAddon
    SET @AdultStayAddon5 = @AdultStayAddon
    SET @AdultStayAddon6 = @AdultStayAddon
    SET @AdultStayAddon7 = @AdultStayAddon
    SET @AdultStayAddon8 = @AdultStayAddon
    SET @AdultStayAddon9 = @AdultStayAddon

    SET @Children1StayAddon2 = @Children1StayAddon
    SET @Children1StayAddon3 = @Children1StayAddon
    SET @Children1StayAddon4 = @Children1StayAddon
    SET @Children1StayAddon5 = @Children1StayAddon
    SET @Children1StayAddon6 = @Children1StayAddon
    SET @Children1StayAddon7 = @Children1StayAddon
    SET @Children1StayAddon8 = @Children1StayAddon
    SET @Children1StayAddon9 = @Children1StayAddon

    SET @Children2StayAddon2 = @Children2StayAddon
    SET @Children2StayAddon3 = @Children2StayAddon
    SET @Children2StayAddon4 = @Children2StayAddon
    SET @Children2StayAddon5 = @Children2StayAddon
    SET @Children2StayAddon6 = @Children2StayAddon
    SET @Children2StayAddon7 = @Children2StayAddon
    SET @Children2StayAddon8 = @Children2StayAddon
    SET @Children2StayAddon9 = @Children2StayAddon

    SET @AdultDepartureAddon2 = @AdultDepartureAddon
    SET @AdultDepartureAddon3 = @AdultDepartureAddon
    SET @AdultDepartureAddon4 = @AdultDepartureAddon
    SET @AdultDepartureAddon5 = @AdultDepartureAddon
    SET @AdultDepartureAddon6 = @AdultDepartureAddon
    SET @AdultDepartureAddon7 = @AdultDepartureAddon
    SET @AdultDepartureAddon8 = @AdultDepartureAddon
    SET @AdultDepartureAddon9 = @AdultDepartureAddon

    SET @Children1DepartureAddon2 = @Children1DepartureAddon
    SET @Children1DepartureAddon3 = @Children1DepartureAddon
    SET @Children1DepartureAddon4 = @Children1DepartureAddon
    SET @Children1DepartureAddon5 = @Children1DepartureAddon
    SET @Children1DepartureAddon6 = @Children1DepartureAddon
    SET @Children1DepartureAddon7 = @Children1DepartureAddon
    SET @Children1DepartureAddon8 = @Children1DepartureAddon
    SET @Children1DepartureAddon9 = @Children1DepartureAddon

    SET @Children2DepartureAddon2 = @Children2DepartureAddon
    SET @Children2DepartureAddon3 = @Children2DepartureAddon
    SET @Children2DepartureAddon4 = @Children2DepartureAddon
    SET @Children2DepartureAddon5 = @Children2DepartureAddon
    SET @Children2DepartureAddon6 = @Children2DepartureAddon
    SET @Children2DepartureAddon7 = @Children2DepartureAddon
    SET @Children2DepartureAddon8 = @Children2DepartureAddon
    SET @Children2DepartureAddon9 = @Children2DepartureAddon
  END

  IF @DateStamp < @FormatedEndDate -- "depature"
    SET @TotalPrice = @TotalPrice + @AFirstDayPrice

  IF @DateStamp = @FormatedStartDate  -- "arrival"
  BEGIN
    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 1 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon
    else if @AdultPax = 2 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon2* (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 3 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon3* (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 4 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon4* (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 5 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon5* (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 6 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon6* (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 7 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon7* (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 8 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon8* (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 9 
      set @TotalPrice = @TotalPrice + @AdultArrivalAddon9* (@AdultPax * @Modifier1 + @Modifier2)

    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 1 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon
    else if @Child1Pax = 2 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon2* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 3 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon3* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 4 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon4* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 5 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon5* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 6 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon6* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 7 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon7* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 8 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon8* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 9 
      set @TotalPrice = @TotalPrice + @Children1ArrivalAddon9* (@Child1Pax * @Modifier1 + @Modifier2)

    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 1 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon
    else if @Child2Pax = 2 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon2* (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 3 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon3* (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 4 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon4* (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 5 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon5* (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 6 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon6* (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 7 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon7* (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 8 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon8* (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 9 
      set @TotalPrice = @TotalPrice + @Children2ArrivalAddon9* (@Child2Pax * @Modifier1 + @Modifier2)
  end
  else if @DateStamp = @FormatedEndDate  -- "departure"
  begin
    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 1 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon
    else if @AdultPax = 2 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon2 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 3 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon3 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 4 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon4 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 5 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon5 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 6 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon6 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 7 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon7 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 8 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon8 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 9 
      set @TotalPrice = @TotalPrice + @AdultDepartureAddon9 * (@AdultPax * @Modifier1 + @Modifier2)

    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 1 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon
    else if @Child1Pax = 2 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon2 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 3 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon3 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 4 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon4 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 5 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon5 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 6 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon6 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 7 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon7 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 8 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon8 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 9 
      set @TotalPrice = @TotalPrice + @Children1DepartureAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)

    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 1 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon
    else if @Child2Pax = 2 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon2 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 3 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon3 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 4 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon4 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 5 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon5 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 6 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon6 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 7 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon7 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 8 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon8 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 9 
      set @TotalPrice = @TotalPrice + @Children2DepartureAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
  end
  else  -- "stay"
  begin
    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @AdultStayAddon * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 1 
      set @TotalPrice = @TotalPrice + @AdultStayAddon
    else if @AdultPax = 2 
      set @TotalPrice = @TotalPrice + @AdultStayAddon2 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 3 
      set @TotalPrice = @TotalPrice + @AdultStayAddon3 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 4 
      set @TotalPrice = @TotalPrice + @AdultStayAddon4 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 5 
      set @TotalPrice = @TotalPrice + @AdultStayAddon5 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 6 
      set @TotalPrice = @TotalPrice + @AdultStayAddon6 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 7 
      set @TotalPrice = @TotalPrice + @AdultStayAddon7 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 8 
      set @TotalPrice = @TotalPrice + @AdultStayAddon8 * (@AdultPax * @Modifier1 + @Modifier2)
    else if @AdultPax = 9 
      set @TotalPrice = @TotalPrice + @AdultStayAddon9 * (@AdultPax * @Modifier1 + @Modifier2)

    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @Children1StayAddon * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 1 
      set @TotalPrice = @TotalPrice + @Children1StayAddon
    else if @Child1Pax = 2 
      set @TotalPrice = @TotalPrice + @Children1StayAddon2 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 3 
      set @TotalPrice = @TotalPrice + @Children1StayAddon3 * (@Child1Pax * @Modifier1 + @Modifier2)

    else if @Child1Pax = 4 
      set @TotalPrice = @TotalPrice + @Children1StayAddon4 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 5 
      set @TotalPrice = @TotalPrice + @Children1StayAddon5 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 6 
      set @TotalPrice = @TotalPrice + @Children1StayAddon6 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 7 
      set @TotalPrice = @TotalPrice + @Children1StayAddon7* (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 8 
      set @TotalPrice = @TotalPrice + @Children1StayAddon8 * (@Child1Pax * @Modifier1 + @Modifier2)
    else if @Child1Pax = 9 
      set @TotalPrice = @TotalPrice + @Children1StayAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)

    if (@OnePersonPaysForAll = 0) and (@NameListSetting = 1)
      set @TotalPrice = @TotalPrice + @Children2StayAddon * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 1 
      set @TotalPrice = @TotalPrice + @Children2StayAddon
    else if @Child2Pax = 2 
      set @TotalPrice = @TotalPrice + @Children2StayAddon2 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 3 
      set @TotalPrice = @TotalPrice + @Children2StayAddon3 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 4 
      set @TotalPrice = @TotalPrice + @Children2StayAddon4 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 5 
      set @TotalPrice = @TotalPrice + @Children2StayAddon5 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 6 
      set @TotalPrice = @TotalPrice + @Children2StayAddon6 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 7 
      set @TotalPrice = @TotalPrice + @Children2StayAddon7 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 8 
      set @TotalPrice = @TotalPrice + @Children2StayAddon8 * (@Child2Pax * @Modifier1 + @Modifier2)
    else if @Child2Pax = 9 
      set @TotalPrice = @TotalPrice + @Children2StayAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
  END
/*
  FETCH NEXT FROM AddonCursor
  INTO @DateStamp,
  @AdultArrivalAddon, @AdultStayAddon, @AdultDepartureAddon, @Children1ArrivalAddon,@Children1StayAddon, @Children1DepartureAddon, @Children2ArrivalAddon, @Children2StayAddon, @Children2DepartureAddon,
  @AdultArrivalAddon2, @AdultStayAddon2, @AdultDepartureAddon2, @Children1ArrivalAddon2, @Children1StayAddon2, @Children1DepartureAddon2, @Children2ArrivalAddon2, @Children2StayAddon2, @Children2DepartureAddon2,
  @AdultArrivalAddon3, @AdultStayAddon3, @AdultDepartureAddon3, @Children1ArrivalAddon3, @Children1StayAddon3, @Children1DepartureAddon3, @Children2ArrivalAddon3, @Children2StayAddon3, @Children2DepartureAddon3,
  @AdultArrivalAddon4, @AdultStayAddon4, @AdultDepartureAddon4, @Children1ArrivalAddon4, @Children1StayAddon4, @Children1DepartureAddon4, @Children2ArrivalAddon4, @Children2StayAddon4, @Children2DepartureAddon4,
  @AdultArrivalAddon5, @AdultStayAddon5, @AdultDepartureAddon5, @Children1ArrivalAddon5, @Children1StayAddon5, @Children1DepartureAddon5, @Children2ArrivalAddon5, @Children2StayAddon5, @Children2DepartureAddon5,
  @AdultArrivalAddon6, @AdultStayAddon6, @AdultDepartureAddon6, @Children1ArrivalAddon6, @Children1StayAddon6, @Children1DepartureAddon6, @Children2ArrivalAddon6, @Children2StayAddon6, @Children2DepartureAddon6,
  @AdultArrivalAddon7, @AdultStayAddon7, @AdultDepartureAddon7, @Children1ArrivalAddon7, @Children1StayAddon7, @Children1DepartureAddon7, @Children2ArrivalAddon7, @Children2StayAddon7, @Children2DepartureAddon7,
  @AdultArrivalAddon8, @AdultStayAddon8, @AdultDepartureAddon8, @Children1ArrivalAddon8, @Children1StayAddon8, @Children1DepartureAddon8, @Children2ArrivalAddon8, @Children2StayAddon8, @Children2DepartureAddon8,
  @AdultArrivalAddon9, @AdultStayAddon9, @AdultDepartureAddon9, @Children1ArrivalAddon9, @Children1StayAddon9, @Children1DepartureAddon9, @Children2ArrivalAddon9, @Children2StayAddon9, @Children2DepartureAddon9
*/
  SET @CurrentDate = @CurrentDate + 1
  SET @CurrentDateStr = CONVERT(CHAR(8), @CurrentDate, 112)
END
/*
CLOSE AddonCursor
DEALLOCATE AddonCursor
*/
