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

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

  KJ 20211130: Added SubType2. Req #3991
  SG/2020-08-24: Added optional param Type and SubType
  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, SubType2)
VALUES (@SystemDateTime, @AType, 12, 3, @AFollowupText, @SystemDateTime, @AUserIdNumber, @ASubType, @AHotelNumber, @ReservationLog, @AFollowupSubType2)
SELECT @NewFollowUpNumber = @@identity
INSERT INTO ReservationFollowUpXTab (ReferenceNumber, GuestNumber, FollowUpNumber) VALUES (@AReferenceNumber, @AGuestNumber, @NewFollowUpNumber)

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