CREATE PROCEDURE RK7SQLPROC_REP_CALC AS
BEGIN
	DECLARE @RES INT;
	DECLARE @GETDATE DATETIME;
	DECLARE @CURR_DAY DATETIME;
	SELECT TOP 1 @CURR_DAY = SHIFTDATE, @RES = IRESTAURANT FROM GLOBALSHIFTS WHERE CLOSED = 0 ORDER BY MIDSERVER,SHIFTNUM DESC;

	SET @GETDATE = GETDATE();
	
	IF(@RES IS NULL)
	BEGIN
		SELECT TOP 1 @RES = IRESTAURANT FROM GLOBALSHIFTS ORDER BY MIDSERVER,SHIFTNUM DESC;
		SET @CURR_DAY = DATEADD(DAY,DATEDIFF(DAY,0,@GETDATE),0);
	END;

	EXEC RATING_REP_CALC @RES,@GETDATE, @VER = NULL,
	@FOODCAT1 = NULL, @FOODCAT2 = NULL, @FOODCAT3 = NULL, @FOODCAT4 = NULL, @FOODCAT5 = NULL, 
	@FOODFIELD1 = NULL, @FOODFIELD2 = NULL, @FOODFIELD3 = NULL, @FOODFIELD4 = NULL, @FOODFIELD5 = NULL,
	@COUNTFIELD = NULL, @AMOUNTFIELD = NULL;

	SELECT (SELECT NAME FROM RESTAURANTS WHERE SIFR = @RES) AS RESTAURANT, @CURR_DAY AS SHIFTDATE;
END;
GO
