CREATE PROCEDURE dbo.RegenerateAvailabilityFromDate @StartDate CHAR (8), @FixReservationDates SMALLINT=0 AS
SET NOCOUNT ON
/*
    Created by Jacob Pedersen
    Last update:
    20070726 JP: added call to fixreservationdates for all hotels in chain
    20041206 JP: fixed set nightaudit parameter
    20041202 JP: fixed hotelnumber 0 problem
    20040218 JP: fixed systemdate. who changed it!?

*/
declare @enddate char (8)
declare @systemdate char (8)
select @systemdate=systemdate from system WITH (nolock)
set @enddate=@systemdate

IF @FixReservationDates = 1
BEGIN
  DECLARE @DominoEnabled SMALLINT
  SELECT @DominoEnabled=CONVERT(SMALLINT,KeyValue) FROM HotelSetup WITH (NOLOCK) WHERE SearchKey='CentralBookingType'
  IF ISNULL(@DominoEnabled, 0) = 0
    SET @DominoEnabled = 0

  IF @DominoEnabled = 1
  BEGIN
    DECLARE @HotelNumber INT

    DECLARE #NoteCursor CURSOR STATIC FORWARD_ONLY FOR

      SELECT HotelNumber FROM Customer WITH (NOLOCK)
      WHERE HotelNumber>0 OR LocalHotel=1

      OPEN #NoteCursor

      FETCH NEXT FROM #NoteCursor INTO @HotelNumber

      WHILE  (@@FETCH_STATUS <> -1)
      BEGIN
        exec fixreservationdates @HotelNumber, @startdate -- optional

        FETCH NEXT FROM #NoteCursor INTO @HotelNumber
      END

      CLOSE #NoteCursor
      DEALLOCATE #NoteCursor
  END
  ELSE
    exec fixreservationdates 0, @startdate -- optional
END

--update terminals set nightauditrunning=1 where terminalnumber in (select min (terminalnumber) from terminals WITH (nolock))
--update system set systemdate=@startdate

exec generateavailability @startdate, @enddate, 0, '', @systemdate, 1, 1, '', '', 2, 0, 1, 0, 1 -- called with the REAL systemdate for correct release allot and calc of dayrooms in sold rooms, when called for long period in past !
--update terminals set nightauditrunning=0 where terminalnumber in (select min (terminalnumber) from terminals WITH (nolock))
--update system set systemdate=@systemdate
GO
