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


CREATE PROCEDURE [dbo].[CP_CtrlPresup_Generar_Item] 
@Id_Trans   INT,
@Item		SMALLINT,
@Id_Centro_Costo CHAR(10),
@Alias		SMALLINT,
@Debe	DECIMAL(16,2),
@Haber	DECIMAL(16,2)
AS 

DECLARE @Mensaje			VARCHAR(100)
		,@Id_Cta_Contable	INT
		,@Fecha		        DATETIME


BEGIN TRY
	BEGIN TRAN
	SET @Fecha = (SELECT Fecha FROM Cbtes WHERE Id_Trans = @Id_Trans)
	SET @Id_Cta_Contable = dbo.CF_Cta_Cont(@Alias,@Fecha)


	/*===================================================================*/
	INSERT INTO Cbtes_Ctas_Contables	(	Id_Trans		,Item		,Id_Cta_Contable
											,Fecha			,Debe		,Haber
											,Observacion	,Alias		,Id_Asiento
											,Id_Centro_Costo)
			   VALUES					(	@Id_Trans		,@Item		,@Id_Cta_Contable
											,@Fecha			,@Debe		,@Haber
											,''				,@Alias		,0
											,@Id_Centro_Costo)

	 
	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;   
