DROP PROCEDURE DSS_DBG_PronosticoIngresos
GO

CREATE PROCEDURE DSS_DBG_PronosticoIngresos
	@fec_ini DATE,
	@fec_fin DATE,
	@id_mone INT
AS
BEGIN

	-- EXEC DSS_DBG_PronosticoIngresos '2015-06-16', '2015-06-30', 3

	CREATE TABLE #PronIngFDK
	(
		cdia VARCHAR(5),
		dia DATE,
		Reserv NUMERIC(18, 2),
		Ocup NUMERIC(18, 2),
		Reg_Extra NUMERIC(18, 2),
		Otr_Extra NUMERIC(18, 2),
		Ro_Al NUMERIC(18, 2),
		Pro_Al NUMERIC(18, 2),
		Re_Pen NUMERIC(18, 2),
		Ro_Pen NUMERIC(18, 2),
		Pro_Pen NUMERIC(18, 2),
		Otr_Re NUMERIC(18, 2),
		Otr_Ro_Ag NUMERIC(18, 2),
		Otr_Pro_Ag NUMERIC(18, 2)
	)
	
	INSERT #PronIngFDK
	EXEC Calc_Booking_Ing @fec_ini, @fec_fin, @id_mone, 1
	
	CREATE TABLE #PronIngFDK2
	(
		fecha date,
		Ing_Reserva numeric(15, 2),
		ing_reserva_Reg numeric(15, 2),
		ing_reserva_Otr numeric(15, 2),
		ing_Ro_Al numeric(15, 2),
		ing_Ro_Pen numeric(15, 2),
		ing_ROAgen numeric(15, 2)
	)
	
	INSERT INTO #PronIngFDK2
	(
		fecha,
		Ing_Reserva,
		ing_reserva_Reg,
		ing_reserva_Otr,
		ing_Ro_Al,
		ing_Ro_Pen,
		ing_ROAgen
	)
	SELECT
		dia,
		Reserv + Ocup,
		Re_Pen + Reg_Extra,
		Otr_Re + Otr_Extra,
		Ro_Al + Pro_Al,
		Ro_Pen + Pro_Pen,
		Otr_Ro_Ag + Otr_Pro_Ag
	FROM #PronIngFDK
	
	SELECT a.fecha,
	       a.Ing_Reserva DSS_Ing_Reserva,
	       b.Ing_Reserva FDK_Ing_Reserva,
	       a.ing_reserva_Reg DSS_ing_reserva_Reg,
	       b.ing_reserva_Reg FDK_ing_reserva_Reg,
	       a.ing_reserva_Otr DSS_ing_reserva_Otr,
	       b.ing_reserva_Otr FDK_ing_reserva_Otr,
	       a.ing_Ro_Al DSS_ing_Ro_Al,
	       b.ing_Ro_Al FDK_ing_Ro_Al,
	       a.ing_Ro_Pen DSS_ing_Ro_Pen,
	       b.ing_Ro_Pen FDK_ing_Ro_Pen,
	       a.ing_ROAgen DSS_ing_ROAgen,
	       b.ing_ROAgen FDK_ing_ROAgen
	FROM       DEBGDAIPG    a
	INNER JOIN #PronIngFDK2 b ON a.fecha = b.fecha
	WHERE a.fecha BETWEEN @fec_ini AND @fec_fin
	  AND (a.Ing_Reserva <> b.Ing_Reserva
	    OR a.ing_reserva_Otr <> b.ing_reserva_Otr
	    OR a.ing_reserva_Reg <> b.ing_reserva_Reg
	    OR a.ing_Ro_Al <> b.ing_Ro_Al
	    OR a.ing_Ro_Pen <> b.ing_Ro_Pen
	    OR a.ing_ROAgen <> b.ing_ROAgen)
	
END
