IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRIGGER_ProductPriceUpdate]'))
DROP TRIGGER [dbo].[TRIGGER_ProductPriceUpdate]
GO
CREATE TRIGGER dbo.TRIGGER_ProductPriceUpdate ON dbo.ProductPrice AFTER INSERT, UPDATE AS
/*
  Created by Kent Johansen october 2014.
  Used for discount products

  Changes:
    KJ 20220209: Support for setting Discount value to 0/NULL. Case #CR214405
    KJ 20200227: Added PPS (Per person sharing)
    KJ 20160527: Ext: Discount is no longer a discount, but a relation. Meaning that a positive number should be added and negative value should be subtracted
    KJ 20141002: Bug: Fix for "Subquery returned more than one record"
    KJ 20141001: Defining cursor as local. Posible fix for "A cursor with the name 'db_cur' already exists."
*/
BEGIN
  SET NOCOUNT ON

  DECLARE @IsDiscounted INT
  
  DECLARE @ProductNumber INT
  DECLARE @DateStamp CHAR(8)
  DECLARE @RoomTypeNumber INT
  
  DECLARE @DiscountProductNumber INT 
  DECLARE @DiscountValue MONEY
  DECLARE @DiscountType INT
  DECLARE @PaxType 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 @AdultArrivalAddon2 MONEY
  DECLARE @AdultArrivalAddon3 MONEY
  DECLARE @AdultArrivalAddon4 MONEY
  DECLARE @AdultArrivalAddon5 MONEY
  DECLARE @AdultArrivalAddon6 MONEY
  DECLARE @AdultArrivalAddon7 MONEY
  DECLARE @AdultArrivalAddon8 MONEY
  DECLARE @AdultArrivalAddon9 MONEY
  DECLARE @AdultStayAddon MONEY
  DECLARE @AdultStayAddon2 MONEY
  DECLARE @AdultStayAddon3 MONEY
  DECLARE @AdultStayAddon4 MONEY
  DECLARE @AdultStayAddon5 MONEY
  DECLARE @AdultStayAddon6 MONEY
  DECLARE @AdultStayAddon7 MONEY
  DECLARE @AdultStayAddon8 MONEY
  DECLARE @AdultStayAddon9 MONEY
  DECLARE @AdultDepartureAddon MONEY
  DECLARE @AdultDepartureAddon2 MONEY
  DECLARE @AdultDepartureAddon3 MONEY
  DECLARE @AdultDepartureAddon4 MONEY
  DECLARE @AdultDepartureAddon5 MONEY
  DECLARE @AdultDepartureAddon6 MONEY
  DECLARE @AdultDepartureAddon7 MONEY
  DECLARE @AdultDepartureAddon8 MONEY
  DECLARE @AdultDepartureAddon9 MONEY
  
  DECLARE @Children1ArrivalAddon MONEY
  DECLARE @Children1ArrivalAddon2 MONEY
  DECLARE @Children1ArrivalAddon3 MONEY
  DECLARE @Children1ArrivalAddon4 MONEY
  DECLARE @Children1ArrivalAddon5 MONEY
  DECLARE @Children1ArrivalAddon6 MONEY
  DECLARE @Children1ArrivalAddon7 MONEY
  DECLARE @Children1ArrivalAddon8 MONEY
  DECLARE @Children1ArrivalAddon9 MONEY
  DECLARE @Children1StayAddon MONEY
  DECLARE @Children1StayAddon2 MONEY
  DECLARE @Children1StayAddon3 MONEY
  DECLARE @Children1StayAddon4 MONEY
  DECLARE @Children1StayAddon5 MONEY
  DECLARE @Children1StayAddon6 MONEY
  DECLARE @Children1StayAddon7 MONEY
  DECLARE @Children1StayAddon8 MONEY
  DECLARE @Children1StayAddon9 MONEY
  DECLARE @Children1DepartureAddon MONEY
  DECLARE @Children1DepartureAddon2 MONEY
  DECLARE @Children1DepartureAddon3 MONEY
  DECLARE @Children1DepartureAddon4 MONEY
  DECLARE @Children1DepartureAddon5 MONEY
  DECLARE @Children1DepartureAddon6 MONEY
  DECLARE @Children1DepartureAddon7 MONEY
  DECLARE @Children1DepartureAddon8 MONEY
  DECLARE @Children1DepartureAddon9 MONEY

  DECLARE @Children2ArrivalAddon MONEY
  DECLARE @Children2ArrivalAddon2 MONEY
  DECLARE @Children2ArrivalAddon3 MONEY
  DECLARE @Children2ArrivalAddon4 MONEY
  DECLARE @Children2ArrivalAddon5 MONEY
  DECLARE @Children2ArrivalAddon6 MONEY
  DECLARE @Children2ArrivalAddon7 MONEY
  DECLARE @Children2ArrivalAddon8 MONEY
  DECLARE @Children2ArrivalAddon9 MONEY
  DECLARE @Children2StayAddon MONEY
  DECLARE @Children2StayAddon2 MONEY
  DECLARE @Children2StayAddon3 MONEY
  DECLARE @Children2StayAddon4 MONEY
  DECLARE @Children2StayAddon5 MONEY
  DECLARE @Children2StayAddon6 MONEY
  DECLARE @Children2StayAddon7 MONEY
  DECLARE @Children2StayAddon8 MONEY
  DECLARE @Children2StayAddon9 MONEY
  DECLARE @Children2DepartureAddon MONEY
  DECLARE @Children2DepartureAddon2 MONEY
  DECLARE @Children2DepartureAddon3 MONEY
  DECLARE @Children2DepartureAddon4 MONEY
  DECLARE @Children2DepartureAddon5 MONEY
  DECLARE @Children2DepartureAddon6 MONEY
  DECLARE @Children2DepartureAddon7 MONEY
  DECLARE @Children2DepartureAddon8 MONEY
  DECLARE @Children2DepartureAddon9 MONEY

  DECLARE @LRowCount INT

  DECLARE db_cur_inserted CURSOR FORWARD_ONLY READ_ONLY LOCAL FOR
    SELECT ProductNumber, DateStamp, RoomTypeNumber,
      AdultPrice1, AdultPrice2, AdultPrice3, AdultPrice4, AdultPrice5, AdultPrice6, AdultPrice7, AdultPrice8, AdultPrice9,
      Children1Price1, Children1Price2, Children1Price3, Children1Price4, Children1Price5, Children1Price6, Children1Price7, Children1Price8, Children1Price9, 
      Children2Price1, Children2Price2, Children2Price3, Children2Price4, Children2Price5, Children2Price6, Children2Price7, Children2Price8, Children2Price9,
      AdultArrivalAddon, AdultArrivalAddon2, AdultArrivalAddon3, AdultArrivalAddon4, AdultArrivalAddon5, AdultArrivalAddon6, AdultArrivalAddon7, AdultArrivalAddon8, AdultArrivalAddon9, 
      AdultStayAddon, AdultStayAddon2, AdultStayAddon3, AdultStayAddon4, AdultStayAddon5, AdultStayAddon6, AdultStayAddon7, AdultStayAddon8, AdultStayAddon9, 
      AdultDepartureAddon, AdultDepartureAddon2, AdultDepartureAddon3, AdultDepartureAddon4, AdultDepartureAddon5, AdultDepartureAddon6, AdultDepartureAddon7, AdultDepartureAddon8, AdultDepartureAddon9, 
      Children1ArrivalAddon, Children1ArrivalAddon2, Children1ArrivalAddon3, Children1ArrivalAddon4, Children1ArrivalAddon5, Children1ArrivalAddon6, Children1ArrivalAddon7, Children1ArrivalAddon8, Children1ArrivalAddon9, 
      Children1StayAddon, Children1StayAddon2, Children1StayAddon3, Children1StayAddon4, Children1StayAddon5, Children1StayAddon6, Children1StayAddon7, Children1StayAddon8, Children1StayAddon9, 
      Children1DepartureAddon, Children1DepartureAddon2, Children1DepartureAddon3, Children1DepartureAddon4, Children1DepartureAddon5, Children1DepartureAddon6, Children1DepartureAddon7, Children1DepartureAddon8, Children1DepartureAddon9, 
      Children2ArrivalAddon, Children2ArrivalAddon2, Children2ArrivalAddon3, Children2ArrivalAddon4, Children2ArrivalAddon5, Children2ArrivalAddon6, Children2ArrivalAddon7, Children2ArrivalAddon8, Children2ArrivalAddon9, 
      Children2StayAddon, Children2StayAddon2, Children2StayAddon3, Children2StayAddon4, Children2StayAddon5, Children2StayAddon6, Children2StayAddon7, Children2StayAddon8, Children2StayAddon9,
      Children2DepartureAddon, Children2DepartureAddon2, Children2DepartureAddon3, Children2DepartureAddon4, Children2DepartureAddon5, Children2DepartureAddon6, Children2DepartureAddon7, Children2DepartureAddon8, Children2DepartureAddon9
	FROM INSERTED
  OPEN db_cur_inserted

  FETCH NEXT FROM db_cur_inserted INTO @ProductNumber, @DateStamp, @RoomTypeNumber,
    @AdultPrice1, @AdultPrice2, @AdultPrice3, @AdultPrice4, @AdultPrice5, @AdultPrice6, @AdultPrice7, @AdultPrice8, @AdultPrice9,
    @Children1Price1, @Children1Price2, @Children1Price3, @Children1Price4, @Children1Price5, @Children1Price6, @Children1Price7, @Children1Price8, @Children1Price9,
    @Children2Price1, @Children2Price2, @Children2Price3, @Children2Price4, @Children2Price5, @Children2Price6, @Children2Price7, @Children2Price8, @Children2Price9,
    @AdultArrivalAddon, @AdultArrivalAddon2, @AdultArrivalAddon3, @AdultArrivalAddon4, @AdultArrivalAddon5, @AdultArrivalAddon6, @AdultArrivalAddon7, @AdultArrivalAddon8, @AdultArrivalAddon9,
    @AdultStayAddon, @AdultStayAddon2, @AdultStayAddon3, @AdultStayAddon4, @AdultStayAddon5, @AdultStayAddon6, @AdultStayAddon7, @AdultStayAddon8, @AdultStayAddon9,
    @AdultDepartureAddon, @AdultDepartureAddon2, @AdultDepartureAddon3, @AdultDepartureAddon4, @AdultDepartureAddon5, @AdultDepartureAddon6, @AdultDepartureAddon7, @AdultDepartureAddon8, @AdultDepartureAddon9,
    @Children1ArrivalAddon, @Children1ArrivalAddon2, @Children1ArrivalAddon3, @Children1ArrivalAddon4, @Children1ArrivalAddon5, @Children1ArrivalAddon6, @Children1ArrivalAddon7, @Children1ArrivalAddon8, @Children1ArrivalAddon9,
    @Children1StayAddon, @Children1StayAddon2, @Children1StayAddon3, @Children1StayAddon4, @Children1StayAddon5, @Children1StayAddon6, @Children1StayAddon7, @Children1StayAddon8, @Children1StayAddon9,
    @Children1DepartureAddon, @Children1DepartureAddon2, @Children1DepartureAddon3, @Children1DepartureAddon4, @Children1DepartureAddon5, @Children1DepartureAddon6, @Children1DepartureAddon7, @Children1DepartureAddon8, @Children1DepartureAddon9,
    @Children2ArrivalAddon, @Children2ArrivalAddon2, @Children2ArrivalAddon3, @Children2ArrivalAddon4, @Children2ArrivalAddon5, @Children2ArrivalAddon6, @Children2ArrivalAddon7, @Children2ArrivalAddon8, @Children2ArrivalAddon9,
    @Children2StayAddon, @Children2StayAddon2, @Children2StayAddon3, @Children2StayAddon4, @Children2StayAddon5, @Children2StayAddon6, @Children2StayAddon7, @Children2StayAddon8, @Children2StayAddon9,
    @Children2DepartureAddon, @Children2DepartureAddon2, @Children2DepartureAddon3, @Children2DepartureAddon4, @Children2DepartureAddon5, @Children2DepartureAddon6, @Children2DepartureAddon7, @Children2DepartureAddon8, @Children2DepartureAddon9

  WHILE @@FETCH_STATUS = 0
  BEGIN
    SELECT @IsDiscounted = COUNT(*) 
    FROM ProductProductDiscountXTab WITH (NOLOCK)
    WHERE FK_ProductNumberDiscounted = @ProductNumber
  
    SET @IsDiscounted = ISNULL(@IsDiscounted, 0)
  
    IF @IsDiscounted = 0
    BEGIN
      DECLARE db_cur CURSOR FORWARD_ONLY READ_ONLY LOCAL FOR 
        SELECT FK_ProductNumberDiscounted, ISNULL(DiscountValue, 0)*-1, DiscountType, PaxType
        FROM ProductProductDiscountXTab WITH (NOLOCK)     
        WHERE FK_ProductNumber = @ProductNumber
      OPEN db_cur
    
      FETCH NEXT FROM db_cur INTO @DiscountProductNumber, @DiscountValue, @DiscountType, @PaxType
    
      WHILE @@FETCH_STATUS = 0
      BEGIN
        SET @LRowCount = -1
        IF @PaxType = 0 OR @PaxType = 1 -- All or Adult
        BEGIN
          UPDATE ProductPrice SET 
            AdultPrice1 = dbo.GetDiscountedPrice (@AdultPrice1, @DiscountType, @DiscountValue, 1),
            AdultPrice2 = dbo.GetDiscountedPrice (@AdultPrice2, @DiscountType, @DiscountValue, 2),
            AdultPrice3 = dbo.GetDiscountedPrice (@AdultPrice3, @DiscountType, @DiscountValue, 3),
            AdultPrice4 = dbo.GetDiscountedPrice (@AdultPrice4, @DiscountType, @DiscountValue, 4),
            AdultPrice5 = dbo.GetDiscountedPrice (@AdultPrice5, @DiscountType, @DiscountValue, 5),
            AdultPrice6 = dbo.GetDiscountedPrice (@AdultPrice6, @DiscountType, @DiscountValue, 6),
            AdultPrice7 = dbo.GetDiscountedPrice (@AdultPrice7, @DiscountType, @DiscountValue, 7),
            AdultPrice8 = dbo.GetDiscountedPrice (@AdultPrice8, @DiscountType, @DiscountValue, 8),
            AdultPrice9 = dbo.GetDiscountedPrice (@AdultPrice9, @DiscountType, @DiscountValue, 9),

            AdultArrivalAddon = dbo.GetDiscountedPrice (@AdultArrivalAddon, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon2 = dbo.GetDiscountedPrice (@AdultArrivalAddon2, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon3 = dbo.GetDiscountedPrice (@AdultArrivalAddon3, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon4 = dbo.GetDiscountedPrice (@AdultArrivalAddon4, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon5 = dbo.GetDiscountedPrice (@AdultArrivalAddon5, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon6 = dbo.GetDiscountedPrice (@AdultArrivalAddon6, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon7 = dbo.GetDiscountedPrice (@AdultArrivalAddon7, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon8 = dbo.GetDiscountedPrice (@AdultArrivalAddon8, @DiscountType, @DiscountValue, 0),
            AdultArrivalAddon9 = dbo.GetDiscountedPrice (@AdultArrivalAddon9, @DiscountType, @DiscountValue, 0),

            AdultStayAddon = dbo.GetDiscountedPrice (@AdultStayAddon, @DiscountType, @DiscountValue, 0),
            AdultStayAddon2 = dbo.GetDiscountedPrice (@AdultStayAddon2, @DiscountType, @DiscountValue, 0),
            AdultStayAddon3 = dbo.GetDiscountedPrice (@AdultStayAddon3, @DiscountType, @DiscountValue, 0),
            AdultStayAddon4 = dbo.GetDiscountedPrice (@AdultStayAddon4, @DiscountType, @DiscountValue, 0),
            AdultStayAddon5 = dbo.GetDiscountedPrice (@AdultStayAddon5, @DiscountType, @DiscountValue, 0),
            AdultStayAddon6 = dbo.GetDiscountedPrice (@AdultStayAddon6, @DiscountType, @DiscountValue, 0),
            AdultStayAddon7 = dbo.GetDiscountedPrice (@AdultStayAddon7, @DiscountType, @DiscountValue, 0),
            AdultStayAddon8 = dbo.GetDiscountedPrice (@AdultStayAddon8, @DiscountType, @DiscountValue, 0),
            AdultStayAddon9 = dbo.GetDiscountedPrice (@AdultStayAddon9, @DiscountType, @DiscountValue, 0),

            AdultdepartureAddon = dbo.GetDiscountedPrice (@AdultdepartureAddon, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon2 = dbo.GetDiscountedPrice (@AdultdepartureAddon2, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon3 = dbo.GetDiscountedPrice (@AdultdepartureAddon3, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon4 = dbo.GetDiscountedPrice (@AdultdepartureAddon4, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon5 = dbo.GetDiscountedPrice (@AdultdepartureAddon5, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon6 = dbo.GetDiscountedPrice (@AdultdepartureAddon6, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon7 = dbo.GetDiscountedPrice (@AdultdepartureAddon7, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon8 = dbo.GetDiscountedPrice (@AdultdepartureAddon8, @DiscountType, @DiscountValue, 0),
            AdultdepartureAddon9 = dbo.GetDiscountedPrice (@AdultdepartureAddon9, @DiscountType, @DiscountValue, 0)
          WHERE ProductNumber = @DiscountProductNumber 
          AND DateStamp = @DateStamp
          AND RoomTypeNumber = @RoomTypeNumber

          SELECT @LRowCount = @@ROWCOUNT
        END
        IF @PaxType = 0 OR @PaxType = 2 -- All or Child1
        BEGIN
          UPDATE ProductPrice SET 
            Children1Price1 = dbo.GetDiscountedPrice (@Children1Price1, @DiscountType, @DiscountValue, 1),
            Children1Price2 = dbo.GetDiscountedPrice (@Children1Price2, @DiscountType, @DiscountValue, 2),
            Children1Price3 = dbo.GetDiscountedPrice (@Children1Price3, @DiscountType, @DiscountValue, 3),
            Children1Price4 = dbo.GetDiscountedPrice (@Children1Price4, @DiscountType, @DiscountValue, 4),
            Children1Price5 = dbo.GetDiscountedPrice (@Children1Price5, @DiscountType, @DiscountValue, 5),
            Children1Price6 = dbo.GetDiscountedPrice (@Children1Price6, @DiscountType, @DiscountValue, 6),
            Children1Price7 = dbo.GetDiscountedPrice (@Children1Price7, @DiscountType, @DiscountValue, 7),
            Children1Price8 = dbo.GetDiscountedPrice (@Children1Price8, @DiscountType, @DiscountValue, 8),
            Children1Price9 = dbo.GetDiscountedPrice (@Children1Price9, @DiscountType, @DiscountValue, 9),

            Children1ArrivalAddon = dbo.GetDiscountedPrice (@Children1ArrivalAddon, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon2 = dbo.GetDiscountedPrice (@Children1ArrivalAddon2, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon3 = dbo.GetDiscountedPrice (@Children1ArrivalAddon3, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon4 = dbo.GetDiscountedPrice (@Children1ArrivalAddon4, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon5 = dbo.GetDiscountedPrice (@Children1ArrivalAddon5, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon6 = dbo.GetDiscountedPrice (@Children1ArrivalAddon6, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon7 = dbo.GetDiscountedPrice (@Children1ArrivalAddon7, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon8 = dbo.GetDiscountedPrice (@Children1ArrivalAddon8, @DiscountType, @DiscountValue, 0),
            Children1ArrivalAddon9 = dbo.GetDiscountedPrice (@Children1ArrivalAddon9, @DiscountType, @DiscountValue, 0),

            Children1StayAddon = dbo.GetDiscountedPrice (@Children1StayAddon, @DiscountType, @DiscountValue, 0),
            Children1StayAddon2 = dbo.GetDiscountedPrice (@Children1StayAddon2, @DiscountType, @DiscountValue, 0),
            Children1StayAddon3 = dbo.GetDiscountedPrice (@Children1StayAddon3, @DiscountType, @DiscountValue, 0),
            Children1StayAddon4 = dbo.GetDiscountedPrice (@Children1StayAddon4, @DiscountType, @DiscountValue, 0),
            Children1StayAddon5 = dbo.GetDiscountedPrice (@Children1StayAddon5, @DiscountType, @DiscountValue, 0),
            Children1StayAddon6 = dbo.GetDiscountedPrice (@Children1StayAddon6, @DiscountType, @DiscountValue, 0),
            Children1StayAddon7 = dbo.GetDiscountedPrice (@Children1StayAddon7, @DiscountType, @DiscountValue, 0),
            Children1StayAddon8 = dbo.GetDiscountedPrice (@Children1StayAddon8, @DiscountType, @DiscountValue, 0),
            Children1StayAddon9 = dbo.GetDiscountedPrice (@Children1StayAddon9, @DiscountType, @DiscountValue, 0),

            Children1DepartureAddon = dbo.GetDiscountedPrice (@Children1DepartureAddon, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon2 = dbo.GetDiscountedPrice (@Children1DepartureAddon2, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon3 = dbo.GetDiscountedPrice (@Children1DepartureAddon3, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon4 = dbo.GetDiscountedPrice (@Children1DepartureAddon4, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon5 = dbo.GetDiscountedPrice (@Children1DepartureAddon5, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon6 = dbo.GetDiscountedPrice (@Children1DepartureAddon6, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon7 = dbo.GetDiscountedPrice (@Children1DepartureAddon7, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon8 = dbo.GetDiscountedPrice (@Children1DepartureAddon8, @DiscountType, @DiscountValue, 0),
            Children1DepartureAddon9 = dbo.GetDiscountedPrice (@Children1DepartureAddon9, @DiscountType, @DiscountValue, 0)
          WHERE ProductNumber = @DiscountProductNumber 
          AND DateStamp = @DateStamp
          AND RoomTypeNumber = @RoomTypeNumber

          SELECT @LRowCount = @@ROWCOUNT
        END
        IF @PaxType = 0 OR @PaxType = 3 -- All or Child2
        BEGIN
          UPDATE ProductPrice SET
            Children2Price1 = dbo.GetDiscountedPrice (@Children2Price1, @DiscountType, @DiscountValue, 1),
            Children2Price2 = dbo.GetDiscountedPrice (@Children2Price2, @DiscountType, @DiscountValue, 2),
            Children2Price3 = dbo.GetDiscountedPrice (@Children2Price3, @DiscountType, @DiscountValue, 3),
            Children2Price4 = dbo.GetDiscountedPrice (@Children2Price4, @DiscountType, @DiscountValue, 4),
            Children2Price5 = dbo.GetDiscountedPrice (@Children2Price5, @DiscountType, @DiscountValue, 5),
            Children2Price6 = dbo.GetDiscountedPrice (@Children2Price6, @DiscountType, @DiscountValue, 6),
            Children2Price7 = dbo.GetDiscountedPrice (@Children2Price7, @DiscountType, @DiscountValue, 7),
            Children2Price8 = dbo.GetDiscountedPrice (@Children2Price8, @DiscountType, @DiscountValue, 8),
            Children2Price9 = dbo.GetDiscountedPrice (@Children2Price9, @DiscountType, @DiscountValue, 9),

            Children2ArrivalAddon = dbo.GetDiscountedPrice (@Children2ArrivalAddon, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon2 = dbo.GetDiscountedPrice (@Children2ArrivalAddon2, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon3 = dbo.GetDiscountedPrice (@Children2ArrivalAddon3, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon4 = dbo.GetDiscountedPrice (@Children2ArrivalAddon4, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon5 = dbo.GetDiscountedPrice (@Children2ArrivalAddon5, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon6 = dbo.GetDiscountedPrice (@Children2ArrivalAddon6, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon7 = dbo.GetDiscountedPrice (@Children2ArrivalAddon7, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon8 = dbo.GetDiscountedPrice (@Children2ArrivalAddon8, @DiscountType, @DiscountValue, 0),
            Children2ArrivalAddon9 = dbo.GetDiscountedPrice (@Children2ArrivalAddon9, @DiscountType, @DiscountValue, 0),

            Children2StayAddon = dbo.GetDiscountedPrice (@Children2StayAddon, @DiscountType, @DiscountValue, 0),
            Children2StayAddon2 = dbo.GetDiscountedPrice (@Children2StayAddon2, @DiscountType, @DiscountValue, 0),
            Children2StayAddon3 = dbo.GetDiscountedPrice (@Children2StayAddon3, @DiscountType, @DiscountValue, 0),
            Children2StayAddon4 = dbo.GetDiscountedPrice (@Children2StayAddon4, @DiscountType, @DiscountValue, 0),
            Children2StayAddon5 = dbo.GetDiscountedPrice (@Children2StayAddon5, @DiscountType, @DiscountValue, 0),
            Children2StayAddon6 = dbo.GetDiscountedPrice (@Children2StayAddon6, @DiscountType, @DiscountValue, 0),
            Children2StayAddon7 = dbo.GetDiscountedPrice (@Children2StayAddon7, @DiscountType, @DiscountValue, 0),
            Children2StayAddon8 = dbo.GetDiscountedPrice (@Children2StayAddon8, @DiscountType, @DiscountValue, 0),
            Children2StayAddon9 = dbo.GetDiscountedPrice (@Children2StayAddon9, @DiscountType, @DiscountValue, 0),

            Children2DepartureAddon = dbo.GetDiscountedPrice (@Children2DepartureAddon, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon2 = dbo.GetDiscountedPrice (@Children2DepartureAddon2, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon3 = dbo.GetDiscountedPrice (@Children2DepartureAddon3, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon4 = dbo.GetDiscountedPrice (@Children2DepartureAddon4, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon5 = dbo.GetDiscountedPrice (@Children2DepartureAddon5, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon6 = dbo.GetDiscountedPrice (@Children2DepartureAddon6, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon7 = dbo.GetDiscountedPrice (@Children2DepartureAddon7, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon8 = dbo.GetDiscountedPrice (@Children2DepartureAddon8, @DiscountType, @DiscountValue, 0),
            Children2DepartureAddon9 = dbo.GetDiscountedPrice (@Children2DepartureAddon9, @DiscountType, @DiscountValue, 0)
          WHERE ProductNumber = @DiscountProductNumber 
          AND DateStamp = @DateStamp
          AND RoomTypeNumber = @RoomTypeNumber

          SELECT @LRowCount = @@ROWCOUNT
        END
      
    	  IF @LROWCOUNT = 0
	      BEGIN
          IF @PaxType = 0 -- All
          BEGIN
	          INSERT INTO ProductPrice 
            (
              ProductNumber, DateStamp, RoomTypeNumber, 
              AdultPrice1, AdultPrice2, AdultPrice3, AdultPrice4, AdultPrice5, AdultPrice6, AdultPrice7, AdultPrice8, AdultPrice9,
              AdultArrivalAddon, AdultArrivalAddon2, AdultArrivalAddon3, AdultArrivalAddon4, AdultArrivalAddon5, AdultArrivalAddon6, AdultArrivalAddon7, AdultArrivalAddon8, AdultArrivalAddon9,
              AdultStayAddon, AdultStayAddon2, AdultStayAddon3, AdultStayAddon4, AdultStayAddon5, AdultStayAddon6, AdultStayAddon7, AdultStayAddon8, AdultStayAddon9,
              AdultdepartureAddon, AdultdepartureAddon2, AdultdepartureAddon3, AdultdepartureAddon4, AdultdepartureAddon5, AdultdepartureAddon6, AdultdepartureAddon7, AdultdepartureAddon8, AdultdepartureAddon9,

              Children1Price1, Children1Price2, Children1Price3, Children1Price4, Children1Price5, Children1Price6, Children1Price7, Children1Price8, Children1Price9,
              Children1ArrivalAddon, Children1ArrivalAddon2, Children1ArrivalAddon3, Children1ArrivalAddon4, Children1ArrivalAddon5, Children1ArrivalAddon6, Children1ArrivalAddon7, Children1ArrivalAddon8, Children1ArrivalAddon9,
              Children1StayAddon, Children1StayAddon2, Children1StayAddon3, Children1StayAddon4, Children1StayAddon5, Children1StayAddon6, Children1StayAddon7, Children1StayAddon8, Children1StayAddon9,
              Children1DepartureAddon, Children1DepartureAddon2, Children1DepartureAddon3, Children1DepartureAddon4, Children1DepartureAddon5 ,Children1DepartureAddon6, Children1DepartureAddon7, Children1DepartureAddon8, Children1DepartureAddon9,

              Children2Price1, Children2Price2, Children2Price3, Children2Price4, Children2Price5, Children2Price6, Children2Price7, Children2Price8, Children2Price9,
              Children2ArrivalAddon, Children2ArrivalAddon2, Children2ArrivalAddon3, Children2ArrivalAddon4, Children2ArrivalAddon5, Children2ArrivalAddon6, Children2ArrivalAddon7, Children2ArrivalAddon8, Children2ArrivalAddon9,
              Children2StayAddon, Children2StayAddon2, Children2StayAddon3, Children2StayAddon4, Children2StayAddon5, Children2StayAddon6, Children2StayAddon7, Children2StayAddon8, Children2StayAddon9,
              Children2DepartureAddon, Children2DepartureAddon2, Children2DepartureAddon3, Children2DepartureAddon4, Children2DepartureAddon5, Children2DepartureAddon6, Children2DepartureAddon7, Children2DepartureAddon8, Children2DepartureAddon9
            )
    		    VALUES 
            (
              @DiscountProductNumber, @DateStamp, @RoomTypeNumber,
              dbo.GetDiscountedPrice (@AdultPrice1, @DiscountType, @DiscountValue, 1),
              dbo.GetDiscountedPrice (@AdultPrice2, @DiscountType, @DiscountValue, 2),
              dbo.GetDiscountedPrice (@AdultPrice3, @DiscountType, @DiscountValue, 3),
              dbo.GetDiscountedPrice (@AdultPrice4, @DiscountType, @DiscountValue, 4),
              dbo.GetDiscountedPrice (@AdultPrice5, @DiscountType, @DiscountValue, 5),
              dbo.GetDiscountedPrice (@AdultPrice6, @DiscountType, @DiscountValue, 6),
              dbo.GetDiscountedPrice (@AdultPrice7, @DiscountType, @DiscountValue, 7),
              dbo.GetDiscountedPrice (@AdultPrice8, @DiscountType, @DiscountValue, 8),
              dbo.GetDiscountedPrice (@AdultPrice9, @DiscountType, @DiscountValue, 9),

              dbo.GetDiscountedPrice (@AdultArrivalAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@AdultStayAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@AdultdepartureAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children1Price1, @DiscountType, @DiscountValue, 1),
              dbo.GetDiscountedPrice (@Children1Price2, @DiscountType, @DiscountValue, 2),
              dbo.GetDiscountedPrice (@Children1Price3, @DiscountType, @DiscountValue, 3),
              dbo.GetDiscountedPrice (@Children1Price4, @DiscountType, @DiscountValue, 4),
              dbo.GetDiscountedPrice (@Children1Price5, @DiscountType, @DiscountValue, 5),
              dbo.GetDiscountedPrice (@Children1Price6, @DiscountType, @DiscountValue, 6),
              dbo.GetDiscountedPrice (@Children1Price7, @DiscountType, @DiscountValue, 7),
              dbo.GetDiscountedPrice (@Children1Price8, @DiscountType, @DiscountValue, 8),
              dbo.GetDiscountedPrice (@Children1Price9, @DiscountType, @DiscountValue, 9),

              dbo.GetDiscountedPrice (@Children1ArrivalAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children1StayAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children1DepartureAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children2Price1, @DiscountType, @DiscountValue, 1),
              dbo.GetDiscountedPrice (@Children2Price2, @DiscountType, @DiscountValue, 2),
              dbo.GetDiscountedPrice (@Children2Price3, @DiscountType, @DiscountValue, 3),
              dbo.GetDiscountedPrice (@Children2Price4, @DiscountType, @DiscountValue, 4),
              dbo.GetDiscountedPrice (@Children2Price5, @DiscountType, @DiscountValue, 5),
              dbo.GetDiscountedPrice (@Children2Price6, @DiscountType, @DiscountValue, 6),
              dbo.GetDiscountedPrice (@Children2Price7, @DiscountType, @DiscountValue, 7),
              dbo.GetDiscountedPrice (@Children2Price8, @DiscountType, @DiscountValue, 8),
              dbo.GetDiscountedPrice (@Children2Price9, @DiscountType, @DiscountValue, 9),

              dbo.GetDiscountedPrice (@Children2ArrivalAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children2StayAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children2DepartureAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon9, @DiscountType, @DiscountValue, 0)
            )
          END
          ELSE IF @PaxType = 1 -- Adult
          BEGIN
	          INSERT INTO ProductPrice 
            (
              ProductNumber, DateStamp, RoomTypeNumber, 
              AdultPrice1, AdultPrice2, AdultPrice3, AdultPrice4, AdultPrice5, AdultPrice6, AdultPrice7, AdultPrice8, AdultPrice9,
              AdultArrivalAddon, AdultArrivalAddon2, AdultArrivalAddon3, AdultArrivalAddon4, AdultArrivalAddon5, AdultArrivalAddon6, AdultArrivalAddon7, AdultArrivalAddon8, AdultArrivalAddon9,
              AdultStayAddon, AdultStayAddon2, AdultStayAddon3, AdultStayAddon4, AdultStayAddon5, AdultStayAddon6, AdultStayAddon7, AdultStayAddon8, AdultStayAddon9,
              AdultdepartureAddon, AdultdepartureAddon2, AdultdepartureAddon3, AdultdepartureAddon4, AdultdepartureAddon5, AdultdepartureAddon6, AdultdepartureAddon7, AdultdepartureAddon8, AdultdepartureAddon9,

              Children1Price1, Children1Price2, Children1Price3, Children1Price4, Children1Price5, Children1Price6, Children1Price7, Children1Price8, Children1Price9,
              Children1ArrivalAddon, Children1ArrivalAddon2, Children1ArrivalAddon3, Children1ArrivalAddon4, Children1ArrivalAddon5, Children1ArrivalAddon6, Children1ArrivalAddon7, Children1ArrivalAddon8, Children1ArrivalAddon9,
              Children1StayAddon, Children1StayAddon2, Children1StayAddon3, Children1StayAddon4, Children1StayAddon5, Children1StayAddon6, Children1StayAddon7, Children1StayAddon8, Children1StayAddon9,
              Children1DepartureAddon, Children1DepartureAddon2, Children1DepartureAddon3, Children1DepartureAddon4, Children1DepartureAddon5 ,Children1DepartureAddon6, Children1DepartureAddon7, Children1DepartureAddon8, Children1DepartureAddon9,

              Children2Price1, Children2Price2, Children2Price3, Children2Price4, Children2Price5, Children2Price6, Children2Price7, Children2Price8, Children2Price9,
              Children2ArrivalAddon, Children2ArrivalAddon2, Children2ArrivalAddon3, Children2ArrivalAddon4, Children2ArrivalAddon5, Children2ArrivalAddon6, Children2ArrivalAddon7, Children2ArrivalAddon8, Children2ArrivalAddon9,
              Children2StayAddon, Children2StayAddon2, Children2StayAddon3, Children2StayAddon4, Children2StayAddon5, Children2StayAddon6, Children2StayAddon7, Children2StayAddon8, Children2StayAddon9,
              Children2DepartureAddon, Children2DepartureAddon2, Children2DepartureAddon3, Children2DepartureAddon4, Children2DepartureAddon5, Children2DepartureAddon6, Children2DepartureAddon7, Children2DepartureAddon8, Children2DepartureAddon9
            )
    		    VALUES 
            (
              @DiscountProductNumber, @DateStamp, @RoomTypeNumber,
              dbo.GetDiscountedPrice (@AdultPrice1, @DiscountType, @DiscountValue, 1),
              dbo.GetDiscountedPrice (@AdultPrice2, @DiscountType, @DiscountValue, 2),
              dbo.GetDiscountedPrice (@AdultPrice3, @DiscountType, @DiscountValue, 3),
              dbo.GetDiscountedPrice (@AdultPrice4, @DiscountType, @DiscountValue, 4),
              dbo.GetDiscountedPrice (@AdultPrice5, @DiscountType, @DiscountValue, 5),
              dbo.GetDiscountedPrice (@AdultPrice6, @DiscountType, @DiscountValue, 6),
              dbo.GetDiscountedPrice (@AdultPrice7, @DiscountType, @DiscountValue, 7),
              dbo.GetDiscountedPrice (@AdultPrice8, @DiscountType, @DiscountValue, 8),
              dbo.GetDiscountedPrice (@AdultPrice9, @DiscountType, @DiscountValue, 9),

              dbo.GetDiscountedPrice (@AdultArrivalAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultArrivalAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@AdultStayAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultStayAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@AdultdepartureAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@AdultdepartureAddon9, @DiscountType, @DiscountValue, 0),

              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,

              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0
            )
          END
          ELSE IF @PaxType = 2 -- Child1
          BEGIN
	          INSERT INTO ProductPrice 
            (
              ProductNumber, DateStamp, RoomTypeNumber, 
              Children1Price1, Children1Price2, Children1Price3, Children1Price4, Children1Price5, Children1Price6, Children1Price7, Children1Price8, Children1Price9,
              Children1ArrivalAddon, Children1ArrivalAddon2, Children1ArrivalAddon3, Children1ArrivalAddon4, Children1ArrivalAddon5, Children1ArrivalAddon6, Children1ArrivalAddon7, Children1ArrivalAddon8, Children1ArrivalAddon9,
              Children1StayAddon, Children1StayAddon2, Children1StayAddon3, Children1StayAddon4, Children1StayAddon5, Children1StayAddon6, Children1StayAddon7, Children1StayAddon8, Children1StayAddon9,
              Children1DepartureAddon, Children1DepartureAddon2, Children1DepartureAddon3, Children1DepartureAddon4, Children1DepartureAddon5 ,Children1DepartureAddon6, Children1DepartureAddon7, Children1DepartureAddon8, Children1DepartureAddon9,

              AdultPrice1, AdultPrice2, AdultPrice3, AdultPrice4, AdultPrice5, AdultPrice6, AdultPrice7, AdultPrice8, AdultPrice9,
              AdultArrivalAddon, AdultArrivalAddon2, AdultArrivalAddon3, AdultArrivalAddon4, AdultArrivalAddon5, AdultArrivalAddon6, AdultArrivalAddon7, AdultArrivalAddon8, AdultArrivalAddon9,
              AdultStayAddon, AdultStayAddon2, AdultStayAddon3, AdultStayAddon4, AdultStayAddon5, AdultStayAddon6, AdultStayAddon7, AdultStayAddon8, AdultStayAddon9,
              AdultdepartureAddon, AdultdepartureAddon2, AdultdepartureAddon3, AdultdepartureAddon4, AdultdepartureAddon5, AdultdepartureAddon6, AdultdepartureAddon7, AdultdepartureAddon8, AdultdepartureAddon9,

              Children2Price1, Children2Price2, Children2Price3, Children2Price4, Children2Price5, Children2Price6, Children2Price7, Children2Price8, Children2Price9,
              Children2ArrivalAddon, Children2ArrivalAddon2, Children2ArrivalAddon3, Children2ArrivalAddon4, Children2ArrivalAddon5, Children2ArrivalAddon6, Children2ArrivalAddon7, Children2ArrivalAddon8, Children2ArrivalAddon9,
              Children2StayAddon, Children2StayAddon2, Children2StayAddon3, Children2StayAddon4, Children2StayAddon5, Children2StayAddon6, Children2StayAddon7, Children2StayAddon8, Children2StayAddon9,
              Children2DepartureAddon, Children2DepartureAddon2, Children2DepartureAddon3, Children2DepartureAddon4, Children2DepartureAddon5, Children2DepartureAddon6, Children2DepartureAddon7, Children2DepartureAddon8, Children2DepartureAddon9
            )
    		    VALUES 
            (
              @DiscountProductNumber, @DateStamp, @RoomTypeNumber,
              dbo.GetDiscountedPrice (@Children1Price1, @DiscountType, @DiscountValue, 1),
              dbo.GetDiscountedPrice (@Children1Price2, @DiscountType, @DiscountValue, 2),
              dbo.GetDiscountedPrice (@Children1Price3, @DiscountType, @DiscountValue, 3),
              dbo.GetDiscountedPrice (@Children1Price4, @DiscountType, @DiscountValue, 4),
              dbo.GetDiscountedPrice (@Children1Price5, @DiscountType, @DiscountValue, 5),
              dbo.GetDiscountedPrice (@Children1Price6, @DiscountType, @DiscountValue, 6),
              dbo.GetDiscountedPrice (@Children1Price7, @DiscountType, @DiscountValue, 7),
              dbo.GetDiscountedPrice (@Children1Price8, @DiscountType, @DiscountValue, 8),
              dbo.GetDiscountedPrice (@Children1Price9, @DiscountType, @DiscountValue, 9),

              dbo.GetDiscountedPrice (@Children1ArrivalAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1ArrivalAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children1StayAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1StayAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children1DepartureAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children1DepartureAddon9, @DiscountType, @DiscountValue, 0),

              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,

              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0
            )
          END
          IF @PaxType = 3 -- Child2
          BEGIN
	          INSERT INTO ProductPrice 
            (
              ProductNumber, DateStamp, RoomTypeNumber, 
              Children2Price1, Children2Price2, Children2Price3, Children2Price4, Children2Price5, Children2Price6, Children2Price7, Children2Price8, Children2Price9,
              Children2ArrivalAddon, Children2ArrivalAddon2, Children2ArrivalAddon3, Children2ArrivalAddon4, Children2ArrivalAddon5, Children2ArrivalAddon6, Children2ArrivalAddon7, Children2ArrivalAddon8, Children2ArrivalAddon9,
              Children2StayAddon, Children2StayAddon2, Children2StayAddon3, Children2StayAddon4, Children2StayAddon5, Children2StayAddon6, Children2StayAddon7, Children2StayAddon8, Children2StayAddon9,
              Children2DepartureAddon, Children2DepartureAddon2, Children2DepartureAddon3, Children2DepartureAddon4, Children2DepartureAddon5, Children2DepartureAddon6, Children2DepartureAddon7, Children2DepartureAddon8, Children2DepartureAddon9,

              AdultPrice1, AdultPrice2, AdultPrice3, AdultPrice4, AdultPrice5, AdultPrice6, AdultPrice7, AdultPrice8, AdultPrice9,
              AdultArrivalAddon, AdultArrivalAddon2, AdultArrivalAddon3, AdultArrivalAddon4, AdultArrivalAddon5, AdultArrivalAddon6, AdultArrivalAddon7, AdultArrivalAddon8, AdultArrivalAddon9,
              AdultStayAddon, AdultStayAddon2, AdultStayAddon3, AdultStayAddon4, AdultStayAddon5, AdultStayAddon6, AdultStayAddon7, AdultStayAddon8, AdultStayAddon9,
              AdultdepartureAddon, AdultdepartureAddon2, AdultdepartureAddon3, AdultdepartureAddon4, AdultdepartureAddon5, AdultdepartureAddon6, AdultdepartureAddon7, AdultdepartureAddon8, AdultdepartureAddon9,

              Children1Price1, Children1Price2, Children1Price3, Children1Price4, Children1Price5, Children1Price6, Children1Price7, Children1Price8, Children1Price9,
              Children1ArrivalAddon, Children1ArrivalAddon2, Children1ArrivalAddon3, Children1ArrivalAddon4, Children1ArrivalAddon5, Children1ArrivalAddon6, Children1ArrivalAddon7, Children1ArrivalAddon8, Children1ArrivalAddon9,
              Children1StayAddon, Children1StayAddon2, Children1StayAddon3, Children1StayAddon4, Children1StayAddon5, Children1StayAddon6, Children1StayAddon7, Children1StayAddon8, Children1StayAddon9,
              Children1DepartureAddon, Children1DepartureAddon2, Children1DepartureAddon3, Children1DepartureAddon4, Children1DepartureAddon5 ,Children1DepartureAddon6, Children1DepartureAddon7, Children1DepartureAddon8, Children1DepartureAddon9
            )
    		    VALUES 
            (
              @DiscountProductNumber, @DateStamp, @RoomTypeNumber,
              dbo.GetDiscountedPrice (@Children2Price1, @DiscountType, @DiscountValue, 1),
              dbo.GetDiscountedPrice (@Children2Price2, @DiscountType, @DiscountValue, 2),
              dbo.GetDiscountedPrice (@Children2Price3, @DiscountType, @DiscountValue, 3),
              dbo.GetDiscountedPrice (@Children2Price4, @DiscountType, @DiscountValue, 4),
              dbo.GetDiscountedPrice (@Children2Price5, @DiscountType, @DiscountValue, 5),
              dbo.GetDiscountedPrice (@Children2Price6, @DiscountType, @DiscountValue, 6),
              dbo.GetDiscountedPrice (@Children2Price7, @DiscountType, @DiscountValue, 7),
              dbo.GetDiscountedPrice (@Children2Price8, @DiscountType, @DiscountValue, 8),
              dbo.GetDiscountedPrice (@Children2Price9, @DiscountType, @DiscountValue, 9),

              dbo.GetDiscountedPrice (@Children2ArrivalAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2ArrivalAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children2StayAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2StayAddon9, @DiscountType, @DiscountValue, 0),

              dbo.GetDiscountedPrice (@Children2DepartureAddon, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon2, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon3, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon4, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon5, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon6, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon7, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon8, @DiscountType, @DiscountValue, 0),
              dbo.GetDiscountedPrice (@Children2DepartureAddon9, @DiscountType, @DiscountValue, 0),

              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,

              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0
            )
          END
        END

        FETCH NEXT FROM db_cur INTO @DiscountProductNumber, @DiscountValue, @DiscountType, @PaxType
      END
      CLOSE db_cur
      DEALLOCATE db_cur
    END

    FETCH NEXT FROM db_cur_inserted INTO @ProductNumber, @DateStamp, @RoomTypeNumber,
      @AdultPrice1, @AdultPrice2, @AdultPrice3, @AdultPrice4, @AdultPrice5, @AdultPrice6, @AdultPrice7, @AdultPrice8, @AdultPrice9,
      @Children1Price1, @Children1Price2, @Children1Price3, @Children1Price4, @Children1Price5, @Children1Price6, @Children1Price7, @Children1Price8, @Children1Price9,
      @Children2Price1, @Children2Price2, @Children2Price3, @Children2Price4, @Children2Price5, @Children2Price6, @Children2Price7, @Children2Price8, @Children2Price9,
      @AdultArrivalAddon, @AdultArrivalAddon2, @AdultArrivalAddon3, @AdultArrivalAddon4, @AdultArrivalAddon5, @AdultArrivalAddon6, @AdultArrivalAddon7, @AdultArrivalAddon8, @AdultArrivalAddon9,
      @AdultStayAddon, @AdultStayAddon2, @AdultStayAddon3, @AdultStayAddon4, @AdultStayAddon5, @AdultStayAddon6, @AdultStayAddon7, @AdultStayAddon8, @AdultStayAddon9,
      @AdultDepartureAddon, @AdultDepartureAddon2, @AdultDepartureAddon3, @AdultDepartureAddon4, @AdultDepartureAddon5, @AdultDepartureAddon6, @AdultDepartureAddon7, @AdultDepartureAddon8, @AdultDepartureAddon9,
      @Children1ArrivalAddon, @Children1ArrivalAddon2, @Children1ArrivalAddon3, @Children1ArrivalAddon4, @Children1ArrivalAddon5, @Children1ArrivalAddon6, @Children1ArrivalAddon7, @Children1ArrivalAddon8, @Children1ArrivalAddon9,
      @Children1StayAddon, @Children1StayAddon2, @Children1StayAddon3, @Children1StayAddon4, @Children1StayAddon5, @Children1StayAddon6, @Children1StayAddon7, @Children1StayAddon8, @Children1StayAddon9,
      @Children1DepartureAddon, @Children1DepartureAddon2, @Children1DepartureAddon3, @Children1DepartureAddon4, @Children1DepartureAddon5, @Children1DepartureAddon6, @Children1DepartureAddon7, @Children1DepartureAddon8, @Children1DepartureAddon9,
      @Children2ArrivalAddon, @Children2ArrivalAddon2, @Children2ArrivalAddon3, @Children2ArrivalAddon4, @Children2ArrivalAddon5, @Children2ArrivalAddon6, @Children2ArrivalAddon7, @Children2ArrivalAddon8, @Children2ArrivalAddon9,
      @Children2StayAddon, @Children2StayAddon2, @Children2StayAddon3, @Children2StayAddon4, @Children2StayAddon5, @Children2StayAddon6, @Children2StayAddon7, @Children2StayAddon8, @Children2StayAddon9,
      @Children2DepartureAddon, @Children2DepartureAddon2, @Children2DepartureAddon3, @Children2DepartureAddon4, @Children2DepartureAddon5, @Children2DepartureAddon6, @Children2DepartureAddon7, @Children2DepartureAddon8, @Children2DepartureAddon9
  END

  CLOSE db_cur_inserted
  DEALLOCATE db_cur_inserted
END