SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
===========================================================
-- Autor:       Francis Antonio Bolaños Arias
-- Fecha:       26/09/2012 09:24:30
-- Descripción: Procedimiento que obtiene la información
--              para generar el informe de Booking
--              para DSS
-- ========================================================
*/

IF EXISTS (SELECT * FROM sys.objects 
   WHERE object_id = OBJECT_ID(N'DSS_FRONT_NoShows') )
DROP Procedure DSS_FRONT_NoShows
GO

CREATE PROCEDURE DSS_FRONT_NoShows
	@FecIni  DATE,
    @FecFin  DATE,
    @cierre  BIT = 0,
    @id_zeje INT = 0
AS
BEGIN 

	DECLARE @FechaHotelera DATE
	
	EXEC dbo.Get_Fecha_Hotelera @FechaHotelera OUTPUT
	
	CREATE TABLE #NoShows(
				Tipo varchar(50) NULL,
				nro_reserva int NULL,
				nombre varchar(100) NULL,
				contrato varchar(50) NULL,
				nacionalidad varchar(50) NULL,
				fecha_ent datetime NULL,
				fecha_sal datetime NULL,
				nomb_reserv varchar(100) NULL,
				telef_reserv varchar(50) NULL,
				referencia varchar(50) NULL,
				Cant_habi int NULL,
				id_rese int NULL)
	
	INSERT INTO #NoShows
	EXEC No_Shows @FecIni, @FecFin
	
	IF @cierre = 0
	BEGIN
	
		SELECT *,
			   @FecIni AS FecIni,
			   @FecFin AS FecFin,
			   @FechaHotelera AS FechaHotelera
		FROM #NoShows
	
	END
	ELSE
	BEGIN
		
		IF NOT EXISTS (SELECT id_zeje FROM CIERNSHW WHERE id_zeje = @id_zeje)
		BEGIN
			INSERT CIERNSHW
			SELECT @id_zeje id_zeje, *,
				   @FecIni AS FecIni,
				   @FecFin AS FecFin,
				   @FechaHotelera AS FechaHotelera
			FROM #NoShows
		END
		
	END
	
	RETURN

END
