

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_pro_actividad_ejecutor]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_pro_actividad_ejecutor]
GO
CREATE PROCEDURE [reg_pro_actividad_ejecutor]
	@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_ejecutor] AS [actividad_ejecutor],
		[id_ejecutores] AS [id_ejecutores],
		[id_actividad] AS [id_actividad]
	FROM [pro_actividad_ejecutor]
	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_ejecutor]')) DROP VIEW [dbo].[view_pro_actividad_ejecutor]
GO
CREATE  VIEW [view_pro_actividad_ejecutor] AS
SELECT 	[pro_actividad_ejecutor].[id] AS [id],
		[pro_actividad_ejecutor].[uid] AS [uid],
		[pro_actividad_ejecutor].[eid] AS [eid],
		[pro_actividad_ejecutor].[id_usuario_modifico] AS [id_usuario_modifico],
		[pro_actividad_ejecutor].[id_usuario_creo] AS [id_usuario_creo],
		[pro_actividad_ejecutor].[fechaModificacion] AS [fechaModificacion],
		[pro_actividad_ejecutor].[fechaCreacion] AS [fechaCreacion],
		[pro_actividad_ejecutor].[active] AS [active],
		[pro_actividad_ejecutor].[actividad_ejecutor] AS [actividad_ejecutor],
		[pro_actividad_ejecutor].[id_ejecutores] AS [id_ejecutores],
[pro_ejecutores].[ejecutores] as [pro_ejecutores_ejecutores],
[pro_ejecutores].[ejecutores_codigo] as [pro_ejecutores_ejecutores_codigo],
[pro_ejecutores].[costo] as [pro_ejecutores_costo],
[pro_ejecutores].[unidadTiempo] as [pro_ejecutores_unidadTiempo],
[pro_ejecutores].[id_horarioEjecutores] as [pro_ejecutores_id_horarioEjecutores],
[pro_ejecutores].[id_usuario] as [pro_ejecutores_id_usuario],
		[pro_actividad_ejecutor].[id_actividad] AS [id_actividad],
[pro_actividad].[actividad] as [pro_actividad_actividad],
[pro_actividad].[actividad_codigo] as [pro_actividad_actividad_codigo],
[pro_actividad].[descripcionDetallada] as [pro_actividad_descripcionDetallada],
[pro_actividad].[fechainicioPlaneada] as [pro_actividad_fechainicioPlaneada],
[pro_actividad].[fechainicioProyectada] as [pro_actividad_fechainicioProyectada],
[pro_actividad].[fechaInicioReal] as [pro_actividad_fechaInicioReal],
[pro_actividad].[duracion] as [pro_actividad_duracion],
[pro_actividad].[fechaTerminacionPlaneada] as [pro_actividad_fechaTerminacionPlaneada],
[pro_actividad].[fechaTerminacionProyectada] as [pro_actividad_fechaTerminacionProyectada],
[pro_actividad].[fechaTerminacionReal] as [pro_actividad_fechaTerminacionReal],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [pro_actividad_ejecutor]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[pro_actividad_ejecutor].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[pro_actividad_ejecutor].[id_usuario_creo]
	INNER JOIN [pro_ejecutores] ON [pro_ejecutores].id=[pro_actividad_ejecutor].[id_ejecutores]
	INNER JOIN [pro_actividad] ON [pro_actividad].id=[pro_actividad_ejecutor].[id_actividad]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [pro_actividad_ejecutor].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_ejecutoresXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXusuario_modifico]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_ejecutor]
	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_ejecutoresXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXusuario_creo]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_ejecutor]
	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_ejecutoresXejecutores]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXejecutores]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXejecutores]
	@p_id_ejecutores INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_ejecutor]
	WHERE ([id_ejecutores]= @p_id_ejecutores)
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_ejecutoresXactividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXactividad]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXactividad]
	@p_id_actividad INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_actividad_ejecutor]
	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_ejecutores]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutores]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutores]
	
	@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_ejecutor]
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_ejecutores]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_pro_actividad_ejecutores]
GO
CREATE PROCEDURE [lis_pro_actividad_ejecutores]
	AS
BEGIN
	SELECT id AS id,
[actividad_ejecutor] AS [pro_actividad_ejecutor]
	FROM [pro_actividad_ejecutor]
	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_ejecutor]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_pro_actividad_ejecutor]
GO
CREATE PROCEDURE [upd_pro_actividad_ejecutor]
	@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_ejecutor varchar(300) = null,
		@p_id_ejecutores int = null,
		@p_id_actividad int = null
AS
BEGIN
		UPDATE [pro_actividad_ejecutor]
		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_ejecutor] = isnull(@p_actividad_ejecutor,[actividad_ejecutor]),
			[id_ejecutores] = isnull(@p_id_ejecutores,[id_ejecutores]),
			[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_ejecutor]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_pro_actividad_ejecutor]
GO
CREATE PROCEDURE [ins_pro_actividad_ejecutor]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_actividad_ejecutor varchar(300),
		@p_id_ejecutores int,
		@p_id_actividad int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [pro_actividad_ejecutor]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[actividad_ejecutor],
			[id_ejecutores],
			[id_actividad])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_actividad_ejecutor,
			@p_id_ejecutores,
			@p_id_actividad)
		SET @v_id = scope_identity()
UPDATE [pro_actividad_ejecutor] 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_ejecutor]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_pro_actividad_ejecutor]
GO
CREATE PROCEDURE [act_pro_actividad_ejecutor]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [pro_actividad_ejecutor]
	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_ejecutor_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_pro_actividad_ejecutor_m]
GO
CREATE PROCEDURE [reg_pro_actividad_ejecutor_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_ejecutor] AS [actividad_ejecutor],
		[id_ejecutores] AS [id_ejecutores],
		[id_actividad] AS [id_actividad]
	FROM [pro_actividad_ejecutor]
	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_ejecutoresXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_ejecutor]
	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_ejecutoresXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXusuario_creo_m]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_ejecutor]
	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_ejecutoresXejecutores_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXejecutores_m]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXejecutores_m]
	@p_id_ejecutores INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_ejecutor]
	WHERE ([id_ejecutores]= @p_id_ejecutores)
	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_ejecutoresXactividad_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutoresXactividad_m]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutoresXactividad_m]
	@p_id_actividad INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_actividad_ejecutor]
	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_ejecutores_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_actividad_ejecutores_m]
GO
CREATE PROCEDURE [sel_pro_actividad_ejecutores_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_ejecutor]
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_ejecutores_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_pro_actividad_ejecutores_m]
GO
CREATE PROCEDURE [lis_pro_actividad_ejecutores_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[actividad_ejecutor] AS [pro_actividad_ejecutor]
	FROM [pro_actividad_ejecutor]
	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_ejecutor]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_pro_actividad_ejecutor]
GO
CREATE PROCEDURE [aud_pro_actividad_ejecutor]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [pro_actividad_ejecutor].id as id_tabla,
	[pro_actividad_ejecutor].id_usuario_modifico as id_usuario_modifico,
	[pro_actividad_ejecutor].id_usuario_creo as id_usuario_creo,
	[pro_actividad_ejecutor].fechaModificacion as fechaModificacion,
	[pro_actividad_ejecutor].fechaCreacion as fechaCreacion,
	[pro_actividad_ejecutor].active as active,
	[pro_actividad_ejecutor].[actividad_ejecutor] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [pro_actividad_ejecutor]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[pro_actividad_ejecutor].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[pro_actividad_ejecutor].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'pro_actividad_ejecutor'
-----------------------------------14/07/2016 11:13:16