CREATE PROCEDURE dbo.GetCashDeskForOnline @AHotelCustomerNumber INT, @ACashDesk INT OUTPUT AS
SET NOCOUNT ON

/*
  Created by Kent Johansen December 2012
  Description: Moved from OnlinePostering.

  Changes:
  KJ 20200414: Added missing Nolock.

*/

--Get Cashbox with fallback (Externals=1 or Hotel match or first one)
SELECT TOP 1 @ACashDesk = ISNULL(PK_CashBox, -1) FROM CashBox WITH (NOLOCK)
WHERE ISNULL(CashRegisterMarking, '') <> '' AND ISNULL(MarkAsDeleted, 0) = 0
AND FK_CustomerHotel = @AHotelCustomerNumber AND ISNULL(Externals, 0) = 1
IF ISNULL(@ACashDesk, -1) = -1 --not found
  SELECT TOP 1 @ACashDesk = ISNULL(PK_CashBox, -1) FROM CashBox  WITH (NOLOCK)
  WHERE ISNULL(CashRegisterMarking, '') <> '' AND ISNULL(MarkAsDeleted, 0) = 0
  AND FK_CustomerHotel = @AHotelCustomerNumber 
IF ISNULL(@ACashDesk, -1) = -1 --not found
  SELECT TOP 1 @ACashDesk = ISNULL(PK_CashBox, -1) FROM CashBox  WITH (NOLOCK)
  WHERE ISNULL(CashRegisterMarking, '') <> ''
  AND ISNULL(MarkAsDeleted, 0) = 0