CREATE PROCEDURE [dbo].[ProductPricesDay] @OldProductNumber int,  @ArrivalDate datetime, @DepartureDate datetime, @PriceDate datetime, @OldRoomTypeNumber int, @NumberOfRooms int, @AdultPax int, @Child1Pax int, @Child2Pax int, @Addon money OUTPUT, @BillTextProduct VARCHAR(50) OUTPUT, @BillTextAddOn VARCHAR(50) OUTPUT, @CalcPriceDay money OUTPUT, @PacketNumber int OUTPUT, @EnvironmentFee smallmoney OUTPUT, @FixedPrice Bit OUTPUT, @VATProduct Bit OUTPUT,  @SpecifiedDepartureAddOn Bit OUTPUT, @NamelistSetting int = -1, @OnePersonPaysForAll Bit = 0, @EnvironmentFeeType Float = 0 OUTPUT, @AIsDayProduct BIT = 0, @AAdultPrice MONEY = 0 OUTPUT, @AChild1Price MONEY = 0 OUTPUT, @AChild2Price MONEY = 0 OUTPUT AS
SET NOCOUNT ON

/*
 KJ 20100419: Ext: Added outparams for ONLINE: @AAdultPrice, @AChild1Price, @AChild2Price 
 KJ 20100329: Bug: Fix for "Package not calculated for empty/null product" 
 KJ 20100302: Bug: Fix for "Package number wrong if no product on hallline" 
 KJ 20090924: Bug: Fix for "complete wrong calculation wehn child1 or child2 on res"
 KJ 20080128: Bug: Fix for "packagenumber not set when running sql server 2005"
 KJ 20071002: Not always a producrprice record for all roomtypes - select the highest packagenumber
 KJ 20070411: Changed @Addon from smallmoney to money
 KJ/AV 20061109: Added PricePerType.
 KJ 20051117: Changed: smallmoney back to money (error on GrandPark ref 15273)
 KJ 20051010: Added @EnvironmentFeeType to output parameter..
 BJ 20050824 changed: money to money for @CalcPriceDay and @TotalPriceDay due to an error from Njaal
 KJ 20050711 changed: Do not charge Environment on departure day.
 JP 20050502 changed: money to money. removed productpricenumber
 JP 20050128 changed: added Children2 to dayproducts
 Rettet d. 04/01-2005 : set EnvironmentFee = 0 if Departure
 Rettet d. 04/01-2005 : Added OnePersonPaysForAll
 Rettet d. 03/01-2005 : Added namelistsettting
 Rettet d. 10/12-2004 : wrong calc of EnvironmentFee
 Rettet d. 07/12-2004 : set oldproductnumber=0 if null
 Rettet d. 06/10-2004 : if not UseEnvironmentFee set @EnvironmentFee = 0 (Skallerup)
 Rettet d. 09/09-2004 : Wrong empty/nul product value-test

 Rettet d. 29/1-2003 :  empty/nul product
 Rettet d. 17/6-2003 :  Fixed problem with no price if startdate=enddate
 Rettet d. 17/7-2003 :  Fixed converterror in empty/nullproduct and environmentfee

 Rettet d. 03/12-2002 : Imp addon pr. person or pr room
 Rettet d. 13/12-2002 : Bugfix addon pr. person or pr room
 Rettet d. 16/12-2002 : Bugfix addon pr. person or pr room again
*/

Declare @ProductNumber Int
Declare @DateStamp char (8)
Declare @RoomtypeNumber int
Declare @AdultPrice1 money
Declare @AdultPrice2 money
Declare @AdultPrice3 money
Declare @AdultPrice4  money
Declare @AdultPrice5  money
Declare @AdultPrice6  money
Declare @AdultPrice7  money
Declare @AdultPrice8  money
Declare @AdultPrice9  money
Declare @Children1Price1  money
Declare @Children1Price2  money
Declare @Children1Price3  money
Declare @Children1Price4  money
Declare @Children1Price5  money
Declare @Children1Price6  money
Declare @Children1Price7  money
Declare @Children1Price8  money
Declare @Children1Price9  money
Declare @Children2Price1  money
Declare @Children2Price2  money
Declare @Children2Price3  money
Declare @Children2Price4  money
Declare @Children2Price5  money
Declare @Children2Price6  money
Declare @Children2Price7  money
Declare @Children2Price8  money
Declare @Children2Price9  money

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 @ArrivalPacketNumber int
Declare @StayPacketNumber int
Declare @DeparturePacketNumber int

