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 @NewFollowUpNumber INT

EXEC SystemDateTime '', @SystemDateTime OUTPUT

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  
