
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_pro_reporteActividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_pro_reporteActividad]
GO
CREATE PROCEDURE [reg_pro_reporteActividad]
	@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],
		[reporteActividad] AS [reporteActividad],
		[reporteActividad_codigo] AS [reporteActividad_codigo],
		[id_actividad] AS [id_actividad],
		[id_SesionActividad] AS [id_SesionActividad],
		[id_ejecutores] AS [id_ejecutores],
		[id_sucursal] AS [id_sucursal],
		[fecha_inicio] AS [fecha_inicio],
		[duracion] AS [duracion],
		[texto] AS [texto],
		[porcentaje_avance] AS [porcentaje_avance]
	FROM [pro_reporteActividad]
	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_reporteActividad]')) DROP VIEW [dbo].[view_pro_reporteActividad]
GO
CREATE  VIEW [view_pro_reporteActividad] AS
SELECT 	[pro_reporteActividad].[id] AS [id],
		[pro_reporteActividad].[uid] AS [uid],
		[pro_reporteActividad].[eid] AS [eid],
		[pro_reporteActividad].[id_usuario_modifico] AS [id_usuario_modifico],
		[pro_reporteActividad].[id_usuario_creo] AS [id_usuario_creo],
		[pro_reporteActividad].[fechaModificacion] AS [fechaModificacion],
		[pro_reporteActividad].[fechaCreacion] AS [fechaCreacion],
		[pro_reporteActividad].[active] AS [active],
		[pro_reporteActividad].[reporteActividad] AS [reporteActividad],
		[pro_reporteActividad].[reporteActividad_codigo] AS [reporteActividad_codigo],
		[pro_reporteActividad].[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],
		[pro_reporteActividad].[id_SesionActividad] AS [id_SesionActividad],
[pro_SesionActividad].[SesionActividad] as [pro_SesionActividad_SesionActividad],
[pro_SesionActividad].[SesionActividad_codigo] as [pro_SesionActividad_SesionActividad_codigo],
[pro_SesionActividad].[id_actividad] as [pro_SesionActividad_id_actividad],
[pro_SesionActividad].[id_ejecutores] as [pro_SesionActividad_id_ejecutores],
[pro_SesionActividad].[id_GrupoSesion] as [pro_SesionActividad_id_GrupoSesion],
[pro_SesionActividad].[duracion] as [pro_SesionActividad_duracion],
[pro_SesionActividad].[descripcion] as [pro_SesionActividad_descripcion],
[pro_SesionActividad].[fecha_inicio] as [pro_SesionActividad_fecha_inicio],
		[pro_reporteActividad].[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_reporteActividad].[id_sucursal] AS [id_sucursal],
[ter_sucursal].[sucursal] as [ter_sucursal_sucursal],
[ter_sucursal].[sucursal_codigo] as [ter_sucursal_sucursal_codigo],
[ter_sucursal].[contacto] as [ter_sucursal_contacto],
[ter_sucursal].[telefono] as [ter_sucursal_telefono],
[ter_sucursal].[Fax] as [ter_sucursal_Fax],
[ter_sucursal].[Email] as [ter_sucursal_Email],
[ter_sucursal].[Direccion] as [ter_sucursal_Direccion],
[ter_sucursal].[paraVenta] as [ter_sucursal_paraVenta],
[ter_sucursal].[paraSoporte] as [ter_sucursal_paraSoporte],
[ter_sucursal].[paraAlquiler] as [ter_sucursal_paraAlquiler],
[ter_sucursal].[id_tercero] as [ter_sucursal_id_tercero],
[ter_sucursal].[id_zona] as [ter_sucursal_id_zona],
[ter_sucursal].[id_usuario_asesor] as [ter_sucursal_id_usuario_asesor],
[ter_sucursal].[id_usuario_tecnico] as [ter_sucursal_id_usuario_tecnico],
[ter_sucursal].[id_sucursal] as [ter_sucursal_id_sucursal],
--[ter_sucursal].[id_listaPrecio] as [ter_sucursal_id_listaPrecio],
[ter_sucursal].[id_estadoTercero] as [ter_sucursal_id_estadoTercero],
[ter_sucursal].[codigorecursiva] as [ter_sucursal_codigorecursiva],
		[pro_reporteActividad].[fecha_inicio] AS [fecha_inicio],
		[pro_reporteActividad].[duracion] AS [duracion],
		[pro_reporteActividad].[texto] AS [texto],
		[pro_reporteActividad].[porcentaje_avance] AS [porcentaje_avance],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [pro_reporteActividad]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[pro_reporteActividad].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[pro_reporteActividad].[id_usuario_creo]
	INNER JOIN [pro_actividad] ON [pro_actividad].id=[pro_reporteActividad].[id_actividad]
	INNER JOIN [pro_SesionActividad] ON [pro_SesionActividad].id=[pro_reporteActividad].[id_SesionActividad]
	INNER JOIN [pro_ejecutores] ON [pro_ejecutores].id=[pro_reporteActividad].[id_ejecutores]
	INNER JOIN [ter_sucursal] ON [ter_sucursal].id=[pro_reporteActividad].[id_sucursal]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [pro_reporteActividad].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [pro_reporteActividad].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_reporteActividadesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXusuario_modifico]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXusuario_creo]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXactividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXactividad]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXactividad]
	@p_id_actividad INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXSesionActividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXSesionActividad]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXSesionActividad]
	@p_id_SesionActividad INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_reporteActividad]
	WHERE ([id_SesionActividad]= @p_id_SesionActividad)
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_reporteActividadesXejecutores]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXejecutores]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXejecutores]
	@p_id_ejecutores INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXsucursal]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXsucursal]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXsucursal]
	@p_id_sucursal INT