Declare @FormatedStartDate Char (10)
Declare @FormatedEndDate Char (10)
Declare @TotalPrice money
Declare @IsDayProduct Bit
Declare @IsFixedPrice Bit

Declare @BillTextAddOnArrival VARCHAR(50)
Declare @BillTextAddOnStay VARCHAR(50)
Declare @BillTextAddOnDeparture VARCHAR(50)

Declare @FormatedPriceDate char(8)

Select @FormatedPriceDate =  Convert (Char (8), @PriceDate, 112)
Select @FormatedStartDate =  Convert (Char (8), @ArrivalDate, 112)
Select @FormatedEndDate =  Convert (Char (8), @DepartureDate, 112)

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 @DayProduct Bit

DECLARE @AddOnFieldsPerPerson Bit
Declare @AddonType SmallInt

DECLARE @Modifier1 Smallint
DECLARE @Modifier2 Smallint

Declare @UseEnvironmentFee bit

Declare @TempAdultPax int
Declare @TempChild1Pax int
Declare @TempChild2Pax int

Declare @PricePerType bit

DECLARE @myAdultPrice MONEY
DECLARE @myAdultAddon MONEY
DECLARE @myChild1Price MONEY
DECLARE @myChild1Addon MONEY
DECLARE @myChild2Price MONEY
DECLARE @myChild2Addon MONEY

DECLARE @MyTmpAdultPrice MONEY
DECLARE @MyTmpChild1Price MONEY
DECLARE @MyTmpChild2Price MONEY

SET @myAdultPrice = CAST(0 AS MONEY)
SET @myAdultAddon = CAST(0 AS MONEY)
SET @myChild1Price = CAST(0 AS MONEY)
SET @myChild1Addon = CAST(0 AS MONEY)
SET @myChild2Price = CAST(0 AS MONEY)
SET @myChild2Addon = CAST(0 AS MONEY)

SET @MyTmpAdultPrice = CAST(0 AS MONEY)
SET @MyTmpChild1Price = CAST(0 AS MONEY)
SET @MyTmpChild2Price = CAST(0 AS MONEY)

if @NamelistSetting = 1 AND @OnePersonPaysForAll = 0
begin
  SET @TempAdultPax = @AdultPax
  SET @TempChild1Pax = @Child1Pax
  SET @TempChild2Pax = @Child2Pax

  IF @AdultPax > 1
    SET @AdultPax = 1
  IF @Child1Pax > 1
    SET @Child1Pax = 1
  IF @Child2Pax > 1
    SET @Child2Pax = 1
end

Select @UseEnvironmentFee = CONVERT(Bit,isnull(KeyValue,0)) from HotelSetUp WITH (NOLOCK)  Where  SearchKey='UseEnvironmentFee'

SET @TotalPrice=0
SET @Addon = 0

if IsNull(@NumberOfRooms,1)=1 
  SET @NumberOfRooms = 1
else if (@NumberOfRooms=0)
  SET @NumberOfRooms = 1

if (isnull(@OldProductNumber,0)=0)
  SET @OldProductNumber = 0

