
CREATE PROCEDURE [dbo].[GetPriceProduct] @PriceProduct MONEY OUTPUT, @PriceProductArrival MONEY OUTPUT, @VatProduct MONEY OUTPUT, @VatProductArrival MONEY OUTPUT
  , @SegmentNumber INT, @PointofSaleNumber INT, @DayProduct INT, @ProductNumber INT, @ArrivalDate DATETIME, @DepartureDate DATETIME
  , @BookedTypeNumber INT, @NumberOfRooms INT, @AdultPax INT, @Child1Pax INT, @Child2Pax INT,  @VatPercent REAL AS
SET NOCOUNT ON
/*
--nb20150306 CR083666 GetRooms SP: Description Wrong Addon Vat, actual wrong TotalPrice and Addon calculation when PriceOverwritten and AddonIfPriceOverwritten setting = true 
--nb20140804 CR075005 Wrong VAT on GetRooms caused by addon fixed?
--nb20091104 CR010105 Wrong Vat on Meeting lines with price overwritten and 200 adults
--nb20090326 Wrong price on meeting line and price overwritten  
  nb20090323 #CR006651 DayProducts Price / Type
  nb20071130 substract Addon when price overwritten (room lines)
  nb20070809 NightProduct overwritten price on several days fixed 
  nb20070626 DayProduct Overwritten price on fixed price product fixed by introducing a temp var in the call to ProductPriceDay SP
  nb20070330 DayProduct when priceoverwrite on meeting product 
  nb20070118 DayProduct variable price products for several days fixed. dependancy in getHalls revision from today
  nb20061130 DayProduct fix from 1012 was not good enough extended today 
  nb20061123 Take care of devide by 0 when Pax=0
  NB20061012 On Day Wrong var used to distinuish between PriceOverwritten or not
  NB20060118 On Rooms wrong amount in VatProductArrival fix /NumberOfRooms
  NB20051230: On Rooms when price overwritten missing lines bug fixed
  NB20051220: On Day products when several lines and Price overwrite bug fixed
  NB20050823: Calculate Product Vat (Addon and right formula)
  NB20050622: Created
  NOTE: Calculates the Product prices and Vat amount of those  
  STATUS: UNDER CONSTRUCTION
  @DayProduct: 0- Overnight; 1-Day; 2-Plus
*/
DECLARE @PlusProduct BIT
, @DiscountPercentPackage REAL
, @PriceProductAddon MONEY 
, @VatProductAddon MONEY
, @PricePackage MONEY
, @PricePackageArrival MONEY
, @VatPackage MONEY
, @VatPackageArrival MONEY
, @ProductName VARCHAR(50) 
, @PriceOverwrite MONEY 
, @TempPriceOverwrite MONEY 
, @AddonIfPriceOverwritten BIT
SET @DiscountPercentPackage = 0 --TODO: Where do you get the value from?
IF ISNULL(@PriceProductArrival, 0) = 0
begin
  set @PriceOverwrite = 0 
  set @TempPriceOverwrite = 0 
end  
else 
begin
  set @PriceOverwrite = @PriceProductArrival
  set @TempPriceOverwrite = @PriceProductArrival
end
IF (@DayProduct <> 1)
BEGIN
  select top 1 @ProductName= 'Overnight Product = '+ProductName from Products WITH (nolock) where ProductNumber=@ProductNumber
  PRINT '------[GetPriceProduct] '+ @ProductName
  --Get Product Price (Addon)
  IF  @DayProduct=2  
  BEGIN
    SET @PlusProduct= 1
    PRINT '+ Product'
  END
  ELSE 
    SET @PlusProduct= 0
    SET @PricePackage = @PriceProduct
  IF @PriceProduct > 0
  BEGIN
    SET @PriceProductArrival = @PricePackage 
    SET @PriceProduct = @PricePackage * @NumberOfRooms
  END
