SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_seg_registroIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_seg_registroIntegracion]
GO
CREATE PROCEDURE [reg_seg_registroIntegracion]
	@p_id INT
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[registroIntegracion] AS [registroIntegracion],
		[registroIntegracion_codigo] AS [registroIntegracion_codigo],
		[mensaje] AS [mensaje],
		[respuesta] AS [respuesta],
		[codigoRespuesta] AS [codigoRespuesta],
		[idObjeto] AS [idObjeto],
		[id_puntoIntegracion] AS [id_puntoIntegracion],
		[numeroReintento] AS [numeroReintento]
	FROM [seg_registroIntegracion]
	WHERE	(id = @p_id)

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_seg_registroIntegracion]')) DROP VIEW [dbo].[view_seg_registroIntegracion]
GO
CREATE  VIEW [view_seg_registroIntegracion] AS
SELECT 	[seg_registroIntegracion].[id] AS [id],
		[seg_registroIntegracion].[uid] AS [uid],
		[seg_registroIntegracion].[eid] AS [eid],
		[seg_registroIntegracion].[id_usuario_modifico] AS [id_usuario_modifico],
		[seg_registroIntegracion].[id_usuario_creo] AS [id_usuario_creo],
		[seg_registroIntegracion].[fechaModificacion] AS [fechaModificacion],
		[seg_registroIntegracion].[fechaCreacion] AS [fechaCreacion],
		[seg_registroIntegracion].[active] AS [active],
		[seg_registroIntegracion].[registroIntegracion] AS [registroIntegracion],
		[seg_registroIntegracion].[registroIntegracion_codigo] AS [registroIntegracion_codigo],
		[seg_registroIntegracion].[mensaje] AS [mensaje],
		[seg_registroIntegracion].[respuesta] AS [respuesta],
		[seg_registroIntegracion].[codigoRespuesta] AS [codigoRespuesta],
		[seg_registroIntegracion].[idObjeto] AS [idObjeto],
		[seg_registroIntegracion].[id_puntoIntegracion] AS [id_puntoIntegracion],
[syn_puntoIntegracion].[puntoIntegracion] as [syn_puntoIntegracion_puntoIntegracion],
[syn_puntoIntegracion].[puntoIntegracion_codigo] as [syn_puntoIntegracion_puntoIntegracion_codigo],
[syn_puntoIntegracion].[tablaLocal] as [syn_puntoIntegracion_tablaLocal],
[syn_puntoIntegracion].[condicion] as [syn_puntoIntegracion_condicion],
[syn_puntoIntegracion].[urlConsumir] as [syn_puntoIntegracion_urlConsumir],
[syn_puntoIntegracion].[id_puntoIntegracion] as [syn_puntoIntegracion_id_puntoIntegracion],
[syn_puntoIntegracion].[id_sistemaIntegrar] as [syn_puntoIntegracion_id_sistemaIntegrar],
[syn_puntoIntegracion].[metodo] as [syn_puntoIntegracion_metodo],
[syn_puntoIntegracion].[cantidadReintentos] as [syn_puntoIntegracion_cantidadReintentos],
[syn_puntoIntegracion].[intervaloReintentos] as [syn_puntoIntegracion_intervaloReintentos],
[syn_puntoIntegracion].[codigosReintentos] as [syn_puntoIntegracion_codigosReintentos],
		[seg_registroIntegracion].[numeroReintento] AS [numeroReintento],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [seg_registroIntegracion]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[seg_registroIntegracion].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[seg_registroIntegracion].[id_usuario_creo]
	INNER JOIN [syn_puntoIntegracion] ON [syn_puntoIntegracion].id=[seg_registroIntegracion].[id_puntoIntegracion]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [seg_registroIntegracion].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [seg_registroIntegracion].active=1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegracionesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegracionesXusuario_modifico]
GO
CREATE PROCEDURE [sel_seg_registroIntegracionesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_registroIntegracion]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegracionesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegracionesXusuario_creo]
GO
CREATE PROCEDURE [sel_seg_registroIntegracionesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_registroIntegracion]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegracionesXpuntoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegracionesXpuntoIntegracion]
GO
CREATE PROCEDURE [sel_seg_registroIntegracionesXpuntoIntegracion]
	@p_id_puntoIntegracion INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_registroIntegracion]
	WHERE ([id_puntoIntegracion]= @p_id_puntoIntegracion)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegraciones]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegraciones]
GO
CREATE PROCEDURE [sel_seg_registroIntegraciones]
	
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_seg_registroIntegracion]
WHERE (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_seg_registroIntegraciones]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_seg_registroIntegraciones]
GO
CREATE PROCEDURE [lis_seg_registroIntegraciones]
	AS
BEGIN
	SELECT id AS id,
[registroIntegracion] AS [seg_registroIntegracion]
	FROM [seg_registroIntegracion]
	WHERE active = 1
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[upd_seg_registroIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_seg_registroIntegracion]
GO
CREATE PROCEDURE [upd_seg_registroIntegracion]
	@p_id int = null,
		@p_uid varchar(500) = null,
		@p_eid varchar(50) = null,
		@p_id_usuario_modifico int = null,
		@p_id_usuario_creo int = null,
		@p_fechaCreacion smalldatetime = null,
		@p_registroIntegracion varchar(300) = null,
		@p_registroIntegracion_codigo varchar(100) = null,
		@p_mensaje varchar(8000) = null,
		@p_respuesta varchar(8000) = null,
		@p_codigoRespuesta varchar(20) = null,
		@p_idObjeto int = null,
		@p_id_puntoIntegracion int = null,
		@p_numeroReintento int = null