if (@OldProductNumber>0)
begin
  IF ISNULL(@OldProductNumber, 0) > 0
  BEGIN
    Select @IsDayProduct = DayProduct, @IsFixedPrice = FixedPrice, @AddonType=AddonType, @PricePerType = ISNULL(PricePerType, 0)
    From Products WITH (NOLOCK)
    Where ProductNumber = @OldProductNumber
  END
  ELSE
    SET @IsDayProduct = ISNULL(@AIsDayProduct, 0)

  If @IsDayProduct = 1 and @PricePerType = 0
    SET @OldRoomTypeNumber = 0  
  SET @OldRoomTypeNumber = ISNULL(@OldRoomTypeNumber,0)

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

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

  IF @IsDayProduct = 0 AND @AddonType = 0 AND @AddOnFieldsPerPerson = 0
  BEGIN
    SET @Modifier1 = 1
    SET @Modifier2 = 0
  END
  ELSE
  BEGIN
    SET @Modifier1 = 0
    SET @Modifier2 = 1
  END

  SELECT distinct
    @ProductNumber = ProductNumber, 
    @DateStamp = DateStamp, 
    @RoomtypeNumber = RoomtypeNumber,
    @AdultPrice1 = AdultPrice1, 
    @AdultPrice2 = AdultPrice2, 
    @AdultPrice3 = AdultPrice3, 
    @AdultPrice4 = AdultPrice4, 
    @AdultPrice5 = AdultPrice5, 
    @AdultPrice6 = AdultPrice6, 
    @AdultPrice7 = AdultPrice7, 

    @AdultPrice8 = AdultPrice8, 
    @AdultPrice9 = AdultPrice9, 
    @Children1Price1 = Children1Price1, 

    @Children1Price2 = Children1Price2, 
    @Children1Price3 = Children1Price3, 
    @Children1Price4 = Children1Price4, 
    @Children1Price5 = Children1Price5, 
    @Children1Price6 = Children1Price6, 
    @Children1Price7 = Children1Price7, 
    @Children1Price8 = Children1Price8, 
    @Children1Price9 = Children1Price9, 
    @Children2Price1 = Children2Price1, 
    @Children2Price2 = Children2Price2, 
    @Children2Price3 = Children2Price3,
    @Children2Price4 = Children2Price4,
    @Children2Price5 = Children2Price5, 
    @Children2Price6 = Children2Price6, 
    @Children2Price7 = Children2Price7, 
    @Children2Price8 = Children2Price8, 
    @Children2Price9 = Children2Price9, 
    @AdultArrivalAddon = AdultArrivalAddon, 
    @AdultStayAddon = AdultStayAddon, 
    @AdultDepartureAddon = AdultDepartureAddon, 
    @Children1ArrivalAddon = Children1ArrivalAddon, 
    @Children1StayAddon = Children1StayAddon, 
    @Children1DepartureAddon = Children1DepartureAddon, 
    @Children2ArrivalAddon = Children2ArrivalAddon, 
    @Children2StayAddon = Children2StayAddon, 
    @Children2DepartureAddon = Children2DepartureAddon, 

    @AdultArrivalAddon2 = AdultArrivalAddon2, 
    @AdultStayAddon2 = AdultStayAddon2, 
    @AdultDepartureAddon2 = AdultDepartureAddon2, 
    @Children1ArrivalAddon2 = Children1ArrivalAddon2, 
    @Children1StayAddon2 = Children1StayAddon2, 
    @Children1DepartureAddon2 = Children1DepartureAddon2, 
    @Children2ArrivalAddon2 = Children2ArrivalAddon2, 
    @Children2StayAddon2 = Children2StayAddon2, 
    @Children2DepartureAddon2 = Children2DepartureAddon2,

    @AdultArrivalAddon3 = AdultArrivalAddon3, 
    @AdultStayAddon3 = AdultStayAddon3, 
    @AdultDepartureAddon3 = AdultDepartureAddon3,
    @Children1ArrivalAddon3 = Children1ArrivalAddon3,
    @Children1StayAddon3 = Children1StayAddon3, 
    @Children1DepartureAddon3 = Children1DepartureAddon3, 
    @Children2ArrivalAddon3 = Children2ArrivalAddon3, 
    @Children2StayAddon3 = Children2StayAddon3, 
    @Children2DepartureAddon3 = Children2DepartureAddon3,

    @AdultArrivalAddon4 = AdultArrivalAddon4, 
    @AdultStayAddon4 = AdultStayAddon4, 
    @AdultDepartureAddon4 = AdultDepartureAddon4, 
    @Children1ArrivalAddon4 = Children1ArrivalAddon4, 
    @Children1StayAddon4 = Children1StayAddon4, 
    @Children1DepartureAddon4 = Children1DepartureAddon4, 
    @Children2ArrivalAddon4 = Children2ArrivalAddon4, 
    @Children2StayAddon4 = Children2StayAddon4, 
    @Children2DepartureAddon4 = Children2DepartureAddon4,

    @AdultArrivalAddon5 = AdultArrivalAddon5, 
    @AdultStayAddon5 = AdultStayAddon5, 
    @AdultDepartureAddon5 = AdultDepartureAddon5, 
    @Children1ArrivalAddon5 = Children1ArrivalAddon5, 
    @Children1StayAddon5 = Children1StayAddon5, 
    @Children1DepartureAddon5 = Children1DepartureAddon5, 
    @Children2ArrivalAddon5 = Children2ArrivalAddon5, 
    @Children2StayAddon5 = Children2StayAddon5, 
    @Children2DepartureAddon5 = Children2DepartureAddon5,

    @AdultArrivalAddon6 = AdultArrivalAddon6, 
    @AdultStayAddon6 = AdultStayAddon6,
    @AdultDepartureAddon6 = AdultDepartureAddon6,
    @Children1ArrivalAddon6 = Children1ArrivalAddon6, 
    @Children1StayAddon6 = Children1StayAddon6, 
    @Children1DepartureAddon6 = Children1DepartureAddon6, 
    @Children2ArrivalAddon6 = Children2ArrivalAddon6, 
    @Children2StayAddon6 = Children2StayAddon6, 
    @Children2DepartureAddon6 = Children2DepartureAddon6,

    @AdultArrivalAddon7 = AdultArrivalAddon7, 
    @AdultStayAddon7 = AdultStayAddon7, 
    @AdultDepartureAddon7 = AdultDepartureAddon7, 
    @Children1ArrivalAddon7 = Children1ArrivalAddon7, 
    @Children1StayAddon7 = Children1StayAddon7, 
    @Children1DepartureAddon7 = Children1DepartureAddon7, 
    @Children2ArrivalAddon7 = Children2ArrivalAddon7, 
    @Children2StayAddon7 = Children2StayAddon7, 
    @Children2DepartureAddon7 = Children2DepartureAddon7,

    @AdultArrivalAddon8 = AdultArrivalAddon8, 
    @AdultStayAddon8 = AdultStayAddon8, 
    @AdultDepartureAddon8 = AdultDepartureAddon8, 
    @Children1ArrivalAddon8 = Children1ArrivalAddon8, 
    @Children1StayAddon8 = Children1StayAddon8, 
    @Children1DepartureAddon8 = Children1DepartureAddon8, 
    @Children2ArrivalAddon8 = Children2ArrivalAddon8, 
    @Children2StayAddon8 = Children2StayAddon8, 
    @Children2DepartureAddon8 = Children2DepartureAddon8,

    @AdultArrivalAddon9 = AdultArrivalAddon9,
    @AdultStayAddon9 = AdultStayAddon9,
    @AdultDepartureAddon9 = AdultDepartureAddon9, 
    @Children1ArrivalAddon9 = Children1ArrivalAddon9, 
    @Children1StayAddon9 = Children1StayAddon9, 
    @Children1DepartureAddon9 = Children1DepartureAddon9, 
    @Children2ArrivalAddon9 = Children2ArrivalAddon9, 
    @Children2StayAddon9 = Children2StayAddon9, 
    @Children2DepartureAddon9 = Children2DepartureAddon9
  From ProductPrice WITH (NOLOCK)
  Where RoomTypeNumber = @OldRoomTypeNumber and ProductNumber = @OldProductNumber and DateStamp = @FormatedPriceDate

  SELECT
    @ArrivalPacketNumber = MAX(ISNULL(ArrivalPacketNumber, -1)),
    @StayPacketNumber = MAX(ISNULL(StayPacketNumber, -1)), 
    @DeparturePacketNumber = MAX(ISNULL(DeparturePacketNumber, -1))
  From ProductPrice WITH (NOLOCK)
  Where /*RoomTypeNumber = @OldRoomTypeNumber and */ProductNumber = @OldProductNumber and DateStamp = @FormatedPriceDate

  Set @TotalPrice = Convert(money,0)
  
  Select 
    @EnvironmentFee=EnvironmentFee, 
    @EnvironmentFeeType=EnvironmentFeeType,
    @BillTextAddOnArrival = BillTextArrival,
    @BillTextAddOnStay = BillTextStay,
    @BillTextAddOnDeparture = BillTextDeparture,
    @BillTextProduct = BillTextProduct,
    @VATProduct = ExcludeVAT
  From Products WITH (NOLOCK) where ProductNumber = @OldProductNumber

  if (@VATProduct is null)
    SET @VATProduct=1
  else
  begin
    if @VATProduct=0 
      SET @VATProduct=1
    else
      SET @VATProduct = 0
  end

  if @IsDayProduct = 0
  begin
    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 (@BillTextAddOnDeparture='') OR (@BillTextAddOnDeparture IS NULL)  
      SET @SpecifiedDepartureAddOn = 0
    else
      SET @SpecifiedDepartureAddOn = 1

    if ((@FormatedEndDate <> @FormatedPriceDate)  AND (@FormatedStartDate<> @FormatedEndDate)) OR((@FormatedStartDate = @FormatedEndDate) AND (@FormatedEndDate=@FormatedPriceDate)) -- "departure = ingen pris"
    begin
      if @AdultPax = 1 set @TotalPrice = @AdultPrice1 else 
      if @AdultPax = 2 set @TotalPrice = @AdultPrice2 else 
      if @AdultPax = 3 set @TotalPrice = @AdultPrice3 else 
      if @AdultPax = 4 set @TotalPrice = @AdultPrice4 else 
      if @AdultPax = 5 set @TotalPrice = @AdultPrice5 else 
      if @AdultPax = 6 set @TotalPrice = @AdultPrice6 else 
      if @AdultPax = 7 set @TotalPrice = @AdultPrice7 else 
      if @AdultPax = 8 set @TotalPrice = @AdultPrice8 else 
      if @AdultPax = 9 set @TotalPrice = @AdultPrice9

      SET @myAdultPrice = @TotalPrice

      if @Child1Pax = 1 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price1 
        SET @myChild1Price = @Children1Price1
      END
      else if @Child1Pax = 2 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price2 
        SET @myChild1Price = @Children1Price2
      END
      else if @Child1Pax = 3 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price3 
        SET @myChild1Price = @Children1Price3
      END
      else if @Child1Pax = 4 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price4 
        SET @myChild1Price = @Children1Price4
      END
      else if @Child1Pax = 5 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price5 
        SET @myChild1Price = @Children1Price5
      END
      else if @Child1Pax = 6 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price6 
        SET @myChild1Price = @Children1Price6
      END
      else if @Child1Pax = 7 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price7 
        SET @myChild1Price = @Children1Price7
      END
      else if @Child1Pax = 8 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price8 
        SET @myChild1Price = @Children1Price8
      END
      else if @Child1Pax = 9 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children1Price9
        SET @myChild1Price = @Children1Price9
      END

      if @Child2Pax = 1 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price1 
        SET @myChild2Price = @Children2Price1
      END
      else if @Child2Pax = 2 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price2 
        SET @myChild2Price = @Children2Price2
      END
      else if @Child2Pax = 3 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price3 
        SET @myChild2Price = @Children2Price3
      END
      else if @Child2Pax = 4 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price4 
        SET @myChild2Price = @Children2Price4
      END
      else if @Child2Pax = 5 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price5 
        SET @myChild2Price = @Children2Price5
      END
      else if @Child2Pax = 6 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price6 
        SET @myChild2Price = @Children2Price6
      END
      else if @Child2Pax = 7 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price7 
        SET @myChild2Price = @Children2Price7
      END
      else if @Child2Pax = 8 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price8 
        SET @myChild2Price = @Children2Price8
      END
      else if @Child2Pax = 9 
      BEGIN
        set @TotalPrice = @TotalPrice + @Children2Price9
        SET @myChild2Price = @Children2Price9
      END
    end
    else
      SET @EnvironmentFee=0

    -- Overnight
    if @FormatedStartDate =@FormatedPriceDate  -- "arrival"
    begin
      SET @BillTextAddOn = @BillTextAddOnArrival
      Set @PacketNumber = @ArrivalPacketNumber

      if @AdultPax = 1 SET @AddOn = @AdultArrivalAddon else 
      if @AdultPax = 2 SET @AddOn = @AdultArrivalAddon2 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 3 SET @AddOn = @AdultArrivalAddon3 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 4 SET @AddOn = @AdultArrivalAddon4 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 5 SET @AddOn = @AdultArrivalAddon5 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 6 SET @AddOn = @AdultArrivalAddon6 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 7 SET @AddOn = @AdultArrivalAddon7 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 8 SET @AddOn = @AdultArrivalAddon8 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 9 SET @AddOn = @AdultArrivalAddon9 * (@AdultPax * @Modifier1 + @Modifier2)

      SET @myAdultAddon = @Addon 

      if @Child1Pax = 1 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon 
        SET @myChild1Addon = @Children1ArrivalAddon
      END
      else if @Child1Pax = 2 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon2 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1ArrivalAddon2 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 3 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon3 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1ArrivalAddon3 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 4 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon4 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1ArrivalAddon4 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 5 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon5 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1ArrivalAddon5 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 6 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon6 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1ArrivalAddon6 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 7 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon7 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1ArrivalAddon7 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 8 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon8 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1ArrivalAddon8 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 9 
      BEGIN
        SET @AddOn = @AddOn + @Children1ArrivalAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)
        SET @myChild1Addon = @Children1ArrivalAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)
      END

      if @Child2Pax = 1 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon 
        SET @myChild2Addon = @Children2ArrivalAddon
      END
      else if @Child2Pax = 2 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon2 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2ArrivalAddon2 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 3 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon3 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2ArrivalAddon3 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 4 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon4 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2ArrivalAddon4 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 5 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon5 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2ArrivalAddon5 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 6 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon6 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2ArrivalAddon6 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 7 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon7 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2ArrivalAddon7 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 8 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon8 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2ArrivalAddon8 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 9 
      BEGIN
        SET @AddOn = @AddOn + @Children2ArrivalAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
        SET @myChild2Addon = @Children2ArrivalAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
    end
    else if @FormatedEndDate=@FormatedPriceDate  -- "departure"
    begin
      if @AdultPax = 1 SET @AddOn = @AdultDepartureAddon else 
      if @AdultPax = 2 SET @AddOn = @AdultDepartureAddon2 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 3 SET @AddOn = @AdultDepartureAddon3 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 4 SET @AddOn = @AdultDepartureAddon4 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 5 SET @AddOn = @AdultDepartureAddon5 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 6 SET @AddOn = @AdultDepartureAddon6 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 7 SET @AddOn = @AdultDepartureAddon7 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 8 SET @AddOn = @AdultDepartureAddon8 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 9 SET @AddOn = @AdultDepartureAddon9 * (@AdultPax * @Modifier1 + @Modifier2)

      SET @myAdultAddon = @Addon 

      if @Child1Pax = 1 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon 
        SET @myChild1Addon = @Children1DepartureAddon
      END
      else if @Child1Pax = 2 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon2 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1DepartureAddon2 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 3 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon3 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1DepartureAddon3 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 4 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon4 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1DepartureAddon4 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 5 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon5 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1DepartureAddon5 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 6 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon6 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1DepartureAddon6 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 7 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon7 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1DepartureAddon7 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 8 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon8 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1DepartureAddon8 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 9 
      BEGIN
        SET @AddOn = @AddOn + @Children1DepartureAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)
        SET @myChild1Addon = @Children1DepartureAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)
      END

      if @Child2Pax = 1 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon 
        SET @myChild2Addon = @Children2DepartureAddon
      END
      else if @Child2Pax = 2 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon2 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2DepartureAddon2 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 3 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon3 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2DepartureAddon3 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 4 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon4 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2DepartureAddon4 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 5 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon5 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2DepartureAddon5 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 6 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon6 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2DepartureAddon6 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 7 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon7 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2DepartureAddon7 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 8 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon8 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2DepartureAddon8 * (@Child2Pax * @Modifier1 + @Modifier2)
      END
      else if @Child2Pax = 9 
      BEGIN
        SET @AddOn = @AddOn + @Children2DepartureAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
        SET @myChild2Addon = @Children2DepartureAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
      END

      SET @BillTextAddOn = @BillTextAddOnDeparture
      Set @PacketNumber = @DeparturePacketNumber
    end
    else  -- "stay"
    begin
      SET @BillTextAddOn = @BillTextAddOnStay

      Set @PacketNumber = @StayPacketNumber

      if @AdultPax = 1 SET @AddOn = @AdultStayAddon else 
      if @AdultPax = 2 SET @AddOn = @AdultStayAddon2 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 3 SET @AddOn = @AdultStayAddon3 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 4 SET @AddOn = @AdultStayAddon4 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 5 SET @AddOn = @AdultStayAddon5 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 6 SET @AddOn = @AdultStayAddon6 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 7 SET @AddOn = @AdultStayAddon7 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 8 SET @AddOn = @AdultStayAddon8 * (@AdultPax * @Modifier1 + @Modifier2) else 
      if @AdultPax = 9 SET @AddOn = @AdultStayAddon9 * (@AdultPax * @Modifier1 + @Modifier2)

      SET @myAdultAddon = @Addon 

      if @Child1Pax = 1 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon 
        SET @myChild1Addon = @Children1StayAddon
      END
      else if @Child1Pax = 2 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon2 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1StayAddon2 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 3 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon3 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1StayAddon3 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 4 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon4 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1StayAddon4 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 5 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon5 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1StayAddon5 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 6 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon6 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1StayAddon6 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 7 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon7 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1StayAddon7 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 8 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon8 * (@Child1Pax * @Modifier1 + @Modifier2) 
        SET @myChild1Addon = @Children1StayAddon8 * (@Child1Pax * @Modifier1 + @Modifier2)
      END
      else if @Child1Pax = 9 
      BEGIN
        SET @AddOn = @AddOn + @Children1StayAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)
        SET @myChild1Addon = @Children1StayAddon9 * (@Child1Pax * @Modifier1 + @Modifier2)
      END

      if @Child2Pax = 1 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon 
        SET @myChild2Addon = @Children2StayAddon
      END 
      else if @Child2Pax = 2 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon2 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2StayAddon2 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
      else if @Child2Pax = 3 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon3 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2StayAddon3 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
      else if @Child2Pax = 4 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon4 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2StayAddon4 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
      else if @Child2Pax = 5 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon5 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2StayAddon5 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
      else if @Child2Pax = 6 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon6 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2StayAddon6 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
      else if @Child2Pax = 7 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon7 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2StayAddon7 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
      else if @Child2Pax = 8 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon8 * (@Child2Pax * @Modifier1 + @Modifier2) 
        SET @myChild2Addon = @Children2StayAddon8 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
      else if @Child2Pax = 9 
      BEGIN
        SET @AddOn = @AddOn + @Children2StayAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
        SET @myChild2Addon = @Children2StayAddon9 * (@Child2Pax * @Modifier1 + @Modifier2)
      END 
    end
  end
  else if @IsDayProduct = 1
  begin
    SET @SpecifiedDepartureAddOn = 0
    SET @PacketNumber= @ArrivalPacketNumber

    if @IsFixedPrice = 0
    begin
      set @TotalPrice = (@AdultPrice1 * @AdultPax)
      set @TotalPrice = @TotalPrice + (@Children1Price1 * @Child1Pax)
      set @TotalPrice = @TotalPrice + (@Children2Price1 * @Child2Pax)  -- JP 20050128
    end
    else 
    begin
      set @TotalPrice = @AdultPrice1
      if (@Child1Pax > 0)
        SET @TotalPrice = @TotalPrice + @Children1Price1
      if (@Child2Pax > 0)
        SET @TotalPrice = @TotalPrice + @Children2Price1
    end
  end
