

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_detalleBloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gui_detalleBloqueHome]
GO
CREATE PROCEDURE [reg_gui_detalleBloqueHome]
	@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],
		[detalleBloqueHome] AS [detalleBloqueHome],
		[detalleBloqueHome_codigo] AS [detalleBloqueHome_codigo],
		[id_bloqueHome] AS [id_bloqueHome],
		[tipoCampo] AS [tipoCampo],
		[orden] AS [orden],
		[tipoBloqueHome] AS [tipoBloqueHome],
		[estrategiaFecha] AS [estrategiaFecha],
		[itemsTab] AS [itemsTab],
		[posicionTab] AS [posicionTab],
		[ordenResultados] AS [ordenResultados]
	FROM [gui_detalleBloqueHome]
	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_detalleBloqueHome]')) DROP VIEW [dbo].[view_gui_detalleBloqueHome]
GO
CREATE  VIEW [view_gui_detalleBloqueHome] AS
SELECT 	[gui_detalleBloqueHome].[id] AS [id],
		[gui_detalleBloqueHome].[uid] AS [uid],
		[gui_detalleBloqueHome].[eid] AS [eid],
		[gui_detalleBloqueHome].[id_usuario_modifico] AS [id_usuario_modifico],
		[gui_detalleBloqueHome].[id_usuario_creo] AS [id_usuario_creo],
		[gui_detalleBloqueHome].[fechaModificacion] AS [fechaModificacion],
		[gui_detalleBloqueHome].[fechaCreacion] AS [fechaCreacion],
		[gui_detalleBloqueHome].[active] AS [active],
		[gui_detalleBloqueHome].[detalleBloqueHome] AS [detalleBloqueHome],
		[gui_detalleBloqueHome].[detalleBloqueHome_codigo] AS [detalleBloqueHome_codigo],
		[gui_detalleBloqueHome].[id_bloqueHome] AS [id_bloqueHome],
[gui_bloqueHome].[bloqueHome] as [gui_bloqueHome_bloqueHome],
[gui_bloqueHome].[bloqueHome_codigo] as [gui_bloqueHome_bloqueHome_codigo],
[gui_bloqueHome].[nombreControl] as [gui_bloqueHome_nombreControl],
[gui_bloqueHome].[urlBusqueda] as [gui_bloqueHome_urlBusqueda],
[gui_bloqueHome].[urlNuevo] as [gui_bloqueHome_urlNuevo],
[gui_bloqueHome].[orden] as [gui_bloqueHome_orden],
[gui_bloqueHome].[colorModulo] as [gui_bloqueHome_colorModulo],
[gui_bloqueHome].[esGenerico] as [gui_bloqueHome_esGenerico],
[gui_bloqueHome].[filtro] as [gui_bloqueHome_filtro],
		[gui_detalleBloqueHome].[tipoCampo] AS [tipoCampo],
		[gui_detalleBloqueHome].[orden] AS [orden],
		[gui_detalleBloqueHome].[tipoBloqueHome] AS [tipoBloqueHome],
		[gui_detalleBloqueHome].[estrategiaFecha] AS [estrategiaFecha],
		[gui_detalleBloqueHome].[itemsTab] AS [itemsTab],
		[gui_detalleBloqueHome].[posicionTab] AS [posicionTab],
		[gui_detalleBloqueHome].[ordenResultados] AS [ordenResultados],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [gui_detalleBloqueHome]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gui_detalleBloqueHome].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gui_detalleBloqueHome].[id_usuario_creo]
	INNER JOIN [gui_bloqueHome] ON [gui_bloqueHome].id=[gui_detalleBloqueHome].[id_bloqueHome]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [gui_detalleBloqueHome].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [gui_detalleBloqueHome].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_detalleBloqueHomesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomesXusuario_modifico]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_gui_detalleBloqueHome]
	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_detalleBloqueHomesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomesXusuario_creo]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_gui_detalleBloqueHome]
	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_detalleBloqueHomesXbloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomesXbloqueHome]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomesXbloqueHome]
	@p_id_bloqueHome INT
AS
BEGIN
	SELECT * 
	FROM [view_gui_detalleBloqueHome]
	WHERE ([id_bloqueHome]= @p_id_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].[sel_gui_detalleBloqueHomes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomes]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomes]
	
	@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_detalleBloqueHome]
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_detalleBloqueHomes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gui_detalleBloqueHomes]
GO
CREATE PROCEDURE [lis_gui_detalleBloqueHomes]
	AS
BEGIN
	SELECT id AS id,
[detalleBloqueHome] AS [gui_detalleBloqueHome]
	FROM [gui_detalleBloqueHome]
	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_detalleBloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_gui_detalleBloqueHome]
GO
CREATE PROCEDURE [upd_gui_detalleBloqueHome]
	@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_detalleBloqueHome varchar(300) = null,
		@p_detalleBloqueHome_codigo varchar(100) = null,
		@p_id_bloqueHome int = null,
		@p_tipoCampo int = null,
		@p_orden int = null,
		@p_tipoBloqueHome int = null,
		@p_estrategiaFecha int = null,
		@p_itemsTab int = null,
		@p_posicionTab int = null,
		@p_ordenResultados int = null
