
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_gui_bloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gui_bloqueHome]
GO
CREATE PROCEDURE [reg_gui_bloqueHome]
	@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],
		[bloqueHome] AS [bloqueHome],
		[bloqueHome_codigo] AS [bloqueHome_codigo],
		[nombreControl] AS [nombreControl],
		[urlBusqueda] AS [urlBusqueda],
		[urlNuevo] AS [urlNuevo],
		[orden] AS [orden],
		[colorModulo] AS [colorModulo],
		[esGenerico] AS [esGenerico],
		[filtro] AS [filtro],
		[actualizacion] AS [actualizacion]
	FROM [gui_bloqueHome]
	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_gui_bloqueHome]')) DROP VIEW [dbo].[view_gui_bloqueHome]
GO
CREATE  VIEW [view_gui_bloqueHome] AS
SELECT 	[gui_bloqueHome].[id] AS [id],
		[gui_bloqueHome].[uid] AS [uid],
		[gui_bloqueHome].[eid] AS [eid],
		[gui_bloqueHome].[id_usuario_modifico] AS [id_usuario_modifico],
		[gui_bloqueHome].[id_usuario_creo] AS [id_usuario_creo],
		[gui_bloqueHome].[fechaModificacion] AS [fechaModificacion],
		[gui_bloqueHome].[fechaCreacion] AS [fechaCreacion],
		[gui_bloqueHome].[active] AS [active],
		[gui_bloqueHome].[bloqueHome] AS [bloqueHome],
		[gui_bloqueHome].[bloqueHome_codigo] AS [bloqueHome_codigo],
		[gui_bloqueHome].[nombreControl] AS [nombreControl],
		[gui_bloqueHome].[urlBusqueda] AS [urlBusqueda],
		[gui_bloqueHome].[urlNuevo] AS [urlNuevo],
		[gui_bloqueHome].[orden] AS [orden],
		[gui_bloqueHome].[colorModulo] AS [colorModulo],
		[gui_bloqueHome].[esGenerico] AS [esGenerico],
		[gui_bloqueHome].[filtro] AS [filtro],
		[gui_bloqueHome].[actualizacion] AS [actualizacion],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [gui_bloqueHome]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gui_bloqueHome].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gui_bloqueHome].[id_usuario_creo]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [gui_bloqueHome].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [gui_bloqueHome].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_gui_bloqueHomesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_bloqueHomesXusuario_modifico]
GO
CREATE PROCEDURE [sel_gui_bloqueHomesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_gui_bloqueHome]
	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_gui_bloqueHomesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_bloqueHomesXusuario_creo]
GO
CREATE PROCEDURE [sel_gui_bloqueHomesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_gui_bloqueHome]
	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_gui_bloqueHomes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_bloqueHomes]
GO
CREATE PROCEDURE [sel_gui_bloqueHomes]
	
	@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_gui_bloqueHome]
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_gui_bloqueHomes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gui_bloqueHomes]
GO
CREATE PROCEDURE [lis_gui_bloqueHomes]
	AS
BEGIN
	SELECT id AS id,
[bloqueHome] AS [gui_bloqueHome]
	FROM [gui_bloqueHome]
	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_gui_bloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_gui_bloqueHome]
GO
CREATE PROCEDURE [upd_gui_bloqueHome]
	@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_bloqueHome varchar(300) = null,
		@p_bloqueHome_codigo varchar(100) = null,
		@p_nombreControl varchar(100) = null,
		@p_urlBusqueda varchar(100) = null,
		@p_urlNuevo varchar(100) = null,
		@p_orden int = null,
		@p_colorModulo varchar(3) = null,
		@p_esGenerico bit = null,
		@p_filtro varchar(8000) = null,
		@p_actualizacion bit = null
AS
BEGIN
		UPDATE [gui_bloqueHome]
		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(),
			[bloqueHome] = isnull(@p_bloqueHome,[bloqueHome]),
			[bloqueHome_codigo] = isnull(@p_bloqueHome_codigo,[bloqueHome_codigo]),
			[nombreControl] = isnull(@p_nombreControl,[nombreControl]),
			[urlBusqueda] = isnull(@p_urlBusqueda,[urlBusqueda]),
			[urlNuevo] = isnull(@p_urlNuevo,[urlNuevo]),
			[orden] = isnull(@p_orden,[orden]),
			[colorModulo] = isnull(@p_colorModulo,[colorModulo]),
			[esGenerico] = isnull(@p_esGenerico,[esGenerico]),
			[filtro] = isnull(@p_filtro,[filtro]),
			[actualizacion] = isnull(@p_actualizacion,[actualizacion])
		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_gui_bloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_gui_bloqueHome]