End
Else
Begin
  SET @SpecifiedDepartureAddOn = 0

  if ISNULL(@IsDayProduct, 0) = 0
  begin
    if (@OldProductNumber=0) -- TomtProduct
    begin
      Select @BillTextProduct = KeyValue from HotelSetUp  WITH (NOLOCK) Where  SearchKey='EmptyBillText' 
      Select @EnvironmentFee=CONVERT(Float,replace(KeyValue,',','.')) from HotelSetUp  WITH (NOLOCK) Where  SearchKey='EmptyEnvFee' 
      Select @EnvironmentFeeType=CONVERT(Int,KeyValue) from HotelSetUp WITH (NOLOCK) Where  SearchKey='EmptyEnvType' 

      if (@ArrivalDate=@PriceDate) -- Arrival
        Select @PacketNumber=CONVERT(INT,KeyValue) from HotelSetUp WITH (NOLOCK) Where  SearchKey='EmptyArrPacket'
      else
      if (@DepartureDate=@PriceDate) -- Departure
        Select @PacketNumber=CONVERT(INT,KeyValue) from HotelSetUp WITH (NOLOCK) Where SearchKey='EmptyDepPacket'
      else -- Stay
        Select @PacketNumber=CONVERT(INT,KeyValue) from HotelSetUp WITH (NOLOCK) Where  SearchKey='EmptyStayPacket'
    end
    else -- NUL-product
    if (@OldProductNumber=-1) -- NUL-Product
    begin
      Select @BillTextProduct = KeyValue from HotelSetUp  WITH (NOLOCK) Where  SearchKey='NullBillText' 
      Select @EnvironmentFee=CONVERT(money,replace(KeyValue,',','.')) from HotelSetUp WITH (NOLOCK)  Where  SearchKey='NullEnvFee' 
      Select @EnvironmentFeeType=CONVERT(Int,KeyValue) from HotelSetUp WITH (NOLOCK) Where  SearchKey='NullEnvType' 

      if (@ArrivalDate=@PriceDate) -- Arrival
        Select @PacketNumber=CONVERT(INT,KeyValue) from HotelSetUp WITH (NOLOCK)  Where  SearchKey='NullArrPacket'
      else
      if (@DepartureDate=@PriceDate) -- Departure
        Select @PacketNumber=CONVERT(INT,KeyValue) from HotelSetUp WITH (NOLOCK)  Where  SearchKey='NullDepPacket'
      else -- Stay
        Select @PacketNumber=CONVERT(INT,KeyValue) from HotelSetUp WITH (NOLOCK) Where  SearchKey='NullStayPacket'
    end
  end
  else
    SET @PacketNumber = 0
