IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_seg_registroPeticion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_seg_registroPeticion]
GO
CREATE PROCEDURE [reg_seg_registroPeticion]
	@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],
		[registroPeticion] AS [registroPeticion],
		[registroPeticion_codigo] AS [registroPeticion_codigo],
		[urlServicio] AS [urlServicio],
		[modulo] AS [modulo],
		[aplicacion] AS [aplicacion],
		[esExitosa] AS [esExitosa],
		[mensajeRespuesta] AS [mensajeRespuesta],
		[id_usuario] AS [id_usuario],
		[tamanoPeticion] AS [tamanoPeticion]
	FROM [seg_registroPeticion]
	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_registroPeticion]')) DROP VIEW [dbo].[view_seg_registroPeticion]
GO
CREATE  VIEW [view_seg_registroPeticion] AS
SELECT 	[seg_registroPeticion].[id] AS [id],
		[seg_registroPeticion].[uid] AS [uid],
		[seg_registroPeticion].[eid] AS [eid],
		[seg_registroPeticion].[id_usuario_modifico] AS [id_usuario_modifico],
		[seg_registroPeticion].[id_usuario_creo] AS [id_usuario_creo],
		[seg_registroPeticion].[fechaModificacion] AS [fechaModificacion],
		[seg_registroPeticion].[fechaCreacion] AS [fechaCreacion],
		[seg_registroPeticion].[active] AS [active],
		[seg_registroPeticion].[registroPeticion] AS [registroPeticion],
		[seg_registroPeticion].[registroPeticion_codigo] AS [registroPeticion_codigo],
		[seg_registroPeticion].[urlServicio] AS [urlServicio],
		[seg_registroPeticion].[modulo] AS [modulo],
		[seg_registroPeticion].[aplicacion] AS [aplicacion],
		[seg_registroPeticion].[esExitosa] AS [esExitosa],
		[seg_registroPeticion].[mensajeRespuesta] AS [mensajeRespuesta],
		[seg_registroPeticion].[id_usuario] AS [id_usuario],
[seg_usuario].[usuario] as [seg_usuario_usuario],
[seg_usuario].[usuario_codigo] as [seg_usuario_usuario_codigo],
[seg_usuario].[intentosFallidos] as [seg_usuario_intentosFallidos],
[seg_usuario].[numeroIngresos] as [seg_usuario_numeroIngresos],
[seg_usuario].[fechaUltimoIngreso_fh] as [seg_usuario_fechaUltimoIngreso_fh],
[seg_usuario].[fechaIntentoFallido_fh] as [seg_usuario_fechaIntentoFallido_fh],
[seg_usuario].[clave] as [seg_usuario_clave],
[seg_usuario].[nombre] as [seg_usuario_nombre],
[seg_usuario].[profesion] as [seg_usuario_profesion],
[seg_usuario].[email] as [seg_usuario_email],
[seg_usuario].[direccion] as [seg_usuario_direccion],
[seg_usuario].[telefono] as [seg_usuario_telefono],
[seg_usuario].[costoHora] as [seg_usuario_costoHora],
[seg_usuario].[porcentajeComision] as [seg_usuario_porcentajeComision],
[seg_usuario].[accesoActivo] as [seg_usuario_accesoActivo],
[seg_usuario].[cambiarClave] as [seg_usuario_cambiarClave],
[seg_usuario].[fechaUltimoCambioClave_fh] as [seg_usuario_fechaUltimoCambioClave_fh],
[seg_usuario].[aplicaRecargo] as [seg_usuario_aplicaRecargo],
[seg_usuario].[sexo] as [seg_usuario_sexo],
[seg_usuario].[id_perfil] as [seg_usuario_id_perfil],
[seg_usuario].[id_cargo] as [seg_usuario_id_cargo],
[seg_usuario].[id_grupo] as [seg_usuario_id_grupo],
[seg_usuario].[id_zona] as [seg_usuario_id_zona],
[seg_usuario].[identificacion] as [seg_usuario_identificacion],
[seg_usuario].[id_usuario] as [seg_usuario_id_usuario],
[seg_usuario].[preferencias] as [seg_usuario_preferencias],
[seg_usuario].[habilitado] as [seg_usuario_habilitado],
[seg_usuario].[idDispositivo] as [seg_usuario_idDispositivo],
		[seg_registroPeticion].[tamanoPeticion] AS [tamanoPeticion],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [seg_registroPeticion]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[seg_registroPeticion].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[seg_registroPeticion].[id_usuario_creo]
	INNER JOIN [seg_usuario] ON [seg_usuario].id=[seg_registroPeticion].[id_usuario]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [seg_registroPeticion].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [seg_registroPeticion].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_registroPeticionesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticionesXusuario_modifico]
GO
CREATE PROCEDURE [sel_seg_registroPeticionesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_registroPeticion]
	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_registroPeticionesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticionesXusuario_creo]
GO
CREATE PROCEDURE [sel_seg_registroPeticionesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_registroPeticion]
	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_registroPeticionesXusuario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticionesXusuario]
