---29/11/2014 12:14:22 p.m.
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_tarea]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_tarea]
GO
CREATE PROCEDURE [reg_doc_tarea]
	@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],
		[tarea] AS [tarea],
		[tarea_codigo] AS [tarea_codigo],
		[id_catalogo] AS [id_catalogo],
		[id_cargo] AS [id_cargo],
		[fechaPlaneada_fh] AS [fechaPlaneada_fh],
		[porcentajeAvance] AS [porcentajeAvance],
		[id_documento] AS [id_documento]
	FROM [doc_tarea]
	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_doc_tarea]')) DROP VIEW [dbo].[view_doc_tarea]
GO
CREATE  VIEW [view_doc_tarea] AS
SELECT 	[doc_tarea].[id] AS [id],
		[doc_tarea].[uid] AS [uid],
		[doc_tarea].[eid] AS [eid],
		[doc_tarea].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_tarea].[id_usuario_creo] AS [id_usuario_creo],
		[doc_tarea].[fechaModificacion] AS [fechaModificacion],
		[doc_tarea].[fechaCreacion] AS [fechaCreacion],
		[doc_tarea].[active] AS [active],
		[doc_tarea].[tarea] AS [tarea],
		[doc_tarea].[tarea_codigo] AS [tarea_codigo],
		[doc_tarea].[id_catalogo] AS [id_catalogo],
[cat_catalogo].[catalogo] as [cat_catalogo_catalogo],
[cat_catalogo].[catalogo_codigo] as [cat_catalogo_catalogo_codigo],
[cat_catalogo].[codigoInventario] as [cat_catalogo_codigoInventario],
[cat_catalogo].[precioVenta] as [cat_catalogo_precioVenta],
[cat_catalogo].[tiempoConsecucion] as [cat_catalogo_tiempoConsecucion],
[cat_catalogo].[esNacional] as [cat_catalogo_esNacional],
[cat_catalogo].[id_familia] as [cat_catalogo_id_familia],
[cat_catalogo].[id_subTipoCatalogo] as [cat_catalogo_id_subTipoCatalogo],
[cat_catalogo].[id_unidad] as [cat_catalogo_id_unidad],
[cat_catalogo].[id_impuesto] as [cat_catalogo_id_impuesto],
[cat_catalogo].[descripcion] as [cat_catalogo_descripcion],
[cat_catalogo].[bloquearCostear] as [cat_catalogo_bloquearCostear],
		[doc_tarea].[id_cargo] AS [id_cargo],
[seg_cargo].[cargo] as [seg_cargo_cargo],
[seg_cargo].[cargo_codigo] as [seg_cargo_cargo_codigo],
[seg_cargo].[esTecnico] as [seg_cargo_esTecnico],
[seg_cargo].[esComercial] as [seg_cargo_esComercial],
[seg_cargo].[esCoordinador] as [seg_cargo_esCoordinador],
[seg_cargo].[valorHora] as [seg_cargo_valorHora],
[seg_cargo].[esAdministrativo] as [seg_cargo_esAdministrativo],
		[doc_tarea].[fechaPlaneada_fh] AS [fechaPlaneada_fh],
		[doc_tarea].[porcentajeAvance] AS [porcentajeAvance],
		[doc_tarea].[id_documento] AS [id_documento],