AS
BEGIN
		UPDATE [seg_registroIntegracion]
		SET	[uid] = isnull(@p_uid,[uid]),
			[eid] = isnull(@p_eid,[eid]),
			[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
			[id_usuario_creo] = isnull(@p_id_usuario_creo,[id_usuario_creo]),
			[fechaModificacion] = GETDATE(),
			[registroIntegracion] = isnull(@p_registroIntegracion,[registroIntegracion]),
			[registroIntegracion_codigo] = isnull(@p_registroIntegracion_codigo,[registroIntegracion_codigo]),
			[mensaje] = isnull(@p_mensaje,[mensaje]),
			[respuesta] = isnull(@p_respuesta,[respuesta]),
			[codigoRespuesta] = isnull(@p_codigoRespuesta,[codigoRespuesta]),
			[idObjeto] = isnull(@p_idObjeto,[idObjeto]),
			[id_puntoIntegracion] = isnull(@p_id_puntoIntegracion,[id_puntoIntegracion]),
			[numeroReintento] = isnull(@p_numeroReintento,[numeroReintento])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ins_seg_registroIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_seg_registroIntegracion]
GO
CREATE PROCEDURE [ins_seg_registroIntegracion]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_registroIntegracion varchar(300),
		@p_registroIntegracion_codigo varchar(100),
		@p_mensaje varchar(8000),
		@p_respuesta varchar(8000),
		@p_codigoRespuesta varchar(20),
		@p_idObjeto int,
		@p_id_puntoIntegracion int,
		@p_numeroReintento int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [seg_registroIntegracion]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[registroIntegracion],
			[registroIntegracion_codigo],
			[mensaje],
			[respuesta],
			[codigoRespuesta],
			[idObjeto],
			[id_puntoIntegracion],
			[numeroReintento])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_registroIntegracion,
			@p_registroIntegracion_codigo,
			@p_mensaje,
			@p_respuesta,
			@p_codigoRespuesta,
			@p_idObjeto,
			@p_id_puntoIntegracion,
			@p_numeroReintento)
		SET @v_id = scope_identity()
UPDATE [seg_registroIntegracion] set [uid] = [uid] + '_' + convert(varchar(20),@v_id) where [id]=@v_id
SELECT @v_id as id
RETURN @v_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[act_seg_registroIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_seg_registroIntegracion]
GO
CREATE PROCEDURE [act_seg_registroIntegracion]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [seg_registroIntegracion]
	SET active=@p_active,
	[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
	[fechaModificacion] = GETDATE()
	WHERE	(id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_seg_registroIntegracion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_seg_registroIntegracion_m]
GO
CREATE PROCEDURE [reg_seg_registroIntegracion_m]
	@p_id INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[registroIntegracion] AS [registroIntegracion],
		[registroIntegracion_codigo] AS [registroIntegracion_codigo],
		[mensaje] AS [mensaje],
		[respuesta] AS [respuesta],
		[codigoRespuesta] AS [codigoRespuesta],
		[idObjeto] AS [idObjeto],
		[id_puntoIntegracion] AS [id_puntoIntegracion],
		[numeroReintento] AS [numeroReintento]
	FROM [seg_registroIntegracion]
	WHERE	(id = @p_id)
	AND	(eid LIKE @p_eid+'%')

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegracionesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegracionesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_seg_registroIntegracionesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_registroIntegracion]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegracionesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegracionesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_seg_registroIntegracionesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_registroIntegracion]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegracionesXpuntoIntegracion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegracionesXpuntoIntegracion_m]
GO
CREATE PROCEDURE [sel_seg_registroIntegracionesXpuntoIntegracion_m]
	@p_id_puntoIntegracion INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_registroIntegracion]
	WHERE ([id_puntoIntegracion]= @p_id_puntoIntegracion)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_seg_registroIntegraciones_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroIntegraciones_m]
GO
CREATE PROCEDURE [sel_seg_registroIntegraciones_m]
	@p_eid as varchar (50)='',
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_seg_registroIntegracion]
WHERE  (eid like '''+@p_eid+'%'+''' ) AND (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_seg_registroIntegraciones_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_seg_registroIntegraciones_m]
GO
CREATE PROCEDURE [lis_seg_registroIntegraciones_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[registroIntegracion] AS [seg_registroIntegracion]
	FROM [seg_registroIntegracion]
	WHERE active = 1
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aud_seg_registroIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_seg_registroIntegracion]
GO
CREATE PROCEDURE [aud_seg_registroIntegracion]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [seg_registroIntegracion].id as id_tabla,
	[seg_registroIntegracion].id_usuario_modifico as id_usuario_modifico,
	[seg_registroIntegracion].id_usuario_creo as id_usuario_creo,
	[seg_registroIntegracion].fechaModificacion as fechaModificacion,
	[seg_registroIntegracion].fechaCreacion as fechaCreacion,
	[seg_registroIntegracion].active as active,
	[seg_registroIntegracion].[registroIntegracion] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [seg_registroIntegracion]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[seg_registroIntegracion].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[seg_registroIntegracion].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'seg_registroIntegracion'
-----------------------------------6/10/2023 21:59:14