/*DEBUG BEGIN nb20060204 - do not remove
  DECLARE @Msg VARCHAR(2000) 
  PRINT 'Call SP ProductPrices begin --------------------------------'
  SET @Msg = 'DECLARE @OldProductNumber int, @StartDate datetime, @EndDate datetime, @OldRoomTypeNumber int, @NumberOfRooms int, @AdultPax int, @Child1Pax int, @Child2Pax int, @CalcTotalPrice real, @CalcArrivalPrice real, @AddonAmount smallmoney, @AddonVatAmount smallmoney, @PlusProduct BIT, @OverrideNameListSetting INT, @ACustomerNumber INT'+CHAR(13)
  IF ISNULL( @ProductNumber, -1) = -1 
    SET @Msg = @Msg+'SET @OldProductNumber = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @OldProductNumber = '+CONVERT(VARCHAR,@ProductNumber)+CHAR(13)
  SET @Msg = @Msg + 'SET @StartDate = CONVERT(DATETIME, '''+CONVERT(VARCHAR, ISNULL(@ArrivalDate, -1), 112)+''' , 112)'+CHAR(13)
  SET @Msg = @Msg + 'SET @EndDate = CONVERT(DATETIME, '''+CONVERT(VARCHAR, ISNULL(@DepartureDate, -1), 112)+''' , 112)'+CHAR(13)
  IF ISNULL( @BookedTypeNumber, -1) = -1 
    SET @Msg = @Msg+'SET @OldRoomTypeNumber = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg+'SET @OldRoomTypeNumber = '+CONVERT(VARCHAR, @BookedTypeNumber)+CHAR(13)
  IF ISNULL( @NumberOfRooms, -1) = -1 
    SET @Msg = @Msg+'SET @NumberOfRooms = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @NumberOfRooms = '+CONVERT(VARCHAR,@NumberOfRooms)+CHAR(13)
  IF ISNULL( @AdultPax, -1) = -1 
    SET @Msg = @Msg+'SET @AdultPax = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @AdultPax = '+CONVERT(VARCHAR,@AdultPax)+CHAR(13)
  IF ISNULL( @Child1Pax, -1) = -1 
    SET @Msg = @Msg+'SET @Child1Pax = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @Child1Pax = '+CONVERT(VARCHAR,@Child1Pax)+CHAR(13)
  IF ISNULL( @Child2Pax, -1) = -1 
    SET @Msg = @Msg+'SET @Child2Pax = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @Child2Pax = '+CONVERT(VARCHAR,@Child2Pax)+CHAR(13)
  IF ISNULL( @PriceProduct, -1) = -1 
    SET @Msg = @Msg+'SET @CalcTotalPrice = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @CalcTotalPrice = '+CONVERT(VARCHAR,@PriceProduct)+CHAR(13)
  IF ISNULL( @PriceProductArrival, -1) = -1 
    SET @Msg = @Msg+'SET @CalcArrivalPrice = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @CalcArrivalPrice = '+CONVERT(VARCHAR,@PriceProductArrival)+CHAR(13)
  IF ISNULL( @PriceProductAddon, -1) = -1 
    SET @Msg = @Msg+'SET @AddonAmount = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @AddonAmount = '+CONVERT(VARCHAR,@PriceProductAddon)+CHAR(13)
  IF ISNULL( @VatProductAddon, -1) = -1 
    SET @Msg = @Msg+'SET @AddonVatAmount = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @AddonVatAmount = '+CONVERT(VARCHAR,@VatProductAddon)+CHAR(13)
  IF ISNULL( @PlusProduct, -1) = -1 
    SET @Msg = @Msg+'SET @PlusProduct = NULL'+CHAR(13)
  ELSE
    SET @Msg = @Msg + 'SET @PlusProduct = '+CONVERT(VARCHAR,@PlusProduct)+CHAR(13)
  SET @Msg = @Msg+'EXEC ProductPrices @OldProductNumber, @StartDate, @EndDate, @OldRoomTypeNumber, @NumberOfRooms, @AdultPax, @Child1Pax, @Child2Pax, @CalcTotalPrice OUTPUT, @CalcArrivalPrice OUTPUT, @AddonAmount OUTPUT, @AddonVatAmount OUTPUT, @PlusProduct'+ CHAR(13)
  SET @Msg = @Msg + 'PRINT CONVERT(varchar, @CalcTotalPrice) --' + CONVERT(varchar, ISNULL(@PriceProduct, -1)) + CHAR(13)
  SET @Msg = @Msg + 'PRINT CONVERT(varchar, @CalcArrivalPrice) --' + CONVERT(varchar, ISNULL(@PriceProductArrival, -1))+ CHAR(13)
  SET @Msg = @Msg + 'PRINT CONVERT(varchar, @AddonAmount) --' + CONVERT(varchar, ISNULL(@PriceProductAddon, -1))+ CHAR(13)
  SET @Msg = @Msg + 'PRINT CONVERT(varchar, @AddonVatAmount) --' + CONVERT(varchar, ISNULL(@VatProductAddon, -1)) + CHAR(13)
  PRINT @Msg
  PRINT 'Call SP ProductPrices end --------------------------------'
DEBUG END*/

  EXEC ProductPrices @ProductNumber, @ArrivalDate, @DepartureDate, @BookedTypeNumber, @NumberOfRooms, @AdultPax, @Child1Pax, @Child2Pax
    , @PriceProduct OUTPUT, @PriceProductArrival OUTPUT, @PriceProductAddon OUTPUT, @VatProductAddon OUTPUT, @PlusProduct
  IF @PricePackage > 0
  BEGIN
    SET @PriceProductArrival = @PricePackage 
    SET @PriceProduct = @PricePackage * @NumberOfRooms
    SET @PricePackage = @PriceProduct 
  END
