
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_syn_campoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_syn_campoIntegracion]
GO
CREATE PROCEDURE [reg_syn_campoIntegracion]
	@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],
		[campoIntegracion] AS [campoIntegracion],
		[campoIntegracion_codigo] AS [campoIntegracion_codigo],
		[campoLocal] AS [campoLocal],
		[tablaAuxiliar] AS [tablaAuxiliar],
		[campoEnlace] AS [campoEnlace],
		[valorXDefecto] AS [valorXDefecto],
		[tipoDato] AS [tipoDato],
		[longitud] AS [longitud],
		[orden] AS [orden],
		[id_puntoIntegracion] AS [id_puntoIntegracion],
		[esLlave] AS [esLlave]
	FROM [syn_campoIntegracion]
	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_syn_campoIntegracion]')) DROP VIEW [dbo].[view_syn_campoIntegracion]
GO
CREATE  VIEW [view_syn_campoIntegracion] AS
SELECT 	[syn_campoIntegracion].[id] AS [id],
		[syn_campoIntegracion].[uid] AS [uid],
		[syn_campoIntegracion].[eid] AS [eid],
		[syn_campoIntegracion].[id_usuario_modifico] AS [id_usuario_modifico],
		[syn_campoIntegracion].[id_usuario_creo] AS [id_usuario_creo],
		[syn_campoIntegracion].[fechaModificacion] AS [fechaModificacion],
		[syn_campoIntegracion].[fechaCreacion] AS [fechaCreacion],
		[syn_campoIntegracion].[active] AS [active],
		[syn_campoIntegracion].[campoIntegracion] AS [campoIntegracion],
		[syn_campoIntegracion].[campoIntegracion_codigo] AS [campoIntegracion_codigo],
		[syn_campoIntegracion].[campoLocal] AS [campoLocal],
		[syn_campoIntegracion].[tablaAuxiliar] AS [tablaAuxiliar],
		[syn_campoIntegracion].[campoEnlace] AS [campoEnlace],
		[syn_campoIntegracion].[valorXDefecto] AS [valorXDefecto],
		[syn_campoIntegracion].[tipoDato] AS [tipoDato],
		[syn_campoIntegracion].[longitud] AS [longitud],
		[syn_campoIntegracion].[orden] AS [orden],
		[syn_campoIntegracion].[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].[id_puntoIntegracion] as [syn_puntoIntegracion_id_puntoIntegracion],
[syn_puntoIntegracion].[id_sistemaIntegrar] as [syn_puntoIntegracion_id_sistemaIntegrar],
[syn_puntoIntegracion].[urlConsumir] as [syn_puntoIntegracion_urlConsumir],
		[syn_campoIntegracion].[esLlave] AS [esLlave],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [syn_campoIntegracion]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[syn_campoIntegracion].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[syn_campoIntegracion].[id_usuario_creo]
	INNER JOIN [syn_puntoIntegracion] ON [syn_puntoIntegracion].id=[syn_campoIntegracion].[id_puntoIntegracion]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [syn_campoIntegracion].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [syn_campoIntegracion].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_syn_campoIntegracionesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegracionesXusuario_modifico]
GO
CREATE PROCEDURE [sel_syn_campoIntegracionesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_campoIntegracion]
	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_syn_campoIntegracionesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegracionesXusuario_creo]
GO
CREATE PROCEDURE [sel_syn_campoIntegracionesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_campoIntegracion]
	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_syn_campoIntegracionesXpuntoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegracionesXpuntoIntegracion]
GO
CREATE PROCEDURE [sel_syn_campoIntegracionesXpuntoIntegracion]
	@p_id_puntoIntegracion INT
AS
BEGIN
	SELECT * 
	FROM [view_syn_campoIntegracion]
	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_syn_campoIntegraciones]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegraciones]
GO
CREATE PROCEDURE [sel_syn_campoIntegraciones]
	
	@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_syn_campoIntegracion]
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_syn_campoIntegraciones]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_syn_campoIntegraciones]
GO
CREATE PROCEDURE [lis_syn_campoIntegraciones]
	AS
BEGIN
	SELECT id AS id,
[campoIntegracion] AS [syn_campoIntegracion]
	FROM [syn_campoIntegracion]
	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_syn_campoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_syn_campoIntegracion]
GO
CREATE PROCEDURE [upd_syn_campoIntegracion]
	@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_campoIntegracion varchar(300) = null,
		@p_campoIntegracion_codigo varchar(100) = null,
		@p_campoLocal varchar(200) = null,
		@p_tablaAuxiliar varchar(200) = null,
		@p_campoEnlace varchar(300) = null,
		@p_valorXDefecto varchar(200) = null,
		@p_tipoDato int = null,
		@p_longitud int = null,
		@p_orden int = null,
		@p_id_puntoIntegracion int = null,
		@p_esLlave bit = null
