CREATE PROCEDURE [dbo].[MisStoreExtrasAndCalcDiscount] 
	@OrderBookBudgetCalcDiscount BIT, 
	@DiscountAsNettoPrice BIT, 
	@ChargeDiscountAsProduct BIT,
	@DiscountVatValueWare FLOAT,  --VAT rate for the discount
	@Room_HallType tinyint, 
	@ReferenceNumber int, 
	@FolioNumber int, 
	@DateStamp char(8), 
	@SegmentNumber int, 
	@PointOfSaleNumber int, 
	@RoomTypeNumber int, 
	@CampaignCode int, 
	@ProjectCode int, 
	@StaffID int, 
	@OwnerReservation bit, 
	@DiscountAccountNumber INT
AS
SET NOCOUNT ON

/*
  SG 20210224: New fields: BookedWareCount, ActualWareCount
  SG 20200609: Get status from reservation instead of parameter
  SG 20200514: Added @WareType and @WareNumber to MIS
  SG 20191209: MenuWare: Prices * Pieces - when not in percent
  SG 20191128: MenuWare: Prices * Pieces
  SG 20181025: HotelCustomerNumber from Arrangement in order to get Mixed Resources correct
  KJ 20150105: Bug: Fix for "Error when post of more than one pieces of a menu ware not in percent". Case #CR081859
  KJ 20140624: Ext: Menu ware split in whole amount. Req #1561
  SG 20130129, CR 051930: No discount was calculated when VAT=0
  OF 20110913: New for extras and calculating of discount
*/

Declare @VatValueWareText varchar(5)

Declare @VatValueIndex0 Float
Declare @VatValueIndex1 Float
Declare @VatValueIndex2 Float
Declare @VatValueIndex3 Float
Declare @VatValueIndex4 Float
Declare @VatValueIndex5 Float

Declare @Price money
Declare @VatOfPrice money
Declare @AccountNumber int
Declare @DepartmentNumber smallint
Declare @MisType int
Declare @WarePayment smallint
Declare @WareGroupNumber int
Declare @WareNumber int
Declare @WareType int
Declare @WareName varchar(50)
Declare @GuestNumber int
Declare @ValueTypeExtra int
DECLARE @HandleAsMenuWare BIT
DECLARE @MenuVatValueNumber INT
DECLARE @MenuProcentage MONEY
DECLARE	@MenuWareResultAccountNumber INT
DECLARE @MenuWarePrice FLOAT
DECLARE @MenuWarePriceVat FLOAT
Declare @MenuVatValueWare FLOAT
DECLARE @InPercent BIT

DECLARE @AllDiscountRate FLOAT
DECLARE @DiscountRate FLOAT
DECLARE @AddressType INT
DECLARE @tmpPrice MONEY
DECLARE @DiscountPrice MONEY
DECLARE @DiscountPriceVat MONEY
DECLARE @SplitBillNumber INT
Declare @Text varchar(100)
Declare @ResultPriceVat MONEY
DECLARE @Pieces INT
Declare @HotelCustomerNumberFromArr int
Declare @Status smallint

SET @VatValueIndex0 = 0

Select @VatValueWareText = KeyValue from HotelSetUp WITH (NOLOCK)  Where  SearchKey='VATValue1'
if (charindex(',',@VatValueWareText)>0)
  SET @VatValueWareText = STUFF(@VatValueWareText, charindex(',',@VatValueWareText) ,1, '.')

SET @VatValueIndex1 = CONVERT(Float,@VatValueWareText) 

Select @VatValueWareText = KeyValue from HotelSetUp WITH (NOLOCK)  Where  SearchKey='VATValue2'
if (charindex(',',@VatValueWareText)>0)
  SET @VatValueWareText = STUFF(@VatValueWareText, charindex(',',@VatValueWareText) ,1, '.')
SET @VatValueIndex2 = CONVERT(Float,@VatValueWareText) 

Select @VatValueWareText = KeyValue from HotelSetUp WITH (NOLOCK)  Where  SearchKey='VATValue3'
if (charindex(',',@VatValueWareText)>0)
  SET @VatValueWareText = STUFF(@VatValueWareText, charindex(',',@VatValueWareText) ,1, '.')
SET @VatValueIndex3 = CONVERT(Float,@VatValueWareText) 

