CREATE PROCEDURE dbo.OnlineAddReservationOrderItem
(
	@ReservationOrderId int,
	@ReferenceNumber int,
	@GuestNumber smallint,
	@FolioNumber int,
	@HotelCustomerNumber int,
	@SplitBillNumber int,
	@UserIDNumber int,
	@WareNumber int,
	@Price money,
	@Pieces int
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @CreateNewFolioIfNotExists bit = 1
	DECLARE @AddressType smallint
	DECLARE @TransNrShowOnBill int

	IF (@FolioNumber IS NULL) OR (@FolioNumber=0)
	BEGIN
		EXECUTE [dbo].[FindFolioNumber] 
		   @ReferenceNumber
		  ,@GuestNumber
		  ,@UserIDNumber
		  ,@WareNumber
		  ,@SplitbillNumber
		  ,1 --CreateNewFolioIfNotExists
		  ,@FolioNumber OUTPUT
		  ,@AddressType OUTPUT
	END

	EXEC [dbo].[OnlinePosteringExt] 
		@WareNumber
		,@HotelCustomerNumber
		,@FolioNumber
		,@Price 
		,@Pieces 
		,'' -- @AWareTextOverwrite
		,@TransNrShowOnBill OUTPUT
		,@UserIDNumber 

	INSERT INTO [dbo].[OnlineReservationOrderItem]
           ([ReservationOrderId]
           ,[TransactionNumber])
		 VALUES
           (@ReservationOrderId
           ,@TransNrShowOnBill)
END
