CREATE PROCEDURE [dbo].[OnlineCancelReservation] @AReferenceNumber INT, @ErrorLevel INT OUTPUT, @IsTableBooking INT = 0
AS
SET NOCOUNT ON
/*
    Created by Jacob Pedersen July 2004

    Changes:
    2015-07-14 SG: Also change status on table. Added optional param @IsTableBooking
    2004-10-04 JP: fixed cancelled status (8->7)

    NOTES: 	- 

*/
/*
  Error Levels:
  00 : No errors
  01 : Reservation was already cancelled
*/
SET @ErrorLevel = 00
DECLARE @Status TINYINT
SELECT @Status=Status FROM Reservations WITH (NOLOCK) WHERE ReferenceNumber=@AReferenceNumber AND GuestNumber=0

IF @Status=7 /* Cancelled */
BEGIN
  SET @ErrorLevel=01
  RETURN
END

If @IsTableBooking = 1
Begin
  UPDATE ReservationConferenceLine 
  SET TableStatus = 7 
  WHERE ReferenceNumber = @AReferenceNumber 
  --Picasso allows more than one table in a reservation. We change status on all, as they are created online in one transaction.
End
UPDATE Reservations SET Status=7 /* Cancelled */ WHERE ReferenceNumber=@AReferenceNumber AND GuestNumber=0

-- FOLLOWUP ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

EXEC OnlineUpdateFollowUp @AReferenceNumber

