IF EXISTS (SELECT * FROM sys.objects  WHERE [type] IN ('FN','P') AND  name = 'CF_Cbtes_Por_Debito')
	DROP FUNCTION DBO.CF_Cbtes_Por_Debito
GO


CREATE FUNCTION dbo.CF_Cbtes_Por_Debito(@pId_Trans INT,@Veirf_Dias_Bloqueo_CobMan TINYINT)
RETURNS TINYINT
AS
BEGIN

DECLARE @Id_Tarjeta				VARCHAR(10)
		,@Tar_Nro				VARCHAR(25)
		,@Retorno				TINYINT
		,@Dias_Bloqueo_CobMan	SMALLINT


SET @Retorno = 0
SET @Id_Tarjeta = dbo.CF_Cbtes_Id_Tarjeta(@pId_Trans)

IF @Id_Tarjeta != ''
BEGIN
	SET @Tar_Nro = dbo.CF_Cbtes_Tar_Nro(@pId_Trans)
	IF @Tar_Nro != ''
	BEGIN
	    SET @Retorno = 1
		IF ISNULL(@Veirf_Dias_Bloqueo_CobMan,0) != 0
		BEGIN
		    SELECT @Dias_Bloqueo_CobMan = Dias_Bloqueo_CobMan FROM Valores_Tarjetas_Cred WHERE Id_Tarjeta = @Id_Tarjeta
			IF ISNULL(@Dias_Bloqueo_CobMan,0) != 0
			BEGIN
			   SELECT @Retorno = 0 FROM Cbtes WHERE Id_Trans = @pId_Trans AND Fecha + @Dias_Bloqueo_CobMan < GETDATE()
			END 
		END
	END
END

RETURN @Retorno
END
