CREATE PROCEDURE DBO.[OnlineGetGuestInvoiceContent] @ReferenceNumber INT, @GuestNumber INT, @Balance MONEY OUTPUT, 
  @AFolioNumber INT = -1 OUTPUT, @AReservationAddressNumber INT = -1 OUTPUT AS
SET NOCOUNT ON
/*
Changes:
  KJ 20171211: Added extra output params for OTA_PurchaseItem
  SG 20170828: Parameters changed according to Nenad in order to get all records regardles if a bill has been printed or not.
  KS 20150224: To get all the payments, 4 of the parameters must have fixed values as below, according to Nenad.

  NB20101223: Created
  NOTE: Get Transactions from reservation guest folio for Online Booking
*/
DECLARE @BillTypeNumber INT

SELECT @AFolioNumber = FolioNumber --, @BillTypeNumber = BillTypeNumber
, @AReservationAddressNumber = F.ReservationAddressNumber
FROM dbo.FOLIOS F with (nolock) 
  INNER JOIN dbo.ReservationAddressXTab RAX WITH (NOLOCK) ON F.ReservationAddressNumber = RAX.ADDRESSNUMBER
where F.ReferenceNumber = @ReferenceNumber AND F.GuestNumber = @GuestNumber AND RAX.AddressTypeNumber = 1

SET @AFolioNumber = @AFolioNumber
--exec dbo.GetTransactions @FolioNumber, @BillTypeNumber, 0, 0, 1, @Balance output
--exec dbo.GetTransactions @FolioNumber, 0, 1, 0, 1, @Balance output
exec dbo.GetTransactions @AFolioNumber, 0, 0, -1, 1, @Balance output