IF EXISTS( SELECT * FROM SYS.OBJECTS
		  WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[P_RC_VD_CONV_PRE_FECHAMENTO]') AND TYPE IN(N'P', N'PC'))
    DROP PROCEDURE [DBO].[P_RC_VD_CONV_PRE_FECHAMENTO];
GO
--Removido por solicitacao da issue 423
--EXEC P_RC_VD_CONV_PRE_FECHAMENTO
/*
CREATE PROCEDURE P_RC_VD_CONV_PRE_FECHAMENTO
AS
    DECLARE @DT_MES_ANT AS DATETIME;
    DECLARE @DT_MES_ATU AS DATETIME;

    SET @DT_MES_ANT = DATEADD(MONTH, -1, GETDATE());
    SET @DT_MES_ATU = GETDATE();

    UPDATE C 
    SET  
	   ST_FECHVD_CONV = 5
    FROM 
	   RC_VD_CONV C
	   INNER JOIN RC_CLI_CONV_RC_CLI ON 
	   C.CD_EMP = RC_CLI_CONV_RC_CLI.CD_EMP AND 
	   C.CD_CLI = RC_CLI_CONV_RC_CLI.CD_CLI AND 
	   C.CD_CONV = RC_CLI_CONV_RC_CLI.CD_CONV

	   INNER JOIN RC_CLI_CONV ON 
	   C.CD_EMP = RC_CLI_CONV.CD_EMP AND 
	   C.CD_CONV = RC_CLI_CONV.CD_CONV

    WHERE 
	   RC_CLI_CONV.DIA_FAT > 0
	   AND CONVERT(CHAR(10), C.DT_FECHA, 112) <= (CASE WHEN RC_CLI_CONV.DIA_FAT >= DAY(GETDATE()) THEN  CAST(YEAR(@DT_MES_ANT) AS VARCHAR)
																						  +RIGHT('0'+CAST(MONTH(@DT_MES_ANT) AS VARCHAR), 2)
																						  +RIGHT('0'+CAST(RC_CLI_CONV.DIA_FAT AS VARCHAR), 2)
											 ELSE 
												CAST(YEAR(@DT_MES_ATU) AS VARCHAR) 
												+ RIGHT('0'+CAST(MONTH(@DT_MES_ATU) AS VARCHAR), 2)
												+RIGHT('0'+CAST(RC_CLI_CONV.DIA_FAT AS VARCHAR), 2)
											 END)
	   AND C.ST_FECHVD_CONV = 0
	   AND RC_CLI_CONV.CONV_HABILITADO = 0;
*/