CREATE PROCEDURE dbo.OnlineUpdateFollowUp @AReferenceNumber INT AS
SET NOCOUNT ON
/*
    Created by Jacob Pedersen July 2004

    Changes: 
      KJ 20110407: Only update Followup if reservation isn't canceled.

    NOTES: Updates the "Created" follow up to match new time. This is done so that reservation is not cancelled while Internet user is actually just slow

*/
DECLARE @Status INT
SELECT @Status = Status FROM Reservations WITH (NOLOCK) WHERE ReferenceNumber = @AReferenceNumber

IF @Status < 7 -- Only add if reservations isn't canceled
BEGIN 
  DECLARE @SystemDateTime DATETIME,
  @SystemDateStr CHAR(8),
  @UserIDNumber INT
  SELECT @SystemDateStr = SYSTEMDATE FROM System WITH (NOLOCK) WHERE NUMBER = 1  -- Only one record YYYYMMDD
  SELECT @SystemDateTime = CONVERT(DATETIME, @SystemDateStr, 112)+CONVERT (CHAR, GetDate(), 108)
  SELECT @UserIDNumber=UserIDNumber FROM Personel WITH (NOLOCK) WHERE UserTypeNumber=5

  UPDATE FollowUp SET [Date]=@SystemDateTime, CreatedDate=@SystemDateTime
  WHERE Type=5 AND Priority=12 and State=3 AND CreatedBy=@UserIDNumber AND SubType=1 AND FollowUpNumber IN (SELECT FollowUpNumber FROM ReservationFollowUpXTab WITH (NOLOCK) WHERE ReferenceNumber=@AReferenceNumber AND GuestNumber=0)
END

