

IF EXISTS ( SELECT * FROM SYS.OBJECTS 
	WHERE NAME = 'P_ATUALIZA_ST_RC_VD_CONV')
BEGIN 
	DROP PROCEDURE P_ATUALIZA_ST_RC_VD_CONV
END
GO
CREATE PROCEDURE [dbo].[P_ATUALIZA_ST_RC_VD_CONV] (@CD_EMP INT ,@CD_CTR INT)
AS


DECLARE @VLR_CREDITOS MONEY

BEGIN

	SET @VLR_CREDITOS = (SELECT SUM(VLR_CRED) FROM RC_VD_CONV_CRED WHERE CD_EMP=@CD_EMP AND CD_CTR=@CD_CTR)

	-- update status
	UPDATE RC_VD_CONV SET
		ST_FECHVD_CONV = (CASE  WHEN VLR_CONV = @VLR_CREDITOS THEN 3 
				  ELSE ST_FECHVD_CONV END)

	WHERE RC_VD_CONV.CD_EMP = @CD_EMP
		  AND RC_VD_CONV.CD_CTR = @CD_CTR
	
END