GO
CREATE PROCEDURE [sel_seg_registroPeticionesXusuario]
	@p_id_usuario INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_registroPeticion]
	WHERE ([id_usuario]= @p_id_usuario)
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_registroPeticiones]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticiones]
GO
CREATE PROCEDURE [sel_seg_registroPeticiones]
	
	@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_registroPeticion]
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_registroPeticiones]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_seg_registroPeticiones]
GO
CREATE PROCEDURE [lis_seg_registroPeticiones]
	AS
BEGIN
	SELECT id AS id,
[registroPeticion] AS [seg_registroPeticion]
	FROM [seg_registroPeticion]
	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_registroPeticion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_seg_registroPeticion]
GO
CREATE PROCEDURE [upd_seg_registroPeticion]
	@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_registroPeticion varchar(300) = null,
		@p_registroPeticion_codigo varchar(100) = null,
		@p_urlServicio varchar(100) = null,
		@p_modulo varchar(100) = null,
		@p_aplicacion varchar(100) = null,
		@p_esExitosa bit = null,
		@p_mensajeRespuesta varchar(1000) = null,
		@p_id_usuario int = null,
		@p_tamanoPeticion float = null
AS
BEGIN
		UPDATE [seg_registroPeticion]
		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(),
			[registroPeticion] = isnull(@p_registroPeticion,[registroPeticion]),
			[registroPeticion_codigo] = isnull(@p_registroPeticion_codigo,[registroPeticion_codigo]),
			[urlServicio] = isnull(@p_urlServicio,[urlServicio]),
			[modulo] = isnull(@p_modulo,[modulo]),
			[aplicacion] = isnull(@p_aplicacion,[aplicacion]),
			[esExitosa] = isnull(@p_esExitosa,[esExitosa]),
			[mensajeRespuesta] = isnull(@p_mensajeRespuesta,[mensajeRespuesta]),
			[id_usuario] = isnull(@p_id_usuario,[id_usuario]),
			[tamanoPeticion] = isnull(@p_tamanoPeticion,[tamanoPeticion])
		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_registroPeticion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_seg_registroPeticion]
GO
CREATE PROCEDURE [ins_seg_registroPeticion]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_registroPeticion varchar(300),
		@p_registroPeticion_codigo varchar(100),
		@p_urlServicio varchar(100),
		@p_modulo varchar(100),
		@p_aplicacion varchar(100),
		@p_esExitosa bit,
		@p_mensajeRespuesta varchar(1000),
		@p_id_usuario int,
		@p_tamanoPeticion float
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [seg_registroPeticion]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[registroPeticion],
			[registroPeticion_codigo],
			[urlServicio],
			[modulo],
			[aplicacion],
			[esExitosa],
			[mensajeRespuesta],
			[id_usuario],
			[tamanoPeticion])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_registroPeticion,
			@p_registroPeticion_codigo,
			@p_urlServicio,
			@p_modulo,
			@p_aplicacion,
			@p_esExitosa,
			@p_mensajeRespuesta,
			@p_id_usuario,
			@p_tamanoPeticion)
		SET @v_id = scope_identity()
UPDATE [seg_registroPeticion] 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_registroPeticion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_seg_registroPeticion]
GO
CREATE PROCEDURE [act_seg_registroPeticion]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [seg_registroPeticion]
	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_registroPeticion_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_seg_registroPeticion_m]
GO
CREATE PROCEDURE [reg_seg_registroPeticion_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],
		[registroPeticion] AS [registroPeticion],
		[registroPeticion_codigo] AS [registroPeticion_codigo],
		[urlServicio] AS [urlServicio],
		[modulo] AS [modulo],
		[aplicacion] AS [aplicacion],
		[esExitosa] AS [esExitosa],
		[mensajeRespuesta] AS [mensajeRespuesta],
		[id_usuario] AS [id_usuario],
		[tamanoPeticion] AS [tamanoPeticion]
	FROM [seg_registroPeticion]
	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_registroPeticionesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticionesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_seg_registroPeticionesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_registroPeticion]
	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_registroPeticionesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticionesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_seg_registroPeticionesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_registroPeticion]
	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_registroPeticionesXusuario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticionesXusuario_m]
GO
CREATE PROCEDURE [sel_seg_registroPeticionesXusuario_m]
	@p_id_usuario INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_registroPeticion]
	WHERE ([id_usuario]= @p_id_usuario)
	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_registroPeticiones_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_registroPeticiones_m]
GO
CREATE PROCEDURE [sel_seg_registroPeticiones_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_registroPeticion]
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_registroPeticiones_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_seg_registroPeticiones_m]
GO
CREATE PROCEDURE [lis_seg_registroPeticiones_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[registroPeticion] AS [seg_registroPeticion]
	FROM [seg_registroPeticion]
	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_registroPeticion]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_seg_registroPeticion]
GO
CREATE PROCEDURE [aud_seg_registroPeticion]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [seg_registroPeticion].id as id_tabla,
	[seg_registroPeticion].id_usuario_modifico as id_usuario_modifico,
	[seg_registroPeticion].id_usuario_creo as id_usuario_creo,
	[seg_registroPeticion].fechaModificacion as fechaModificacion,
	[seg_registroPeticion].fechaCreacion as fechaCreacion,
	[seg_registroPeticion].active as active,
	[seg_registroPeticion].[registroPeticion] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [seg_registroPeticion]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[seg_registroPeticion].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[seg_registroPeticion].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'seg_registroPeticion'
-----------------------------------23/05/21 20:46:22