AS
BEGIN
	SELECT * 
	FROM [view_pro_reporteActividad]
	WHERE ([id_sucursal]= @p_id_sucursal)
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_reporteActividades]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividades]
GO
CREATE PROCEDURE [sel_pro_reporteActividades]
	
	@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_reporteActividad]
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_reporteActividades]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_pro_reporteActividades]
GO
CREATE PROCEDURE [lis_pro_reporteActividades]
	AS
BEGIN
	SELECT id AS id,
[reporteActividad] AS [pro_reporteActividad]
	FROM [pro_reporteActividad]
	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_reporteActividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_pro_reporteActividad]
GO
CREATE PROCEDURE [upd_pro_reporteActividad]
	@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_reporteActividad varchar(300) = null,
		@p_reporteActividad_codigo varchar(100) = null,
		@p_id_actividad int = null,
		@p_id_SesionActividad int = null,
		@p_id_ejecutores int = null,
		@p_id_sucursal int = null,
		@p_fecha_inicio smalldatetime = null,
		@p_duracion float = null,
		@p_texto varchar(3000) = null,
		@p_porcentaje_avance float = null
AS
BEGIN
		UPDATE [pro_reporteActividad]
		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(),
			[reporteActividad] = isnull(@p_reporteActividad,[reporteActividad]),
			[reporteActividad_codigo] = isnull(@p_reporteActividad_codigo,[reporteActividad_codigo]),
			[id_actividad] = isnull(@p_id_actividad,[id_actividad]),
			[id_SesionActividad] = isnull(@p_id_SesionActividad,[id_SesionActividad]),
			[id_ejecutores] = isnull(@p_id_ejecutores,[id_ejecutores]),
			[id_sucursal] = isnull(@p_id_sucursal,[id_sucursal]),
			[fecha_inicio] = isnull(@p_fecha_inicio,[fecha_inicio]),
			[duracion] = isnull(@p_duracion,[duracion]),
			[texto] = isnull(@p_texto,[texto]),
			[porcentaje_avance] = isnull(@p_porcentaje_avance,[porcentaje_avance])
		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_reporteActividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_pro_reporteActividad]
GO
CREATE PROCEDURE [ins_pro_reporteActividad]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_reporteActividad varchar(300),
		@p_reporteActividad_codigo varchar(100),
		@p_id_actividad int,
		@p_id_SesionActividad int,
		@p_id_ejecutores int,
		@p_id_sucursal int,
		@p_fecha_inicio smalldatetime,
		@p_duracion float,
		@p_texto varchar(3000),
		@p_porcentaje_avance float
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [pro_reporteActividad]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[reporteActividad],
			[reporteActividad_codigo],
			[id_actividad],
			[id_SesionActividad],
			[id_ejecutores],
			[id_sucursal],
			[fecha_inicio],
			[duracion],
			[texto],
			[porcentaje_avance])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_reporteActividad,
			@p_reporteActividad_codigo,
			@p_id_actividad,
			@p_id_SesionActividad,
			@p_id_ejecutores,
			@p_id_sucursal,
			@p_fecha_inicio,
			@p_duracion,
			@p_texto,
			@p_porcentaje_avance)
		SET @v_id = scope_identity()
UPDATE [pro_reporteActividad] 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_reporteActividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_pro_reporteActividad]
GO
CREATE PROCEDURE [act_pro_reporteActividad]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [pro_reporteActividad]
	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_reporteActividad_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_pro_reporteActividad_m]
GO
CREATE PROCEDURE [reg_pro_reporteActividad_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],
		[reporteActividad] AS [reporteActividad],
		[reporteActividad_codigo] AS [reporteActividad_codigo],
		[id_actividad] AS [id_actividad],
		[id_SesionActividad] AS [id_SesionActividad],
		[id_ejecutores] AS [id_ejecutores],
		[id_sucursal] AS [id_sucursal],
		[fecha_inicio] AS [fecha_inicio],
		[duracion] AS [duracion],
		[texto] AS [texto],
		[porcentaje_avance] AS [porcentaje_avance]
	FROM [pro_reporteActividad]
	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_reporteActividadesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXactividad_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXactividad_m]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXactividad_m]
	@p_id_actividad INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXSesionActividad_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXSesionActividad_m]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXSesionActividad_m]
	@p_id_SesionActividad INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_reporteActividad]
	WHERE ([id_SesionActividad]= @p_id_SesionActividad)
	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_reporteActividadesXejecutores_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXejecutores_m]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXejecutores_m]
	@p_id_ejecutores INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_reporteActividad]
	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_reporteActividadesXsucursal_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividadesXsucursal_m]
GO
CREATE PROCEDURE [sel_pro_reporteActividadesXsucursal_m]
	@p_id_sucursal INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_pro_reporteActividad]
	WHERE ([id_sucursal]= @p_id_sucursal)
	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_reporteActividades_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_pro_reporteActividades_m]
GO
CREATE PROCEDURE [sel_pro_reporteActividades_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_reporteActividad]
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_reporteActividades_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_pro_reporteActividades_m]
GO
CREATE PROCEDURE [lis_pro_reporteActividades_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[reporteActividad] AS [pro_reporteActividad]
	FROM [pro_reporteActividad]
	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_reporteActividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_pro_reporteActividad]
GO
CREATE PROCEDURE [aud_pro_reporteActividad]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [pro_reporteActividad].id as id_tabla,
	[pro_reporteActividad].id_usuario_modifico as id_usuario_modifico,
	[pro_reporteActividad].id_usuario_creo as id_usuario_creo,
	[pro_reporteActividad].fechaModificacion as fechaModificacion,
	[pro_reporteActividad].fechaCreacion as fechaCreacion,
	[pro_reporteActividad].active as active,
	[pro_reporteActividad].[reporteActividad] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

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