[doc_documento].[documento] as [doc_documento_documento],
[doc_documento].[documento_codigo] as [doc_documento_documento_codigo],
[doc_documento].[documento_numero] as [doc_documento_documento_numero],
[doc_documento].[prefijo] as [doc_documento_prefijo],
[doc_documento].[subtotal] as [doc_documento_subtotal],
[doc_documento].[descuento] as [doc_documento_descuento],
[doc_documento].[iva] as [doc_documento_iva],
[doc_documento].[total] as [doc_documento_total],
[doc_documento].[costo] as [doc_documento_costo],
[doc_documento].[rentabilidad] as [doc_documento_rentabilidad],
[doc_documento].[trm] as [doc_documento_trm],
[doc_documento].[fecha_fh] as [doc_documento_fecha_fh],
[doc_documento].[fechaSugerida_fh] as [doc_documento_fechaSugerida_fh],
[doc_documento].[fechaCierre_ff] as [doc_documento_fechaCierre_ff],
[doc_documento].[fechaLimite_fh] as [doc_documento_fechaLimite_fh],
[doc_documento].[id_subtipoDocumento] as [doc_documento_id_subtipoDocumento],
[doc_documento].[id_tercero_cliente] as [doc_documento_id_tercero_cliente],
[doc_documento].[id_documento] as [doc_documento_id_documento],
[doc_documento].[id_tercero_proveedor] as [doc_documento_id_tercero_proveedor],
[doc_documento].[id_prioridadDocumento] as [doc_documento_id_prioridadDocumento],
[doc_documento].[id_moneda] as [doc_documento_id_moneda],
[doc_documento].[id_estadoTipoDocumento] as [doc_documento_id_estadoTipoDocumento],
[doc_documento].[id_motivoestado] as [doc_documento_id_motivoestado],
[doc_documento].[subtotalPlaneado] as [doc_documento_subtotalPlaneado],
[doc_documento].[descuentoPlaneado] as [doc_documento_descuentoPlaneado],
[doc_documento].[ivaPlaneado] as [doc_documento_ivaPlaneado],
[doc_documento].[totalPlaneado] as [doc_documento_totalPlaneado],
[doc_documento].[costoPlaneado] as [doc_documento_costoPlaneado],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_tarea]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_tarea].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_tarea].[id_usuario_creo]
	INNER JOIN [cat_catalogo] ON [cat_catalogo].id=[doc_tarea].[id_catalogo]
	INNER JOIN [seg_cargo] ON [seg_cargo].id=[doc_tarea].[id_cargo]
	INNER JOIN [doc_documento] ON [doc_documento].id=[doc_tarea].[id_documento]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_tarea].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [doc_tarea].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_doc_tareasXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXusuario_modifico]
GO
CREATE PROCEDURE [sel_doc_tareasXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_tarea]
	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_doc_tareasXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXusuario_creo]
GO
CREATE PROCEDURE [sel_doc_tareasXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_tarea]
	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_doc_tareasXcatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXcatalogo]
GO
CREATE PROCEDURE [sel_doc_tareasXcatalogo]
	@p_id_catalogo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_tarea]
	WHERE ([id_catalogo]= @p_id_catalogo)
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_doc_tareasXcargo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXcargo]
GO
CREATE PROCEDURE [sel_doc_tareasXcargo]
	@p_id_cargo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_tarea]
	WHERE ([id_cargo]= @p_id_cargo)
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_doc_tareasXdocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXdocumento]
GO
CREATE PROCEDURE [sel_doc_tareasXdocumento]
	@p_id_documento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_tarea]
	WHERE ([id_documento]= @p_id_documento)
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_doc_tareas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareas]
GO
CREATE PROCEDURE [sel_doc_tareas]
	
	@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_doc_tarea]
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_doc_tareas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_tareas]
GO
CREATE PROCEDURE [lis_doc_tareas]
	AS
BEGIN
	SELECT id AS id,
[tarea] AS [doc_tarea]
	FROM [doc_tarea]
	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_doc_tarea]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_tarea]
GO
CREATE PROCEDURE [upd_doc_tarea]
	@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_tarea varchar(300) = null,
		@p_tarea_codigo varchar(100) = null,
		@p_id_catalogo int = null,
		@p_id_cargo int = null,
		@p_fechaPlaneada_fh smalldatetime = null,
		@p_porcentajeAvance int = null,
		@p_id_documento int = null
AS
BEGIN
		UPDATE [doc_tarea]
		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(),
			[tarea] = isnull(@p_tarea,[tarea]),
			[tarea_codigo] = isnull(@p_tarea_codigo,[tarea_codigo]),
			[id_catalogo] = isnull(@p_id_catalogo,[id_catalogo]),
			[id_cargo] = isnull(@p_id_cargo,[id_cargo]),
			[fechaPlaneada_fh] = isnull(@p_fechaPlaneada_fh,[fechaPlaneada_fh]),
			[porcentajeAvance] = isnull(@p_porcentajeAvance,[porcentajeAvance]),
			[id_documento] = isnull(@p_id_documento,[id_documento])
		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_doc_tarea]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_tarea]
