CREATE PROCEDURE dbo.CalcProductPrice (@PriceOverWritten integer, @FirstPrice integer, @Adults integer, @AddonIfPriceOverwritten integer, /*PARAMETERS FOR ProductPricesDay*/@OldProductNumber int,  @ArrivalDate datetime, @DepartureDate datetime, @PriceDate datetime, @OldRoomTypeNumber int, @NumberOfRooms int, @AdultPax int, @Child1Pax int, @Child2Pax int, @Addon smallmoney 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, /*PARAMETERS FOR CalcPacketPrice*/@DayProduct Bit, @RoomtypeNumber int, @DateStamp Char(8), @ProductNumber int, @Adult int, @Children1 int, @Children2 int, @PackagePrice Float OUTPUT, @VatByPacketValue Float Output) AS
SET NOCOUNT ON

/*Set @ProductStartDate = Convert (DATETIME, @ArrivalDate)+@Day2-1
Set @ProductEndDate   = Convert (DATETIME, @ArrivalDate)+@Day3-1*/

exec ProductPricesDay @ProductNumber,@ArrivalDate,@DepartureDate, @PriceDate, @OldRoomTypeNumber, @NumberOfRooms, @AdultPax, @Child1Pax, @Child2Pax, @Addon OUTPUT, @BillTextProduct OUTPUT, @BillTextAddOn OUTPUT, @CalcPriceDay OUTPUT, @PacketNumber OUTPUT, @EnvironmentFee OUTPUT, @FixedPrice OUTPUT, @VATProduct OUTPUT, @SpecifiedDepartureAddOn OUTPUT, @NameListSetting, @OnePersonPaysForAll -- new imp @NameListSetting+@OnePersonPaysForAll
--ProductPricesDay @ProductNumber2,@ProductStartDate,@ProductEndDate, @ProductPriceDate, @AllocatedTypeNumber, @NumberOfRooms, @PaysAdults, @PaysChildren1, @PaysChildren2, @Addon2 OUTPUT, @BillTextProduct OUTPUT, @BillTextAddOnProduct OUTPUT, @PriceProduct2 OUTPUT, @PacketNumber OUTPUT, @EnviromentFee OUTPUT, @FixedPrice OUTPUT, @VATProduct OUTPUT, @SpecifiedDepartureAddOn OUTPUT, @NameListSetting, @OnePersonPaysForAll -- new imp @NameListSetting+@OnePersonPaysForAll
if (@PriceOverWritten=1) 
    Begin
    if (@ArrivalDate <> @DepartureDate)
    begin
        Set @CalcPriceDay = @FirstPrice * @NumberOfRooms
        if @NameListSetting = 1
            if @OnePersonPaysForAll = 0 SET @CalcPriceDay = @CalcPriceDay * (@Adults + @Children1+ @Children2)
    end
    if  (@AddonIfPriceOverwritten=0)
        SET @Addon = 0
end
exec CalcPacketPrice 0, @OldRoomTypeNumber, @DateStamp, @PacketNumber, @ProductNumber,@AdultPax, @Child1Pax, @Child2Pax,@PackagePrice OUTPUT, @VatByPacketValue OUTPUT, @NameListSetting, @OnePersonPaysForAll -- new imp @NameListSetting+@OnePersonPaysForAll