GO
CREATE PROCEDURE [ins_gui_bloqueHome]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_bloqueHome varchar(300),
		@p_bloqueHome_codigo varchar(100),
		@p_nombreControl varchar(100),
		@p_urlBusqueda varchar(100),
		@p_urlNuevo varchar(100),
		@p_orden int,
		@p_colorModulo varchar(3),
		@p_esGenerico bit,
		@p_filtro varchar(8000),
		@p_actualizacion bit
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [gui_bloqueHome]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[bloqueHome],
			[bloqueHome_codigo],
			[nombreControl],
			[urlBusqueda],
			[urlNuevo],
			[orden],
			[colorModulo],
			[esGenerico],
			[filtro],
			[actualizacion])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_bloqueHome,
			@p_bloqueHome_codigo,
			@p_nombreControl,
			@p_urlBusqueda,
			@p_urlNuevo,
			@p_orden,
			@p_colorModulo,
			@p_esGenerico,
			@p_filtro,
			@p_actualizacion)
		SET @v_id = scope_identity()
UPDATE [gui_bloqueHome] 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_gui_bloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_gui_bloqueHome]
GO
CREATE PROCEDURE [act_gui_bloqueHome]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [gui_bloqueHome]
	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_gui_bloqueHome_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gui_bloqueHome_m]
GO
CREATE PROCEDURE [reg_gui_bloqueHome_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],
		[bloqueHome] AS [bloqueHome],
		[bloqueHome_codigo] AS [bloqueHome_codigo],
		[nombreControl] AS [nombreControl],
		[urlBusqueda] AS [urlBusqueda],
		[urlNuevo] AS [urlNuevo],
		[orden] AS [orden],
		[colorModulo] AS [colorModulo],
		[esGenerico] AS [esGenerico],
		[filtro] AS [filtro],
		[actualizacion] AS [actualizacion]
	FROM [gui_bloqueHome]
	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_gui_bloqueHomesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_bloqueHomesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_gui_bloqueHomesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gui_bloqueHome]
	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_gui_bloqueHomesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_bloqueHomesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_gui_bloqueHomesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gui_bloqueHome]
	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_gui_bloqueHomes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_bloqueHomes_m]
GO
CREATE PROCEDURE [sel_gui_bloqueHomes_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_gui_bloqueHome]
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_gui_bloqueHomes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gui_bloqueHomes_m]
GO
CREATE PROCEDURE [lis_gui_bloqueHomes_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[bloqueHome] AS [gui_bloqueHome]
	FROM [gui_bloqueHome]
	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_gui_bloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_gui_bloqueHome]
GO
CREATE PROCEDURE [aud_gui_bloqueHome]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [gui_bloqueHome].id as id_tabla,
	[gui_bloqueHome].id_usuario_modifico as id_usuario_modifico,
	[gui_bloqueHome].id_usuario_creo as id_usuario_creo,
	[gui_bloqueHome].fechaModificacion as fechaModificacion,
	[gui_bloqueHome].fechaCreacion as fechaCreacion,
	[gui_bloqueHome].active as active,
	[gui_bloqueHome].[bloqueHome] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [gui_bloqueHome]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gui_bloqueHome].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gui_bloqueHome].[id_usuario_creo]
	where ' + @p_filtro)
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_perfilesXbloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_perfilesXbloqueHome]
GO
CREATE PROCEDURE [sel_seg_perfilesXbloqueHome]
	@p_id_gui_bloqueHome INT
AS
BEGIN
	SELECT 	[seg_perfil_bloqueHome].[id] AS [I_id],
		[seg_perfil_bloqueHome].[uid] AS [I_uid],
		[seg_perfil_bloqueHome].[eid] AS [I_eid],
		[seg_perfil_bloqueHome].[fechaModificacion] AS [I_fechaModificacion],
		[seg_perfil_bloqueHome].[fechaCreacion] AS [I_fechaCreacion],
		[seg_perfil_bloqueHome].[active] AS [I_active],
		[seg_perfil_bloqueHome].[perfil_bloqueHome] AS [I_perfil_bloqueHome]
	FROM seg_perfil_bloqueHome INNER JOIN seg_perfil
	 ON [seg_perfil_bloqueHome].[id_perfil] = [seg_perfil].id
	WHERE	([seg_perfil_bloqueHome].[id_bloqueHome]= @p_id_gui_bloqueHome)
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_perfil_bloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_seg_perfil_bloqueHome]
GO
CREATE PROCEDURE [ins_seg_perfil_bloqueHome]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_perfil_bloqueHome varchar(300),
		@p_id_perfil int,
		@p_id_bloqueHome int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [seg_perfil_bloqueHome]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[perfil_bloqueHome],
			[id_perfil],
			[id_bloqueHome])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_perfil_bloqueHome,
			@p_id_perfil,
			@p_id_bloqueHome)
		SET @v_id = scope_identity()
UPDATE [seg_perfil_bloqueHome] 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].[upd_seg_perfil_bloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_seg_perfil_bloqueHome]
GO
CREATE PROCEDURE [upd_seg_perfil_bloqueHome]
	@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_perfil_bloqueHome varchar(300) = null,
		@p_id_perfil int = null,
		@p_id_bloqueHome int = null
AS
BEGIN
		UPDATE [seg_perfil_bloqueHome]
		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(),
			[perfil_bloqueHome] = isnull(@p_perfil_bloqueHome,[perfil_bloqueHome]),
			[id_perfil] = isnull(@p_id_perfil,[id_perfil]),
			[id_bloqueHome] = isnull(@p_id_bloqueHome,[id_bloqueHome])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'gui_bloqueHome'
-----------------------------------11/11/2021 9:40:48