Select @VatValueWareText = KeyValue from HotelSetUp WITH (NOLOCK)  Where  SearchKey='VATValue4'
if (charindex(',',@VatValueWareText)>0)
  SET @VatValueWareText = STUFF(@VatValueWareText, charindex(',',@VatValueWareText) ,1, '.')
SET @VatValueIndex4 = CONVERT(Float,@VatValueWareText) 

Select @VatValueWareText = KeyValue from HotelSetUp WITH (NOLOCK)  Where  SearchKey='VATValue5'
if (charindex(',',@VatValueWareText)>0)
  SET @VatValueWareText = STUFF(@VatValueWareText, charindex(',',@VatValueWareText) ,1, '.')
SET @VatValueIndex5 = CONVERT(Float,@VatValueWareText) 

if isnull(@VatValueIndex1,0) = 0  SET @VatValueIndex1 = 0
if isnull(@VatValueIndex2,0) = 0  SET @VatValueIndex2 = 0
if isnull(@VatValueIndex3,0) = 0  SET @VatValueIndex3 = 0
if isnull(@VatValueIndex4,0) = 0  SET @VatValueIndex4 = 0
if isnull(@VatValueIndex5,0) = 0  SET @VatValueIndex5 = 0

DECLARE @BudgetExtra INT
SELECT @BudgetExtra = KeyValue FROM HotelSetup WITH (NOLOCK) WHERE SearchKey = 'BudgetExtra'
SET @BudgetExtra = ISNULL(@BudgetExtra, 1)

Declare ExtrasCur Cursor Fast_Forward READ_ONLY For
SELECT 
	isnull(ArrangementLines.Pieces * ArrangementLines.Price,0) as Total,
	isnull(
	CASE WHEN
	Accounts.VATValueNumber = 0  THEN 
	  (ArrangementLines.Pieces * ArrangementLines.Price * ((1-(1/convert(float,((@VatValueIndex0/100)+1))))))  
	when Accounts.VATValueNumber = 1  THEN
	  (ArrangementLines.Pieces * ArrangementLines.Price * ((1-(1/convert(float,((@VatValueIndex1/100)+1))))))  
	when Accounts.VATValueNumber = 2  THEN
	  (ArrangementLines.Pieces * ArrangementLines.Price * ((1-(1/convert(float,((@VatValueIndex2/100)+1))))))  
	when Accounts.VATValueNumber = 3  THEN
	  (ArrangementLines.Pieces * ArrangementLines.Price * ((1-(1/convert(float,((@VatValueIndex3/100)+1))))))  
	when Accounts.VATValueNumber = 4  THEN
	  (ArrangementLines.Pieces * ArrangementLines.Price * ((1-(1/convert(float,((@VatValueIndex4/100)+1))))))  
	when Accounts.VATValueNumber = 5  THEN
	  (ArrangementLines.Pieces * ArrangementLines.Price * ((1-(1/convert(float,((@VatValueIndex5/100)+1))))))  
	end, 0) as TotalVat,
	Accounts.AccountNumber,
	Case when ArrangementLines.FK_ExDepartment is null then isnull( 
			(SELECT TOP 1 PK_Department FROM Departments d WITH (NOLOCK)
				INNER JOIN ReservationMain r WITH (NOLOCK) ON d.HotelNumber = r.HotelNumber AND AutoCharge = 1 AND ISNULL(MarkAsDeleted, 0) = 0 AND ReferenceNumber = @ReferenceNumber), -1)
		else
			ArrangementLines.FK_ExDepartment
		end as DepartmentNumber,
	isnull(WareGroups.WareType, -1),
	isnull(WareGroups.Payment, -1),
	WareGroups.SortNumber as WareGroupNumber,
	Ware.WareNumber,
	Ware.Type as WareType,
	WareName,
	ArrangementReservationsXtab.GuestNumber,
	ArrangementLines.Pieces,
	isnull(Customer.CustomerNumber,-1) as HotelCustomerNumber,
    r.Status
FROM ArrangementLines WITH (NOLOCK) 
inner join ArrangementReservationsXtab WITH (NOLOCK) on ArrangementReservationsXtab.ArrangementLineNumber = ArrangementLines.ArrangementLineNumber 
  and referencenumber = @ReferenceNumber --AND GuestNumber = @GuestNumber