GO
CREATE PROCEDURE [ins_doc_tarea]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_tarea varchar(300),
		@p_tarea_codigo varchar(100),
		@p_id_catalogo int,
		@p_id_cargo int,
		@p_fechaPlaneada_fh smalldatetime,
		@p_porcentajeAvance int,
		@p_id_documento int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_tarea]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[tarea],
			[tarea_codigo],
			[id_catalogo],
			[id_cargo],
			[fechaPlaneada_fh],
			[porcentajeAvance],
			[id_documento])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_tarea,
			@p_tarea_codigo,
			@p_id_catalogo,
			@p_id_cargo,
			@p_fechaPlaneada_fh,
			@p_porcentajeAvance,
			@p_id_documento)
		SET @v_id = scope_identity()
UPDATE [doc_tarea] 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_doc_tarea]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_doc_tarea]
GO
CREATE PROCEDURE [act_doc_tarea]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [doc_tarea]
	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_doc_tarea_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_tarea_m]
GO
CREATE PROCEDURE [reg_doc_tarea_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],
		[tarea] AS [tarea],
		[tarea_codigo] AS [tarea_codigo],
		[id_catalogo] AS [id_catalogo],
		[id_cargo] AS [id_cargo],
		[fechaPlaneada_fh] AS [fechaPlaneada_fh],
		[porcentajeAvance] AS [porcentajeAvance],
		[id_documento] AS [id_documento]
	FROM [doc_tarea]
	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_doc_tareasXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_doc_tareasXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_tarea]
	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_doc_tareasXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXusuario_creo_m]
GO
CREATE PROCEDURE [sel_doc_tareasXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_tarea]
	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_doc_tareasXcatalogo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXcatalogo_m]
GO
CREATE PROCEDURE [sel_doc_tareasXcatalogo_m]
	@p_id_catalogo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_tarea]
	WHERE ([id_catalogo]= @p_id_catalogo)
	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_doc_tareasXcargo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXcargo_m]
GO
CREATE PROCEDURE [sel_doc_tareasXcargo_m]
	@p_id_cargo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_tarea]
	WHERE ([id_cargo]= @p_id_cargo)
	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_doc_tareasXdocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareasXdocumento_m]
GO
CREATE PROCEDURE [sel_doc_tareasXdocumento_m]
	@p_id_documento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_tarea]
	WHERE ([id_documento]= @p_id_documento)
	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_doc_tareas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_tareas_m]
GO
CREATE PROCEDURE [sel_doc_tareas_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_doc_tarea]
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_doc_tareas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_tareas_m]
GO
CREATE PROCEDURE [lis_doc_tareas_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[tarea] AS [doc_tarea]
	FROM [doc_tarea]
	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_doc_tarea]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_doc_tarea]
GO
CREATE PROCEDURE [aud_doc_tarea]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [doc_tarea].id as id_tabla,
	[doc_tarea].id_usuario_modifico as id_usuario_modifico,
	[doc_tarea].id_usuario_creo as id_usuario_creo,
	[doc_tarea].fechaModificacion as fechaModificacion,
	[doc_tarea].fechaCreacion as fechaCreacion,
	[doc_tarea].active as active,
	[doc_tarea].[tarea] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [doc_tarea]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_tarea].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_tarea].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'doc_tarea'
--------------------------------

---29/11/2014 01:42:57 p.m.
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_tarea_aux]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_tarea_aux]
GO
CREATE PROCEDURE [reg_doc_tarea_aux]
	@p_id INT
AS
BEGIN
	SELECT [doc_tarea_aux].*
	FROM [doc_tarea] INNER JOIN [doc_tarea_aux]
	ON [doc_tarea].uid = [doc_tarea_aux].uid
	WHERE	[doc_tarea].id = @p_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