end

if IsNull(@EnvironmentFee,0)=0 SET @EnvironmentFee = Convert(money,0) -- safe

if IsNull(@EnvironmentFeeType,0)=0 SET @EnvironmentFeeType = 0 -- safe

if IsNull(@TotalPrice,0)=0 SET @TotalPrice = Convert(money,0) -- safe
if IsNull(@NumberOfRooms,0)=0 SET @NumberOfRooms = 0 -- safe

if IsNull(@Addon,0) = 0  SET @Addon = Convert(money,0)

if (@BillTextAddOn is null) SET @BillTextAddOn = ''
if (@BillTextProduct is null) SET @BillTextProduct = ''

Set @CalcPriceDay = @TotalPrice

if @NamelistSetting = 1 AND @OnePersonPaysForAll = 0
begin
--  SET @CalcPriceDay = @CalcPriceDay * (@TempAdultPax + @TempChild1Pax + @TempChild2Pax)
--  SET @Addon = @Addon * (@TempAdultPax + @TempChild1Pax + @TempChild2Pax)
  SET @MyTmpAdultPrice = CAST(0 AS MONEY)
  SET @MyTmpChild1Price = CAST(0 AS MONEY)
  SET @MyTmpChild2Price = CAST(0 AS MONEY)

  IF ISNULL(@MyAdultPrice, 0) > 0 AND ISNULL(@TempAdultPax, 0) > 0
    SET @MyTmpAdultPrice = (@MyAdultPrice * @TempAdultPax) 

  IF ISNULL(@MyChild1Price, 0) > 0 AND ISNULL(@TempChild1Pax, 0) > 0
    SET @MyTmpChild1Price = (@MyChild1Price * @TempChild1Pax) 

  IF ISNULL(@MyChild2Price, 0) > 0 AND ISNULL(@TempChild2Pax, 0) > 0
    SET @MyTmpChild2Price = (@MyChild2Price * @TempChild2Pax) 

  SET @CalcPriceDay = ISNULL(@MyTmpAdultPrice, 0) + ISNULL(@MyTmpChild1Price, 0) + ISNULL(@MyTmpChild2Price, 0)

  SET @AAdultPrice = CONVERT(MONEY, ISNULL(@MyTmpAdultPrice, 0))
  SET @AChild1Price = CONVERT(MONEY, ISNULL(@MyTmpChild1Price, 0))
  SET @AChild2Price = CONVERT(MONEY, ISNULL(@MyTmpChild2Price, 0))
  
  IF ISNULL(@MyAdultAddon, 0) > 0 AND ISNULL(@TempAdultPax, 0) > 0
    SET @AAdultPrice = CONVERT(MONEY, @AAdultPrice + @MyAdultAddon * @TempAdultPax)
  IF ISNULL(@MyChild1Addon, 0) > 0 AND ISNULL(@TempChild1Pax, 0) > 0
    SET @AChild1Price = CONVERT(MONEY, @AChild1Price + @MyChild1Addon * @TempChild1Pax)
  IF ISNULL(@MyChild2Addon, 0) > 0 AND ISNULL(@TempChild2Pax, 0) > 0
    SET @AChild2Price = CONVERT(MONEY, @AChild2Price + @MyChild2Addon * @TempChild2Pax)

  SET @MyTmpAdultPrice = CAST(0 AS MONEY)
  SET @MyTmpChild1Price = CAST(0 AS MONEY)
  SET @MyTmpChild2Price = CAST(0 AS MONEY)

  IF ISNULL(@MyAdultAddon, 0) > 0 AND ISNULL(@TempAdultPax, 0) > 0
    SET @MyTmpAdultPrice = (@MyAdultAddon * @TempAdultPax) 
  IF ISNULL(@MyChild1Addon, 0) > 0 AND ISNULL(@TempChild1Pax, 0) > 0
    SET @MyTmpChild1Price = (@MyChild1Addon * @TempChild1Pax) 
  IF ISNULL(@MyChild2Addon, 0) > 0 AND ISNULL(@TempChild2Pax, 0) > 0
    SET @MyTmpChild2Price = (@MyChild2Addon * @TempChild2Pax) 

  SET @Addon = ISNULL(@MyTmpAdultPrice, 0) + ISNULL(@MyTmpChild1Price, 0) + ISNULL(@MyTmpChild1Price, 0)
end

if (@EnvironmentFeeType=1) AND @UseEnvironmentFee = 1
begin
  set @EnvironmentFeeType = @EnvironmentFee
  set @EnvironmentFee=(@CalcPriceDay)*(@EnvironmentFee/100)
end

SET @Addon = Convert(money,@Addon * @NumberOfRooms)
SET @CalcPriceDay = Convert(money,@CalcPriceDay * @NumberOfRooms)

if @UseEnvironmentFee=1
  SET @EnvironmentFee = Convert(money,@EnvironmentFee * @NumberOfRooms)
else
  SET @EnvironmentFee = 0
 
if IsNull(@PacketNumber,0)=0 SET @PacketNumber = 0 -- safe
if IsNull(@VATProduct,1)=1 SET @VATProduct = 1
if IsNull(@IsFixedPrice,0)=0 SET @IsFixedPrice = 0

SET @FixedPrice = @IsFixedPrice

if @FormatedEndDate=@FormatedPriceDate
  SET @EnvironmentFee = 0