AS
BEGIN
		UPDATE [gui_detalleBloqueHome]
		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(),
			[detalleBloqueHome] = isnull(@p_detalleBloqueHome,[detalleBloqueHome]),
			[detalleBloqueHome_codigo] = isnull(@p_detalleBloqueHome_codigo,[detalleBloqueHome_codigo]),
			[id_bloqueHome] = isnull(@p_id_bloqueHome,[id_bloqueHome]),
			[tipoCampo] = isnull(@p_tipoCampo,[tipoCampo]),
			[orden] = isnull(@p_orden,[orden]),
			[tipoBloqueHome] = isnull(@p_tipoBloqueHome,[tipoBloqueHome]),
			[estrategiaFecha] = isnull(@p_estrategiaFecha,[estrategiaFecha]),
			[itemsTab] = isnull(@p_itemsTab,[itemsTab]),
			[posicionTab] = isnull(@p_posicionTab,[posicionTab]),
			[ordenResultados] = isnull(@p_ordenResultados,[ordenResultados])
		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_detalleBloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_gui_detalleBloqueHome]
GO
CREATE PROCEDURE [ins_gui_detalleBloqueHome]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_detalleBloqueHome varchar(300),
		@p_detalleBloqueHome_codigo varchar(100),
		@p_id_bloqueHome int,
		@p_tipoCampo int,
		@p_orden int,
		@p_tipoBloqueHome int,
		@p_estrategiaFecha int,
		@p_itemsTab int,
		@p_posicionTab int,
		@p_ordenResultados int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [gui_detalleBloqueHome]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[detalleBloqueHome],
			[detalleBloqueHome_codigo],
			[id_bloqueHome],
			[tipoCampo],
			[orden],
			[tipoBloqueHome],
			[estrategiaFecha],
			[itemsTab],
			[posicionTab],
			[ordenResultados])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_detalleBloqueHome,
			@p_detalleBloqueHome_codigo,
			@p_id_bloqueHome,
			@p_tipoCampo,
			@p_orden,
			@p_tipoBloqueHome,
			@p_estrategiaFecha,
			@p_itemsTab,
			@p_posicionTab,
			@p_ordenResultados)
		SET @v_id = scope_identity()
UPDATE [gui_detalleBloqueHome] 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_detalleBloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_gui_detalleBloqueHome]
GO
CREATE PROCEDURE [act_gui_detalleBloqueHome]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [gui_detalleBloqueHome]
	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_detalleBloqueHome_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gui_detalleBloqueHome_m]
GO
CREATE PROCEDURE [reg_gui_detalleBloqueHome_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],
		[detalleBloqueHome] AS [detalleBloqueHome],
		[detalleBloqueHome_codigo] AS [detalleBloqueHome_codigo],
		[id_bloqueHome] AS [id_bloqueHome],
		[tipoCampo] AS [tipoCampo],
		[orden] AS [orden],
		[tipoBloqueHome] AS [tipoBloqueHome],
		[estrategiaFecha] AS [estrategiaFecha],
		[itemsTab] AS [itemsTab],
		[posicionTab] AS [posicionTab],
		[ordenResultados] AS [ordenResultados]
	FROM [gui_detalleBloqueHome]
	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_detalleBloqueHomesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gui_detalleBloqueHome]
	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_detalleBloqueHomesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gui_detalleBloqueHome]
	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_detalleBloqueHomesXbloqueHome_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomesXbloqueHome_m]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomesXbloqueHome_m]
	@p_id_bloqueHome INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gui_detalleBloqueHome]
	WHERE ([id_bloqueHome]= @p_id_bloqueHome)
	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_detalleBloqueHomes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gui_detalleBloqueHomes_m]
GO
CREATE PROCEDURE [sel_gui_detalleBloqueHomes_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_detalleBloqueHome]
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_detalleBloqueHomes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gui_detalleBloqueHomes_m]
GO
CREATE PROCEDURE [lis_gui_detalleBloqueHomes_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[detalleBloqueHome] AS [gui_detalleBloqueHome]
	FROM [gui_detalleBloqueHome]
	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_detalleBloqueHome]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_gui_detalleBloqueHome]
GO
CREATE PROCEDURE [aud_gui_detalleBloqueHome]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [gui_detalleBloqueHome].id as id_tabla,
	[gui_detalleBloqueHome].id_usuario_modifico as id_usuario_modifico,
	[gui_detalleBloqueHome].id_usuario_creo as id_usuario_creo,
	[gui_detalleBloqueHome].fechaModificacion as fechaModificacion,
	[gui_detalleBloqueHome].fechaCreacion as fechaCreacion,
	[gui_detalleBloqueHome].active as active,
	[gui_detalleBloqueHome].[detalleBloqueHome] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [gui_detalleBloqueHome]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gui_detalleBloqueHome].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gui_detalleBloqueHome].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'gui_detalleBloqueHome'
-----------------------------------20/05/2013 03:43:21 p.m.