IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[SP_Fact_Proforma_Anular]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[SP_Fact_Proforma_Anular] 
END
GO

CREATE PROCEDURE [dbo].[SP_Fact_Proforma_Anular]  @pLote VarChar(20)

AS
SET NOCOUNT ON

DECLARE

	@pId_Tipo_Cbte		CHAR(4),
	@pId_Tipo_Cli       Smallint 

	SET @pId_Tipo_Cbte  = 'CPRO'

/*Declaracion Variables Locales*/
  DECLARE  @Mensaje			VARCHAR(100)
	      ,@UltError	    INT
		  ,@Id_Trans		INT
		  ,@Id_Cliente		INT
		  ,@Importe			DECIMAL(16,2)
		  ,@Email_Cob   	VARCHAR(256)
		  ,@Comprobante_Nro   INT
		  ,@CursorOpen        INT
		  ,@Descrip_Cbte      VARCHAR(100)
		  ,@Result_Stored_Invocado  INT
		  ,@JSON_Parametros_Stored_Invocado VARCHAR(8000)

  DECLARE @Respuesta Table (
				ErrorNumber		INT,
				ErrorSeverity	INT,
				ErrorState		INT,
				ErrorProcedure  VARCHAR(1000),
				ErrorLine		INT,
				ErrorMessage	VARCHAR(1000)
				)


  BEGIN TRY

    /*Borrar Cupones */

	UPDATE CBTES SET ID_ESTADO_CBTE = 3 WHERE ID_ESTADO_CBTE = 1 AND ID_TIPO_CBTE = @pId_Tipo_Cbte AND FECHA < Getdate() - 30
	

	/******************************fin del proceso***********************************************/

	SELECT	 0				AS ErrorNumber 
			,0				AS ErrorSeverity  
			,0				AS ErrorState 
			,0				AS ErrorProcedure  
			,0				AS ErrorLine		
			,@Mensaje		AS ErrorMessage
END TRY  


BEGIN CATCH  
    EXECUTE usp_GetErrorInfo
	
  	
	RETURN 9999
END CATCH

RETURN 0


--exec SP_Fact_Proforma_Anular ''

--select * from cbtes where id_tipo_cbte = 'cpro'