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


CREATE PROCEDURE [dbo].[CP_CtrlPresup_Generar_Fin] 
@Id_Trans   INT
AS 

DECLARE @Mensaje			VARCHAR(100)
		,@Importe			DECIMAL(16,2)


BEGIN TRY
	BEGIN TRAN
	SET @Importe = ISNULL((SELECT SUM(Debe) FROM Cbtes_Ctas_Contables WHERE Id_Trans = @Id_Trans),0)

	UPDATE Cbtes SET Id_Estado_Cbte = 2 , Imp_Total = @Importe WHERE Id_Trans = @Id_Trans
	 
	COMMIT

	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;  
	ROLLBACK
END CATCH;   
