CREATE PROCEDURE DBO.InvoiceCreate @ACustomerNumber INT, @AAdressType INT, @AHotelCustomerNumber INT, @AAddressNumber INT OUTPUT, @AFolioNumber INT OUTPUT, @ARoomNumber INT = -1 AS

/*
  Created by Kent Johansen december 2006
  Used to create a new Invoice

  Changes:
    KJ 20191120: Bug: Fix for "Post is made on wrong folionumber if bonus card". Case #CR174101
--nb20140721 FolioIdentity discontinued
    KJ 20100112: Ext: Added Owner calculation per room number
    KJ 20081029: Bug: Fix for "OpenFolio should be true"
    KJ 20070501: Set BillType = 0
    KJ 20061206: Moved ReservationAddress stuff to UpdateReservationAddress
*/

EXEC UpdateReservationAddress @ACustomerNumber, @AAdressType, @AAddressNumber OUTPUT, @ARoomNumber

IF @AAddressNumber > 0
BEGIN
  INSERT INTO Folios (GuestNumber, ReservationAddressNumber, OpenFolio, Note, HotelCustomerNumber)
  VALUES (0, @AAddressNumber, 1, '', @AHotelCustomerNumber)
  SELECT @AFolioNumber = SCOPE_IDENTITY()--@@IDENTITY
END