--  PRINT 'PriceProduct1: ' + Convert(VARCHAR, @PriceProduct) 
  --Get Package Part of the Product
  EXEC GetPricePackagePartProduct @ProductNumber, @ArrivalDate, @DepartureDate, @BookedTypeNumber, @NumberOfRooms, @AdultPax, @Child1Pax
    , @Child2Pax, @DiscountPercentPackage, @PricePackage OUTPUT, @VatPackage OUTPUT
  --Get Package Part of the Product only for Arrival
  --PRINT '--Price Package Arrival------------'
  EXEC GetPricePackagePartProduct @ProductNumber, @ArrivalDate, @ArrivalDate, @BookedTypeNumber, 1, @AdultPax, @Child1Pax
  , @Child2Pax, @DiscountPercentPackage, @PricePackageArrival OUTPUT, @VatPackageArrival OUTPUT, 1
/*
print 'procedure GetPriceProduct begin -----------------------'
  IF @VatProductAddon > 0 
    print 'SET @VatProduct= (@PriceProduct-@PricePackage + (@PriceProductAddon*@NumberOfRooms))*(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackage + @VatProductAddon '
  ELSE IF @PriceProductAddon <> 0 and @PriceOverwrite > 0 
    print 'SET @VatProduct= (@PriceProduct-@PricePackage)*(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackage '
  ELSE 
    print 'SET @VatProduct= (@PriceProduct-@PricePackage)*(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackage '
print '@PriceProduct: ' + convert(varchar, @PriceProduct)
print '@PricePackage: ' + convert(varchar, @PricePackage)
print '@PriceProductAddon: ' + convert(varchar, @PriceProductAddon)
print '@VatPercent: ' + convert(varchar, @VatPercent)
print '@VatPackage: ' + convert(varchar, @VatPackage)
print '@VatProductAddon: ' + convert(varchar, @VatProductAddon)
print '@NumberOfRooms: ' + convert(varchar, @NumberOfRooms)
print '@PriceOverwrite: ' + convert(varchar, @PriceOverwrite)
print '*VatEquation: ' + convert(varchar, (1-(1/convert(float,((@VatPercent/100)+1)))))
print 'procedure GetPriceProduct end -----------------------'
*/
  --nb20070809 NightProduct overwritten price on several days fixed 
  if @PriceOverwrite > 0
  BEGIN 
    SET @PriceProduct = @PriceProduct*datediff(dy, convert(datetime, @ArrivalDate, 122), convert(datetime, @DepartureDate, 122))
    SELECT @AddonIfPriceOverwritten = dbo.GetHotelSetupKeyValue('AddonIfPriceOverwritten', -1)
    IF ISNULL(@AddonIfPriceOverwritten,0)=0 SET @AddonIfPriceOverwritten=0
    IF (@AddonIfPriceOverwritten = 1)
      SET @PriceProduct = @PriceProduct + @PriceProductAddon*@NumberOfRooms
  END
  IF @VatProductAddon > 0 
    SET @VatProduct= (@PriceProduct-@PricePackage + (@PriceProductAddon*@NumberOfRooms))*(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackage + @VatProductAddon 
  ELSE 
    SET @VatProduct= (@PriceProduct-@PricePackage)*(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackage
  IF @PricePackageArrival < @PriceProductArrival
    SET @VatProductArrival= (@PriceProductArrival-@PricePackageArrival)*(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackageArrival
  ELSE
    SET @VatProductArrival= @VatPackageArrival

END
ELSE
BEGIN
  PRINT '------[GetPriceProduct] - Day Product'
  DECLARE 
    @BillTextProduct VARCHAR(50)
  , @BillTextAddOn VARCHAR(50)
  , @PackageNumber INT
  , @EnvironmentFee MONEY
  , @FixedPrice BIT
  , @VATProductDummy BIT
  , @SpecifiedDepartureAddOn BIT
  , @CurrentDate DATETIME
  , @PriceProductDay MONEY
  , @PricePackageDay MONEY
  , @VatPackageDay MONEY
  SET @CurrentDate = @ArrivalDate
  SET @PricePackage = @PriceProduct
  SET @PriceProduct = 0  
  SET @PriceProductArrival = 0
--PRINT CONVERT(VARCHAR,@PriceOverwrite)
  SET @VatProduct= 0
  SET @PricePackage = 0
  SET @VatPackage= 0
  WHILE @CurrentDate <= @DepartureDate
  BEGIN
    SET @PriceProductAddon= 0
    SET @PriceProductDay= 0
    SET @PricePackageDay=0 --if not reset then act as price overwritted
/*
PRINT 'DECLARE @ProductNumber INT'
PRINT ', @ArrivalDate DATETIME'
PRINT ', @DepartureDate DATETIME'
PRINT ', @CurrentDate DATETIME'
PRINT ', @NumberOfRooms INT, @AdultPax INT'
PRINT ', @Child1Pax INT'
PRINT ', @Child2Pax INT'
PRINT ', @PriceProductAddon MONEY '
PRINT ', @BillTextProduct VARCHAR(50)'
PRINT ', @BillTextAddOn VARCHAR(50)'
PRINT ', @PriceProductDay MONEY'
PRINT ', @PackageNumber INT'
PRINT ', @EnvironmentFee MONEY'
PRINT ', @FixedPrice BIT'
PRINT ', @VATProductDummy BIT'
PRINT ', @SpecifiedDepartureAddOn BIT'
PRINT 'SET @ProductNumber= '+CONVERT(VARCHAR,  @ProductNumber)
PRINT 'SET @ArrivalDate= CONVERT(DATETIME, '''+CONVERT(VARCHAR,  @ArrivalDate, 112)+''')'
PRINT 'SET @DepartureDate= CONVERT(DATETIME, '''+CONVERT(VARCHAR,  @DepartureDate , 112)+''')'
PRINT 'SET @CurrentDate= CONVERT(DATETIME, '''+CONVERT(VARCHAR,  @CurrentDate , 112)+''')'
PRINT 'SET @NumberOfRooms= '+CONVERT(VARCHAR,  @NumberOfRooms)
PRINT 'SET @AdultPax= '+CONVERT(VARCHAR,  @AdultPax)
PRINT 'SET @Child1Pax= '+CONVERT(VARCHAR,  @Child1Pax) 
PRINT 'SET @Child2Pax= '+CONVERT(VARCHAR,  @Child2Pax)
PRINT 'SET @PriceProductAddon= '+CONVERT(VARCHAR, ISNULL(@PriceProductAddon,0))
PRINT 'SET @BillTextProduct= '+CONVERT(VARCHAR,  ISNULL(@BillTextProduct, 0))
PRINT 'SET @BillTextProduct= '+CONVERT(VARCHAR,  ISNULL(@BillTextAddOn, 0))
PRINT 'SET @PriceProductDay= '+CONVERT(VARCHAR, ISNULL(@PriceProductDay, 0) )
PRINT 'SET @PackageNumber= '+CONVERT(VARCHAR,  ISNULL(@PackageNumber, 0) )
PRINT 'SET @EnvironmentFee= '+CONVERT(VARCHAR, ISNULL(@EnvironmentFee, 0) )
PRINT 'SET @FixedPrice= '+CONVERT(VARCHAR,  ISNULL(@FixedPrice, 0) )
PRINT 'SET @VATProductDummy= '+CONVERT(VARCHAR,  ISNULL(@VATProductDummy,0))
PRINT 'SET @SpecifiedDepartureAddOn= '+CONVERT(VARCHAR,  ISNULL(@SpecifiedDepartureAddOn,0) )
PRINT 'EXEC ProductPricesDay @ProductNumber, @ArrivalDate, @DepartureDate, @CurrentDate, 0, @NumberOfRooms, @AdultPax, @Child1Pax, @Child2Pax, @PriceProductAddon OUTPUT, @BillTextProduct OUTPUT, @BillTextAddOn OUTPUT, @PriceProductDay OUTPUT, @PackageNumber OUTPUT, @EnvironmentFee OUTPUT, @FixedPrice OUTPUT, @VATProductDummy OUTPUT,  @SpecifiedDepartureAddOn OUTPUT'

*/
    --EXEC ProductPricesDay @ProductNumber, @ArrivalDate, @DepartureDate, @CurrentDate, 0, @NumberOfRooms, @AdultPax, @Child1Pax, @Child2Pax, @PriceProductAddon OUTPUT, @BillTextProduct OUTPUT, @BillTextAddOn OUTPUT, @PriceProductDay OUTPUT, @PackageNumber OUTPUT, @EnvironmentFee OUTPUT, @FixedPrice OUTPUT, @VATProductDummy OUTPUT,  @SpecifiedDepartureAddOn OUTPUT
    --  nb20070330 DayProduct when priceoverwrite on meeting product 
    EXEC ProductPricesDay @ProductNumber, @ArrivalDate, @DepartureDate, @CurrentDate, @BookedTypeNumber, @NumberOfRooms, @AdultPax, @Child1Pax, @Child2Pax, @PriceProductAddon OUTPUT, @BillTextProduct OUTPUT, @BillTextAddOn OUTPUT, 
      @TempPriceOverwrite OUTPUT, @PackageNumber OUTPUT, @EnvironmentFee OUTPUT, @FixedPrice OUTPUT, @VATProductDummy OUTPUT,  @SpecifiedDepartureAddOn OUTPUT
  
    IF @PackageNumber > 0 
      EXEC GetPricePackage @PackageNumber, @CurrentDate, @ProductNumber, 0, @NumberOfRooms, @AdultPax, @Child1Pax, @Child2Pax, 0, @PricePackageDay OUTPUT, @VatPackageDay OUTPUT
    ELSE
    BEGIN
      SET @PricePackageDay= 0
      SET @VatPackageDay= 0
    END
    IF @PriceOverwrite > 0 
      SET @PriceProductDay = @PriceOverwrite
    ELSE
      SET @PriceProductDay = @TempPriceOverwrite

/*
PRINT '@PriceOverwrite='+ CONVERT(VARCHAR, @PriceOverwrite)
PRINT '@PriceProductDay='+ CONVERT(VARCHAR, @PriceProductDay)
PRINT '@NumberOfRooms='+ CONVERT(VARCHAR, @NumberOfRooms)
*/
    IF @CurrentDate = @ArrivalDate
    BEGIN
      IF (SELECT TOP 1 FixedPrice FROM Products WITH (NOLOCK) WHERE ProductNumber=@ProductNumber) = 1
     --nb20061123 Take care of devide by 0 when Pax=0
      OR @AdultPax + @Child1Pax + @Child2Pax = 0
      BEGIN
        SET @PriceProductArrival = @PriceProductDay/@NumberOfRooms
        SET @PricePackageArrival = @PricePackageDay/@NumberOfRooms
        SET @VatPackageArrival = @VatPackageDay/@NumberOfRooms
      END
      /*
      ELSE
      BEGIN
        SET @PriceProductArrival = @PriceProductDay / (@AdultPax + @Child1Pax + @Child2Pax)
        SET @PricePackageArrival = @PricePackageDay / (@AdultPax + @Child1Pax + @Child2Pax)
        SET @VatPackageArrival = @VatPackageDay / (@AdultPax + @Child1Pax + @Child2Pax)
      END
      */--nb20090326 Wrong price when meeting line and price overwritten
/*      ELSE IF @PriceOverwrite = 0 
      BEGIN
        SET @PriceProductArrival = @PriceProductDay / (@AdultPax + @Child1Pax + @Child2Pax)
        SET @PricePackageArrival = @PricePackageDay / (@AdultPax + @Child1Pax + @Child2Pax)
        SET @VatPackageArrival = @VatPackageDay / (@AdultPax + @Child1Pax + @Child2Pax)
      END
*/--nb20091104 Wrong Vat on Meeting lines with price overwritten and 200 adults
      ELSE IF @PriceOverwrite <> 0 
      BEGIN
        SET @PriceProductArrival = @PriceProductDay --/ (@AdultPax + @Child1Pax + @Child2Pax)
        SET @PricePackageArrival = @PricePackageDay / (@AdultPax + @Child1Pax + @Child2Pax)
        SET @VatPackageArrival = @VatPackageDay / (@AdultPax + @Child1Pax + @Child2Pax)
      END

      ELSE 
      BEGIN
        SET @PriceProductArrival = @PriceProductDay 
        SET @PricePackageArrival = @PricePackageDay 
        SET @VatPackageArrival = @VatPackageDay 
      END

    END
--PRINT '@PricePackageDay= '+CONVERT(VARCHAR,@PricePackageDay)
--PRINT '@VatPackageDay= '+CONVERT(VARCHAR,@VatPackageDay)
    /*
    SET @PriceProduct = @PriceProduct + @PriceProductDay
    SET @PricePackage = @PricePackage + @PricePackageDay
    SET @VatPackage = @VatPackage + @VatPackageDay
    */--nb20090326 Wrong price when meeting line and price overwritten
    IF (SELECT TOP 1 FixedPrice FROM Products WITH (NOLOCK) WHERE ProductNumber=@ProductNumber) = 1
      OR @AdultPax + @Child1Pax + @Child2Pax = 0 OR  @PriceOverwrite = 0 
    BEGIN
      SET @PriceProduct = @PriceProduct + @PriceProductDay
      SET @PricePackage = @PricePackage + @PricePackageDay
      SET @VatPackage = @VatPackage + @VatPackageDay
    END
    ELSE
    BEGIN
      SET @PriceProduct = @PriceProduct + @PriceProductDay*(@AdultPax + @Child1Pax + @Child2Pax)
/*
        SET @PricePackage = @PricePackage + @PricePackageDay*(@AdultPax + @Child1Pax + @Child2Pax)
        SET @VatPackage = @VatPackage + @VatPackageDay*(@AdultPax + @Child1Pax + @Child2Pax)
*/
--nb20091104 Wrong Vat on Meeting lines with price overwritten and 200 adults
      IF (SELECT TOP 1 FixedPrice FROM Products WITH (NOLOCK) WHERE ProductNumber=@ProductNumber) <> 1
        OR @AdultPax + @Child1Pax + @Child2Pax = 0 OR  @PriceOverwrite <> 0 
      BEGIN
        SET @PricePackage = @PricePackage + @PricePackageDay
        SET @VatPackage = @VatPackage + @VatPackageDay
      END
      ELSE
      BEGIN
        SET @PricePackage = @PricePackage + @PricePackageDay*(@AdultPax + @Child1Pax + @Child2Pax)
        SET @VatPackage = @VatPackage + @VatPackageDay*(@AdultPax + @Child1Pax + @Child2Pax)
      END

    END

    SET @CurrentDate = DATEADD(Day, 1, @CurrentDate)
  END
  /*
  --Calculate the Vat of the Product Part
  SET @VatProduct= (@PriceProduct-@PricePackage)*@VatPercent/100 + @VatPackage
--  IF @PricePackageArrival < @PriceProductArrival
  SET @VatProductArrival= (@PriceProductArrival-@PricePackageArrival)*@VatPercent/100 + @VatPackageArrival
--  ELSE
--    SET @VatProductArrival= @VatPackageArrival
  */--nb20050823
  --Calculate the Vat of the Product Part
  SET @VatProduct= (@PriceProduct-@PricePackage) *(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackage
  SET @VatProductArrival= (@PriceProductArrival-@PricePackageArrival) *(1-(1/convert(float,((@VatPercent/100)+1)))) + @VatPackageArrival

END
/*
  PRINT '--Price Product------------'
  PRINT '@PriceProduct='+CONVERT(VARCHAR, @PriceProduct)
  PRINT '@PriceProductArrival='+CONVERT(VARCHAR, @PriceProductArrival)
  PRINT '@PriceProductAddon='+CONVERT(VARCHAR, @PriceProductAddon)
  PRINT '@VatProductAddon='+CONVERT(VARCHAR, @VatProductAddon)
  PRINT '--Price Package------------'
  PRINT '@PricePackage='+CONVERT(VARCHAR, @PricePackage)
  PRINT '@PricePackageArrival='+CONVERT(VARCHAR, @PricePackageArrival)
  PRINT '--Vat Package ------------'
  PRINT '@VatPackage='+CONVERT(VARCHAR, @VatPackage)
  PRINT '@VatPackageArrival='+CONVERT(VARCHAR, @VatPackageArrival)
  PRINT '--Result------------'
  PRINT '@VatPercent='+CONVERT(VARCHAR, @VatPercent)
  PRINT '@VatProduct='+CONVERT(VARCHAR, @VatProduct)
  PRINT '@VatProductArrival='+CONVERT(VARCHAR, @VatProductArrival)
*/