inner join Ware WITH (NOLOCK) ON ArrangementLines.WareNumber = Ware.WareNumber
inner JOIN WareGroups WITH (NOLOCK) on WareGroups.WaregroupNumber = Ware.WareGroupNumber 
inner join Accounts WITH (NOLOCK) ON Accounts.AccountNumber = Ware.ResultAccountNumber
left outer join arrangementroomxtab WITH (NOLOCK) on arrangementlines.arrangementLinenumber = arrangementroomxtab.arrangementLinenumber
INNER JOIN Departments WITH (NOLOCK) ON Departments.PK_Department = ArrangementLines.FK_ExDepartment
INNER JOIN Customer WITH (NOLOCK) ON Customer.HotelNumber = Departments.HotelNumber
  AND Customer.HotelNumber >= 0
  AND Customer.CustomerTypeNumber = 7
  AND ISNULL(Customer.MarkAsDeleted, 0) = 0
INNER JOIN Reservations r on ArrangementReservationsXtab.ReferenceNumber = r.ReferenceNumber and ArrangementReservationsXtab.GuestNumber = r.GuestNumber
where --WareGroups.WareType = @MISType and
ArrangementLines.Date = @DateStamp and arrangementroomxtab.arrangementLinenumber is null 
and ((@BudgetExtra = 0) OR (not ArrangementLines.FK_ExDepartment is null))
AND ISNULL(ArrangementLines.PacketItemNumber, 0) = 0

Open ExtrasCur 

Fetch Next From ExtrasCur Into @Price, @VatOfPrice, @AccountNumber, @DepartmentNumber, @MisType, @WarePayment, @WaregroupNumber, 
      @WareNumber, @WareType, @WareName, @GuestNumber, @Pieces, @HotelCustomerNumberFromArr, @Status

