CREATE PROCEDURE [dbo].[OnlineCreateReservationFollowup] @AReferenceNumber INT, @AGuestNumber INT, @AUserIdNumber INT, @AFollowupText VARCHAR(8000), @AHotelNumber INT, @ReservationLog VARCHAR(max) = ''
                                                  
AS
SET NOCOUNT ON

/*
  Based on CreateReservationFollowup
  Create a new followup on a reservation

  SG/2015-08-13: Added optional param @ReservationLog
  SG/2015-06-12: Add a detailed log 
*/

DECLARE @SystemDateTime DATETIME
DECLARE @SystemDateStr CHAR(8)
DECLARE @NewFollowUpNumber INT

SELECT  @SystemDateStr = SystemDate FROM System WITH (NOLOCK) WHERE Number = 1
SELECT @SystemDateTime = CONVERT(DATETIME, @SystemDateStr, 112) + CONVERT (CHAR, GetDate(), 108)

INSERT INTO FollowUp ([Date], Type, Priority, State, Note, CreatedDate, CreatedBy, SubType, HotelNumber, ReservationLog)
VALUES (@SystemDateTime, 5, 12, 3, @AFollowupText, @SystemDateTime, @AUserIdNumber, 1, @AHotelNumber, @ReservationLog)
SELECT @NewFollowUpNumber = @@identity
INSERT INTO ReservationFollowUpXTab (ReferenceNumber, GuestNumber, FollowUpNumber) VALUES (@AReferenceNumber, @AGuestNumber, @NewFollowUpNumber)

IF @ReservationLog = ''
BEGIN
  EXEC UpdateDetailedReservationLog @AReferenceNumber, @AGuestNumber, @NewFollowUpNumber
END  