AS
BEGIN
		UPDATE [syn_campoIntegracion]
		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(),
			[campoIntegracion] = isnull(@p_campoIntegracion,[campoIntegracion]),
			[campoIntegracion_codigo] = isnull(@p_campoIntegracion_codigo,[campoIntegracion_codigo]),
			[campoLocal] = isnull(@p_campoLocal,[campoLocal]),
			[tablaAuxiliar] = isnull(@p_tablaAuxiliar,[tablaAuxiliar]),
			[campoEnlace] = isnull(@p_campoEnlace,[campoEnlace]),
			[valorXDefecto] = isnull(@p_valorXDefecto,[valorXDefecto]),
			[tipoDato] = isnull(@p_tipoDato,[tipoDato]),
			[longitud] = isnull(@p_longitud,[longitud]),
			[orden] = isnull(@p_orden,[orden]),
			[id_puntoIntegracion] = isnull(@p_id_puntoIntegracion,[id_puntoIntegracion]),
			[esLlave] = isnull(@p_esLlave,[esLlave])
		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_syn_campoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_syn_campoIntegracion]
GO
CREATE PROCEDURE [ins_syn_campoIntegracion]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_campoIntegracion varchar(300),
		@p_campoIntegracion_codigo varchar(100),
		@p_campoLocal varchar(200),
		@p_tablaAuxiliar varchar(200),
		@p_campoEnlace varchar(300),
		@p_valorXDefecto varchar(200),
		@p_tipoDato int,
		@p_longitud int,
		@p_orden int,
		@p_id_puntoIntegracion int,
		@p_esLlave bit
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [syn_campoIntegracion]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[campoIntegracion],
			[campoIntegracion_codigo],
			[campoLocal],
			[tablaAuxiliar],
			[campoEnlace],
			[valorXDefecto],
			[tipoDato],
			[longitud],
			[orden],
			[id_puntoIntegracion],
			[esLlave])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_campoIntegracion,
			@p_campoIntegracion_codigo,
			@p_campoLocal,
			@p_tablaAuxiliar,
			@p_campoEnlace,
			@p_valorXDefecto,
			@p_tipoDato,
			@p_longitud,
			@p_orden,
			@p_id_puntoIntegracion,
			@p_esLlave)
		SET @v_id = scope_identity()
UPDATE [syn_campoIntegracion] 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_syn_campoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_syn_campoIntegracion]
GO
CREATE PROCEDURE [act_syn_campoIntegracion]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [syn_campoIntegracion]
	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_syn_campoIntegracion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_syn_campoIntegracion_m]
GO
CREATE PROCEDURE [reg_syn_campoIntegracion_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],
		[campoIntegracion] AS [campoIntegracion],
		[campoIntegracion_codigo] AS [campoIntegracion_codigo],
		[campoLocal] AS [campoLocal],
		[tablaAuxiliar] AS [tablaAuxiliar],
		[campoEnlace] AS [campoEnlace],
		[valorXDefecto] AS [valorXDefecto],
		[tipoDato] AS [tipoDato],
		[longitud] AS [longitud],
		[orden] AS [orden],
		[id_puntoIntegracion] AS [id_puntoIntegracion],
		[esLlave] AS [esLlave]
	FROM [syn_campoIntegracion]
	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_syn_campoIntegracionesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegracionesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_syn_campoIntegracionesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_campoIntegracion]
	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_syn_campoIntegracionesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegracionesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_syn_campoIntegracionesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_campoIntegracion]
	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_syn_campoIntegracionesXpuntoIntegracion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegracionesXpuntoIntegracion_m]
GO
CREATE PROCEDURE [sel_syn_campoIntegracionesXpuntoIntegracion_m]
	@p_id_puntoIntegracion INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_syn_campoIntegracion]
	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_syn_campoIntegraciones_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_syn_campoIntegraciones_m]
GO
CREATE PROCEDURE [sel_syn_campoIntegraciones_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_syn_campoIntegracion]
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_syn_campoIntegraciones_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_syn_campoIntegraciones_m]
GO
CREATE PROCEDURE [lis_syn_campoIntegraciones_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[campoIntegracion] AS [syn_campoIntegracion]
	FROM [syn_campoIntegracion]
	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_syn_campoIntegracion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_syn_campoIntegracion]
GO
CREATE PROCEDURE [aud_syn_campoIntegracion]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [syn_campoIntegracion].id as id_tabla,
	[syn_campoIntegracion].id_usuario_modifico as id_usuario_modifico,
	[syn_campoIntegracion].id_usuario_creo as id_usuario_creo,
	[syn_campoIntegracion].fechaModificacion as fechaModificacion,
	[syn_campoIntegracion].fechaCreacion as fechaCreacion,
	[syn_campoIntegracion].active as active,
	[syn_campoIntegracion].[campoIntegracion] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [syn_campoIntegracion]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[syn_campoIntegracion].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[syn_campoIntegracion].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'syn_campoIntegracion'
-----------------------------------20/08/2020 8:35:21 a. m.