

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_pro_actividad_hito]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_pro_actividad_hito]
GO
CREATE PROCEDURE [reg_pro_actividad_hito]
	@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],
		[actividad_hito] AS [actividad_hito],
		[id_hito] AS [id_hito],
		[id_actividad] AS [id_actividad]
	FROM [pro_actividad_hito]
	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_pro_actividad_hito]')) DROP VIEW [dbo].[view_pro_actividad_hito]
GO
CREATE  VIEW [view_pro_actividad_hito] AS
SELECT 	[pro_actividad_hito].[id] AS [id],
		[pro_actividad_hito].[uid] AS [uid],
		[pro_actividad_hito].[eid] AS [eid],
		[pro_actividad_hito].[id_usuario_modifico] AS [id_usuario_modifico],
		[pro_actividad_hito].[id_usuario_creo] AS [id_usuario_creo],
		[pro_actividad_hito].[fechaModificacion] AS [fechaModificacion],
		[pro_actividad_hito].[fechaCreacion] AS [fechaCreacion],
		[pro_actividad_hito].[active] AS [active],
		[pro_actividad_hito].[actividad_hito] AS [actividad_hito],
		[pro_actividad_hito].[id_hito] AS [id_hito],
[pro_hito].[hito] as [pro_hito_hito],
[pro_hito].[hito_codigo] as [pro_hito_hito_codigo],
[pro_hito].[id_documento.proyecto] as [pro_hito_id_documento.proyecto],
		[pro_actividad_hito].[id_actividad] AS [id_actividad],
[pro_actividad].[actividad] as [pro_actividad_actividad],
[pro_actividad].[actividad_codigo] as [pro_actividad_actividad_codigo],
[pro_actividad].[fechainicioPlaneada] as [pro_actividad_fechainicioPlaneada],
[pro_actividad].[fechainicioProyectada] as [pro_actividad_fechainicioProyectada],
[pro_actividad].[fechaInicioReal] as [pro_actividad_fechaInicioReal],
[pro_actividad].[fechaTerminacionPlaneada] as [pro_actividad_fechaTerminacionPlaneada],
[pro_actividad].[fechaTerminacionProyectada] as [pro_actividad_fechaTerminacionProyectada],
[pro_actividad].[fechaTerminacionReal] as [pro_actividad_fechaTerminacionReal],
[pro_actividad].[descripcionDetallada] as [pro_actividad_descripcionDetallada],
[pro_actividad].[duracion] as [pro_actividad_duracion],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [pro_actividad_hito]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[pro_actividad_hito].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[pro_actividad_hito].[id_usuario_creo]
	INNER JOIN [pro_hito] ON [pro_hito].id=[pro_actividad_hito].[id_hito]
	INNER JOIN [pro_actividad] ON [pro_actividad].id=[pro_actividad_hito].[id_actividad]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [pro_actividad_hito].eid = [empresaCodigo].[codigo] and empresaCodigo.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_pro_actividad_hitosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXusuario_modifico]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_hito]
	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_pro_actividad_hitosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXusuario_creo]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_hito]
	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_pro_actividad_hitosXhito]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXhito]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXhito]
	@p_id_hito INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_hito]
	WHERE ([id_hito]= @p_id_hito)
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_pro_actividad_hitosXactividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXactividad]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXactividad]
	@p_id_actividad INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_hito]
	WHERE ([id_actividad]= @p_id_actividad)
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_pro_actividad_hitos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitos]
GO
CREATE PROCEDURE [sel_pro_actividad_hitos]
	
	@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_pro_actividad_hito]
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_pro_actividad_hitos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_pro_actividad_hitos]
GO
CREATE PROCEDURE [lis_pro_actividad_hitos]
	AS
BEGIN
	SELECT id AS id,
[actividad_hito] AS [pro_actividad_hito]
	FROM [pro_actividad_hito]
	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_pro_actividad_hito]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_pro_actividad_hito]
GO
CREATE PROCEDURE [upd_pro_actividad_hito]
	@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_actividad_hito varchar(300) = null,
		@p_id_hito int = null,
		@p_id_actividad int = null
AS
BEGIN
		UPDATE [pro_actividad_hito]
		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(),
			[actividad_hito] = isnull(@p_actividad_hito,[actividad_hito]),
			[id_hito] = isnull(@p_id_hito,[id_hito]),
			[id_actividad] = isnull(@p_id_actividad,[id_actividad])
		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_pro_actividad_hito]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_pro_actividad_hito]
GO
CREATE PROCEDURE [ins_pro_actividad_hito]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_actividad_hito varchar(300),
		@p_id_hito int,
		@p_id_actividad int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [pro_actividad_hito]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[actividad_hito],
			[id_hito],
			[id_actividad])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_actividad_hito,
			@p_id_hito,
			@p_id_actividad)
		SET @v_id = scope_identity()
UPDATE [pro_actividad_hito] 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_pro_actividad_hito]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_pro_actividad_hito]
GO
CREATE PROCEDURE [act_pro_actividad_hito]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [pro_actividad_hito]
	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_pro_actividad_hito_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_pro_actividad_hito_m]
GO
CREATE PROCEDURE [reg_pro_actividad_hito_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],
		[actividad_hito] AS [actividad_hito],
		[id_hito] AS [id_hito],
		[id_actividad] AS [id_actividad]
	FROM [pro_actividad_hito]
	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_pro_actividad_hitosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_hito]
	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_pro_actividad_hitosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_hito]
	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_pro_actividad_hitosXhito_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXhito_m]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXhito_m]
	@p_id_hito INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_hito]
	WHERE ([id_hito]= @p_id_hito)
	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_pro_actividad_hitosXactividad_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitosXactividad_m]
GO
CREATE PROCEDURE [sel_pro_actividad_hitosXactividad_m]
	@p_id_actividad INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_hito]
	WHERE ([id_actividad]= @p_id_actividad)
	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_pro_actividad_hitos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_hitos_m]
GO
CREATE PROCEDURE [sel_pro_actividad_hitos_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_pro_actividad_hito]
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_pro_actividad_hitos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_pro_actividad_hitos_m]
GO
CREATE PROCEDURE [lis_pro_actividad_hitos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[actividad_hito] AS [pro_actividad_hito]
	FROM [pro_actividad_hito]
	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_pro_actividad_hito]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_pro_actividad_hito]
GO
CREATE PROCEDURE [aud_pro_actividad_hito]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [pro_actividad_hito].id as id_tabla,
	[pro_actividad_hito].id_usuario_modifico as id_usuario_modifico,
	[pro_actividad_hito].id_usuario_creo as id_usuario_creo,
	[pro_actividad_hito].fechaModificacion as fechaModificacion,
	[pro_actividad_hito].fechaCreacion as fechaCreacion,
	[pro_actividad_hito].active as active,
	[pro_actividad_hito].[actividad_hito] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [pro_actividad_hito]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[pro_actividad_hito].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[pro_actividad_hito].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'pro_actividad_hito'
-----------------------------------17/07/2015 04:34:40 p.m.