WHILE(@@FETCH_STATUS <> -1) 
Begin 
	--print '@HotelCustomerNumberFromArr=' + convert(varchar, @HotelCustomerNumberFromArr) + ', @Price=' + convert(varchar, @Price)
	Set @ValueTypeExtra = 0
	if @MisType = 1
	begin
		Set @ValueTypeExtra = 5
	end
	else if @MisType = 2
	begin
		Set @ValueTypeExtra = 4
	end
	else if @MisType = 0
	begin
		if @WarePayment = 7 -- ManuelRoom
		begin
			Set @ValueTypeExtra = 1	
		end
		else if @WarePayment = 8 -- ManuelHalls
		begin
			Set @ValueTypeExtra = 2
		end 
	end

  EXEC WareIsMenuWare @WareNumber, @Price, @Pieces, @HandleAsMenuWare OUTPUT

	IF @HandleAsMenuWare = 1
	BEGIN
	  --Insert the menuWare
		INSERT INTO MISTABLE (Room_HallType, ReferenceNumber, GuestNumber, FolioNumber, DateStamp, SegmentNumber, PointOfSaleNumber, RoomTypeNumber, BookedAdult, BookedChildren1, BookedChildren2, BookedNumberOfRooms, BookedPrice, BookedVatOfPrice, BookedPackage, BookedVatOfPackage, ActualAdult, ActualChildren1, ActualChildren2, ActualNumberOfRooms, ActualPrice, ActualVatOfPrice, ActualPackage, ActualVatOfPackage, ValueType, HotelCustomerNumber, ReservationStatus, CampaignCode, ProjectCode, StaffID, WareGroupNumber, AccountNumber, DepartmentNumber, Text, OwnerReservation,
				   WareType, WareNumber, BookedWareCount, ActualWareCount) 
		VALUES (@Room_HallType, @referencenumber, @GuestNumber, -1, @DateStamp, @SegmentNumber, @PointOfSaleNumber, @RoomTypeNumber, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @ValueTypeExtra, @HotelCustomerNumberFromArr, @Status, @CampaignCode, @ProjectCode, @StaffID, @WareGroupNumber, @DiscountAccountNumber, @DepartmentNumber, @WareName, @OwnerReservation,
				   @WareType, @WareNumber, @Pieces, 0) 

    -- get the sub menuwares
	  DECLARE db_menuware_cur CURSOR STATIC FOR
		SELECT mw.Procentage, Accounts.VatValueNumber, w.ResultAccountNumber, wg.SortNumber AS WaregroupNumber, ISNUll(MenuWare.InPercent, 0),
           w.WareNumber, w.WareName
		FROM Ware w WITH (NOLOCK)          
		INNER JOIN MenuWareXTab mw WITH (NOLOCK) ON w.WareNumber = mw.WareNumber AND mw.MenuNumber = @WareNumber
		INNER JOIN WareGroups wg WITH (NOLOCK) ON wg.WareGroupNumber = w.WareGroupNumber
		INNER JOIN ACCOUNTS WITH (NOLOCK) ON w.ResultAccountNumber = Accounts.AccountNumber
		INNER JOIN MenuWare WITH (NOLOCK) ON MenuWare.FK_MenuNumber = mw.MenuNumber
	  OPEN db_menuware_cur

	  FETCH NEXT FROM db_menuware_cur INTO @MenuProcentage, @MenuVatValueNumber, @MenuWareResultAccountNumber, @WareGroupNumber, @InPercent,
                                         @WareNumber, @WareName
	  WHILE @@FETCH_STATUS = 0
	  BEGIN
		EXEC GetVatvalueFromVATValueNumber @MenuVatValueNumber, @MenuVatValueWare OUTPUT
		IF @InPercent = 1
          SET @MenuWarePrice = ((@Price*@MenuProcentage)/100.0) 
		ELSE
          SET @MenuWarePrice = @MenuProcentage * @Pieces

		IF @OrderBookBudgetCalcDiscount = 1
		BEGIN
		  SET @AllDiscountRate = 0
		  EXEC FindFolioNumber @ReferenceNumber, @GuestNumber, 0, @WareNumber, @SplitbillNumber, 0, @FolioNumber OUTPUT, @AddressType OUTPUT

		  EXEC GetDiscountRate @ReferenceNumber, @GuestNumber, @AddressType, 0, @AllDiscountRate OUTPUT

		  IF @AllDiscountRate>0
		  BEGIN
			IF @DiscountAsNettoPrice=0
			BEGIN
			  SET @DiscountPrice = Round((@MenuWarePrice*(@AllDiscountRate/100)),2)*-1
			  SET @DiscountPriceVat = (@DiscountPrice*(1-(1/((@DiscountVatValueWare/100)+1))))
			  
			  IF @ChargeDiscountAsProduct = 0
			  begin	
				INSERT INTO MISTABLE (Room_HallType, ReferenceNumber, GuestNumber, FolioNumber, DateStamp, SegmentNumber, PointOfSaleNumber, RoomTypeNumber, BookedAdult, BookedChildren1, BookedChildren2, BookedNumberOfRooms, BookedPrice, BookedVatOfPrice, BookedPackage, BookedVatOfPackage, ActualAdult, ActualChildren1, ActualChildren2, ActualNumberOfRooms, ActualPrice, ActualVatOfPrice, ActualPackage, ActualVatOfPackage, ValueType, HotelCustomerNumber, ReservationStatus, CampaignCode, ProjectCode, StaffID, WareGroupNumber, AccountNumber, DepartmentNumber, Text, OwnerReservation,
				       WareType, WareNumber, BookedWareCount, ActualWareCount) 
				VALUES (@Room_HallType, @referencenumber, @GuestNumber, -1, @DateStamp, @SegmentNumber, @PointOfSaleNumber, @RoomTypeNumber, 0, 0, 0, 0, @DiscountPrice, @DiscountPriceVat, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @ValueTypeExtra, @HotelCustomerNumberFromArr, @Status, @CampaignCode, @ProjectCode, @StaffID, @WareGroupNumber, @DiscountAccountNumber, @DepartmentNumber, @WareName, @OwnerReservation,
				        @WareType, @WareNumber, @Pieces, 0) 
			  end
			  ELSE
			  begin
				INSERT INTO MISTABLE (Room_HallType, ReferenceNumber, GuestNumber, FolioNumber, DateStamp, SegmentNumber, PointOfSaleNumber, RoomTypeNumber, BookedAdult, BookedChildren1, BookedChildren2, BookedNumberOfRooms, BookedPrice, BookedVatOfPrice, BookedPackage, BookedVatOfPackage, ActualAdult, ActualChildren1, ActualChildren2, ActualNumberOfRooms, ActualPrice, ActualVatOfPrice, ActualPackage, ActualVatOfPackage, ValueType, HotelCustomerNumber, ReservationStatus, CampaignCode, ProjectCode, StaffID, WareGroupNumber, AccountNumber, DepartmentNumber, Text, OwnerReservation,
				       WareType, WareNumber, BookedWareCount, ActualWareCount) 
				VALUES (@Room_HallType, @referencenumber, @GuestNumber, -1, @DateStamp, @SegmentNumber, @PointOfSaleNumber, @RoomTypeNumber, 0, 0, 0, 0, @DiscountPrice, @DiscountPriceVat, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @ValueTypeExtra, @HotelCustomerNumberFromArr, @Status, @CampaignCode, @ProjectCode, @StaffID, @WareGroupNumber, @MenuWareResultAccountNumber, @DepartmentNumber, @WareName, @OwnerReservation,
				        @WareType, @WareNumber, @Pieces, 0) 
			  end
			END
			ELSE
			  SET @MenuWarePrice = @MenuWarePrice-(Round((@MenuWarePrice*(@AllDiscountRate/100)),2))
		  END
		END   

	  SET @MenuWarePriceVat = (@MenuWarePrice*(1-(1/((@DiscountVatValueWare/100)+1))))
		INSERT INTO MISTABLE (Room_HallType, ReferenceNumber, GuestNumber, FolioNumber, DateStamp, SegmentNumber, PointOfSaleNumber, RoomTypeNumber, BookedAdult, BookedChildren1, BookedChildren2, BookedNumberOfRooms, BookedPrice, BookedVatOfPrice, BookedPackage, BookedVatOfPackage, ActualAdult, ActualChildren1, ActualChildren2, ActualNumberOfRooms, ActualPrice, ActualVatOfPrice, ActualPackage, ActualVatOfPackage, ValueType, HotelCustomerNumber, ReservationStatus, CampaignCode, ProjectCode, StaffID, WareGroupNumber, AccountNumber, DepartmentNumber, Text, OwnerReservation,
		       WareType, WareNumber, BookedWareCount, ActualWareCount) 
		VALUES (@Room_HallType, @referencenumber, @GuestNumber, -1, @DateStamp, @SegmentNumber, @PointOfSaleNumber, @RoomTypeNumber, 0, 0, 0, 0, @MenuWarePrice, @MenuWarePriceVat, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @ValueTypeExtra, @HotelCustomerNumberFromArr, @Status, @CampaignCode, @ProjectCode, @StaffID, @WareGroupNumber, @MenuWareResultAccountNumber, @DepartmentNumber, @WareName, @OwnerReservation,
		        @WareType, @WareNumber, @Pieces, 0) 
	  --BookedWareCount: Both the menuware and the manuparts are stored with a count  
		FETCH NEXT FROM db_menuware_cur INTO @MenuProcentage, @MenuVatValueNumber, @MenuWareResultAccountNumber, @WareGroupNumber, @InPercent,
                                         @WareNumber, @WareName
    END  
	  CLOSE db_menuware_cur
	  DEALLOCATE db_menuware_cur
	END
	ELSE
	BEGIN
	  -- Calc Discount
	  IF @OrderBookBudgetCalcDiscount = 1
	  BEGIN
		SET @AllDiscountRate = 0
		EXEC FindFolioNumber @ReferenceNumber, @GuestNumber, 0, @WareNumber, @SplitbillNumber, 0, @FolioNumber OUTPUT, @AddressType OUTPUT

		EXEC GetDiscountRate @ReferenceNumber, @GuestNumber, @AddressType, 0, @AllDiscountRate OUTPUT

		IF @AllDiscountRate>0
		BEGIN
		  IF @DiscountAsNettoPrice=0
		  BEGIN
			SET @DiscountPrice = Round((@Price*(@AllDiscountRate/100)),2)*-1
		  	SET @DiscountPriceVat = (@DiscountPrice*(1-(1/((@DiscountVatValueWare/100)+1))))

			IF @ChargeDiscountAsProduct = 0
			BEGIN
				INSERT INTO MISTABLE (Room_HallType, ReferenceNumber, GuestNumber, FolioNumber, DateStamp, SegmentNumber, PointOfSaleNumber, RoomTypeNumber, BookedAdult, BookedChildren1, BookedChildren2, BookedNumberOfRooms, BookedPrice, BookedVatOfPrice, BookedPackage, BookedVatOfPackage, ActualAdult, ActualChildren1, ActualChildren2, ActualNumberOfRooms, ActualPrice, ActualVatOfPrice, ActualPackage, ActualVatOfPackage, ValueType, HotelCustomerNumber, ReservationStatus, CampaignCode, ProjectCode, StaffID, WareGroupNumber, AccountNumber, DepartmentNumber, Text, OwnerReservation,
				       WareType, WareNumber, BookedWareCount, ActualWareCount) 
				VALUES (@Room_HallType, @referencenumber, @GuestNumber, -1, @DateStamp, @SegmentNumber, @PointOfSaleNumber, @RoomTypeNumber, 0, 0, 0, 0, @DiscountPrice, @DiscountPriceVat, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @ValueTypeExtra, @HotelCustomerNumberFromArr, @Status, @CampaignCode, @ProjectCode, @StaffID, @WareGroupNumber, @DiscountAccountNumber, @DepartmentNumber, @WareName, @OwnerReservation,
				        @WareType, @WareNumber, 0, 0) 
			END
			ELSE
			BEGIN
				INSERT INTO MISTABLE (Room_HallType, ReferenceNumber, GuestNumber, FolioNumber, DateStamp, SegmentNumber, PointOfSaleNumber, RoomTypeNumber, BookedAdult, BookedChildren1, BookedChildren2, BookedNumberOfRooms, BookedPrice, BookedVatOfPrice, BookedPackage, BookedVatOfPackage, ActualAdult, ActualChildren1, ActualChildren2, ActualNumberOfRooms, ActualPrice, ActualVatOfPrice, ActualPackage, ActualVatOfPackage, ValueType, HotelCustomerNumber, ReservationStatus, CampaignCode, ProjectCode, StaffID, WareGroupNumber, AccountNumber, DepartmentNumber, Text, OwnerReservation,
				       WareType, WareNumber, BookedWareCount, ActualWareCount) 
				VALUES (@Room_HallType, @referencenumber, @GuestNumber, -1, @DateStamp, @SegmentNumber, @PointOfSaleNumber, @RoomTypeNumber, 0, 0, 0, 0, @DiscountPrice, @DiscountPriceVat, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @ValueTypeExtra, @HotelCustomerNumberFromArr, @Status, @CampaignCode, @ProjectCode, @StaffID, @WareGroupNumber, @AccountNumber, @DepartmentNumber, @WareName, @OwnerReservation,
				        @WareType, @WareNumber, 0, 0) 
			END
		  END
		  ELSE
			SET @Price = @Price-(Round((@Price*(@AllDiscountRate/100)),2))
		END
	  END  
	  -- Calc Discount END

 	 INSERT INTO MISTABLE (Room_HallType, ReferenceNumber, GuestNumber, FolioNumber, DateStamp, SegmentNumber, PointOfSaleNumber, RoomTypeNumber, BookedAdult, BookedChildren1, BookedChildren2, BookedNumberOfRooms, BookedPrice, BookedVatOfPrice, BookedPackage, BookedVatOfPackage, ActualAdult, ActualChildren1, ActualChildren2, ActualNumberOfRooms, ActualPrice, ActualVatOfPrice, ActualPackage, ActualVatOfPackage, ValueType, HotelCustomerNumber, ReservationStatus, CampaignCode, ProjectCode, StaffID, WareGroupNumber, AccountNumber, DepartmentNumber, Text, OwnerReservation,
	        WareType, WareNumber, BookedWareCount, ActualWareCount) 
	 VALUES (@Room_HallType, @referencenumber, @GuestNumber, -1, @DateStamp, @SegmentNumber, @PointOfSaleNumber, @RoomTypeNumber, 0, 0, 0, 0, @Price, @VatOfPrice, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @ValueTypeExtra, @HotelCustomerNumberFromArr, @Status, @CampaignCode, @ProjectCode, @StaffID, @WareGroupNumber, @AccountNumber, @DepartmentNumber, 'WARE ' + @WareName, @OwnerReservation,
	         @WareType, @WareNumber, @Pieces, 0) 
  END


	Fetch Next From ExtrasCur Into @Price, @VatOfPrice, @AccountNumber, @DepartmentNumber, @MisType, @WarePayment, @WaregroupNumber, 
	      @WareNumber, @WareType, @WareName, @GuestNumber, @Pieces, @HotelCustomerNumberFromArr, @Status
end
Close ExtrasCur 
Deallocate ExtrasCur
