
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_documentoComentario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_documentoComentario]
GO
CREATE PROCEDURE [reg_doc_documentoComentario]
	@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],
		[documentoComentario] AS [documentoComentario],
		[documentoComentario_codigo] AS [documentoComentario_codigo],
		[comentario] AS [comentario],
		[recordar] AS [recordar],
		[id_documento] AS [id_documento],
		[id_usuario] AS [id_usuario],
		[id_tarea] AS [id_tarea],
		[fechaRecordar_fh] AS [fechaRecordar_fh],
		[cerrada] AS [cerrada],
		[id_documentoComentario] AS [id_documentoComentario]
	FROM [doc_documentoComentario]
	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_documentoComentario]')) DROP VIEW [dbo].[view_doc_documentoComentario]
GO
CREATE  VIEW [view_doc_documentoComentario] AS
SELECT 	[doc_documentoComentario].[id] AS [id],
		[doc_documentoComentario].[uid] AS [uid],
		[doc_documentoComentario].[eid] AS [eid],
		[doc_documentoComentario].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_documentoComentario].[id_usuario_creo] AS [id_usuario_creo],
		[doc_documentoComentario].[fechaModificacion] AS [fechaModificacion],
		[doc_documentoComentario].[fechaCreacion] AS [fechaCreacion],
		[doc_documentoComentario].[active] AS [active],
		[doc_documentoComentario].[documentoComentario] AS [documentoComentario],
		[doc_documentoComentario].[documentoComentario_codigo] AS [documentoComentario_codigo],
		[doc_documentoComentario].[comentario] AS [comentario],
		[doc_documentoComentario].[recordar] AS [recordar],
		[doc_documentoComentario].[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],
		[doc_documentoComentario].[id_usuario] AS [id_usuario],
[seg_usuario].[usuario] as [seg_usuario_usuario],
[seg_usuario].[usuario_codigo] as [seg_usuario_usuario_codigo],
[seg_usuario].[intentosFallidos] as [seg_usuario_intentosFallidos],
[seg_usuario].[numeroIngresos] as [seg_usuario_numeroIngresos],
[seg_usuario].[fechaUltimoIngreso_fh] as [seg_usuario_fechaUltimoIngreso_fh],
[seg_usuario].[fechaIntentoFallido_fh] as [seg_usuario_fechaIntentoFallido_fh],
[seg_usuario].[clave] as [seg_usuario_clave],
[seg_usuario].[nombre] as [seg_usuario_nombre],
[seg_usuario].[profesion] as [seg_usuario_profesion],
[seg_usuario].[email] as [seg_usuario_email],
[seg_usuario].[direccion] as [seg_usuario_direccion],
[seg_usuario].[telefono] as [seg_usuario_telefono],
[seg_usuario].[costoHora] as [seg_usuario_costoHora],
[seg_usuario].[porcentajeComision] as [seg_usuario_porcentajeComision],
[seg_usuario].[accesoActivo] as [seg_usuario_accesoActivo],
[seg_usuario].[cambiarClave] as [seg_usuario_cambiarClave],
[seg_usuario].[fechaUltimoCambioClave_fh] as [seg_usuario_fechaUltimoCambioClave_fh],
[seg_usuario].[aplicaRecargo] as [seg_usuario_aplicaRecargo],
[seg_usuario].[sexo] as [seg_usuario_sexo],
[seg_usuario].[id_perfil] as [seg_usuario_id_perfil],
[seg_usuario].[id_cargo] as [seg_usuario_id_cargo],
[seg_usuario].[id_grupo] as [seg_usuario_id_grupo],
[seg_usuario].[id_zona] as [seg_usuario_id_zona],
[seg_usuario].[identificacion] as [seg_usuario_identificacion],
[seg_usuario].[id_usuario] as [seg_usuario_id_usuario],
[seg_usuario].[preferencias] as [seg_usuario_preferencias],
		[doc_documentoComentario].[id_tarea] AS [id_tarea],
[doc_tarea].[tarea] as [doc_tarea_tarea],
[doc_tarea].[tarea_codigo] as [doc_tarea_tarea_codigo],
[doc_tarea].[id_catalogo] as [doc_tarea_id_catalogo],
[doc_tarea].[id_cargo] as [doc_tarea_id_cargo],
[doc_tarea].[fechaPlaneada_fh] as [doc_tarea_fechaPlaneada_fh],
[doc_tarea].[porcentajeAvance] as [doc_tarea_porcentajeAvance],
		[doc_documentoComentario].[fechaRecordar_fh] AS [fechaRecordar_fh],
		[doc_documentoComentario].[cerrada] AS [cerrada],
		[doc_documentoComentario].[id_documentoComentario] AS [id_documentoComentario],
[doc_documentoComentario_padre].[documentoComentario] as [doc_documentoComentario_padre_documentoComentario],
[doc_documentoComentario_padre].[documentoComentario_codigo] as [doc_documentoComentario_padre_documentoComentario_codigo],
[doc_documentoComentario_padre].[comentario] as [doc_documentoComentario_padre_comentario],
[doc_documentoComentario_padre].[recordar] as [doc_documentoComentario_padre_recordar],
[doc_documentoComentario_padre].[id_documento] as [doc_documentoComentario_padre_id_documento],
[doc_documentoComentario_padre].[id_usuario] as [doc_documentoComentario_padre_id_usuario],
[doc_documentoComentario_padre].[id_tarea] as [doc_documentoComentario_padre_id_tarea],
[doc_documentoComentario_padre].[fechaRecordar_fh] as [doc_documentoComentario_padre_fechaRecordar_fh],
[doc_documentoComentario_padre].[cerrada] as [doc_documentoComentario_padre_cerrada],
[doc_documentoComentario_padre].[id_documentoComentario] as [doc_documentoComentario_padre_id_documentoComentario],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_documentoComentario]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_documentoComentario].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_documentoComentario].[id_usuario_creo]
	INNER JOIN [doc_documento] ON [doc_documento].id=[doc_documentoComentario].[id_documento]
	INNER JOIN [seg_usuario] ON [seg_usuario].id=[doc_documentoComentario].[id_usuario]
	INNER JOIN [doc_tarea] ON [doc_tarea].id=[doc_documentoComentario].[id_tarea]
	INNER JOIN [doc_documentoComentario] AS [doc_documentoComentario_padre] ON [doc_documentoComentario_padre].id=[doc_documentoComentario].[id_documentoComentario]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_documentoComentario].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [doc_documentoComentario].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_documentoComentariosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXusuario_modifico]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoComentario]
	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_documentoComentariosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXusuario_creo]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoComentario]
	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_documentoComentariosXdocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXdocumento]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXdocumento]
	@p_id_documento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoComentario]
	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_documentoComentariosXusuario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXusuario]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXusuario]
	@p_id_usuario INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoComentario]
	WHERE ([id_usuario]= @p_id_usuario)
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_documentoComentariosXtarea]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXtarea]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXtarea]
	@p_id_tarea INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoComentario]
	WHERE ([id_tarea]= @p_id_tarea)
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_documentoComentariosXdocumentoComentario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXdocumentoComentario]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXdocumentoComentario]
	@p_id_documentoComentario INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documentoComentario]
	WHERE ([id_documentoComentario]= @p_id_documentoComentario)
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_documentoComentarios]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentarios]
GO
CREATE PROCEDURE [sel_doc_documentoComentarios]
	
	@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_documentoComentario]
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_documentoComentarios]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_documentoComentarios]
GO
CREATE PROCEDURE [lis_doc_documentoComentarios]
	AS
BEGIN
	SELECT id AS id,
[documentoComentario] AS [doc_documentoComentario]
	FROM [doc_documentoComentario]
	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_documentoComentario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_documentoComentario]
GO
CREATE PROCEDURE [upd_doc_documentoComentario]
	@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_documentoComentario varchar(300) = null,
		@p_documentoComentario_codigo varchar(100) = null,
		@p_comentario varchar(8000) = null,
		@p_recordar bit = null,
		@p_id_documento int = null,
		@p_id_usuario int = null,
		@p_id_tarea int = null,
		@p_fechaRecordar_fh smalldatetime = null,
		@p_cerrada bit = null,
		@p_id_documentoComentario int = null
AS
BEGIN
		UPDATE [doc_documentoComentario]
		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(),
			[documentoComentario] = isnull(@p_documentoComentario,[documentoComentario]),
			[documentoComentario_codigo] = isnull(@p_documentoComentario_codigo,[documentoComentario_codigo]),
			[comentario] = isnull(@p_comentario,[comentario]),
			[recordar] = isnull(@p_recordar,[recordar]),
			[id_documento] = isnull(@p_id_documento,[id_documento]),
			[id_usuario] = isnull(@p_id_usuario,[id_usuario]),
			[id_tarea] = isnull(@p_id_tarea,[id_tarea]),
			[fechaRecordar_fh] = isnull(@p_fechaRecordar_fh,[fechaRecordar_fh]),
			[cerrada] = isnull(@p_cerrada,[cerrada]),
			[id_documentoComentario] = isnull(@p_id_documentoComentario,[id_documentoComentario])
		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_documentoComentario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_documentoComentario]
GO
CREATE PROCEDURE [ins_doc_documentoComentario]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_documentoComentario varchar(300),
		@p_documentoComentario_codigo varchar(100),
		@p_comentario varchar(8000),
		@p_recordar bit,
		@p_id_documento int,
		@p_id_usuario int,
		@p_id_tarea int,
		@p_fechaRecordar_fh smalldatetime,
		@p_cerrada bit,
		@p_id_documentoComentario int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_documentoComentario]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[documentoComentario],
			[documentoComentario_codigo],
			[comentario],
			[recordar],
			[id_documento],
			[id_usuario],
			[id_tarea],
			[fechaRecordar_fh],
			[cerrada],
			[id_documentoComentario])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_documentoComentario,
			@p_documentoComentario_codigo,
			@p_comentario,
			@p_recordar,
			@p_id_documento,
			@p_id_usuario,
			@p_id_tarea,
			@p_fechaRecordar_fh,
			@p_cerrada,
			@p_id_documentoComentario)
		SET @v_id = scope_identity()
UPDATE [doc_documentoComentario] 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_documentoComentario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_doc_documentoComentario]
GO
CREATE PROCEDURE [act_doc_documentoComentario]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [doc_documentoComentario]
	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_documentoComentario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_documentoComentario_m]
GO
CREATE PROCEDURE [reg_doc_documentoComentario_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],
		[documentoComentario] AS [documentoComentario],
		[documentoComentario_codigo] AS [documentoComentario_codigo],
		[comentario] AS [comentario],
		[recordar] AS [recordar],
		[id_documento] AS [id_documento],
		[id_usuario] AS [id_usuario],
		[id_tarea] AS [id_tarea],
		[fechaRecordar_fh] AS [fechaRecordar_fh],
		[cerrada] AS [cerrada],
		[id_documentoComentario] AS [id_documentoComentario]
	FROM [doc_documentoComentario]
	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_documentoComentariosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoComentario]
	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_documentoComentariosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoComentario]
	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_documentoComentariosXdocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXdocumento_m]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXdocumento_m]
	@p_id_documento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoComentario]
	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_documentoComentariosXusuario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXusuario_m]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXusuario_m]
	@p_id_usuario INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoComentario]
	WHERE ([id_usuario]= @p_id_usuario)
	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_documentoComentariosXtarea_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXtarea_m]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXtarea_m]
	@p_id_tarea INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoComentario]
	WHERE ([id_tarea]= @p_id_tarea)
	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_documentoComentariosXdocumentoComentario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentariosXdocumentoComentario_m]
GO
CREATE PROCEDURE [sel_doc_documentoComentariosXdocumentoComentario_m]
	@p_id_documentoComentario INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documentoComentario]
	WHERE ([id_documentoComentario]= @p_id_documentoComentario)
	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_documentoComentarios_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documentoComentarios_m]
GO
CREATE PROCEDURE [sel_doc_documentoComentarios_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_documentoComentario]
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_documentoComentarios_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_documentoComentarios_m]
GO
CREATE PROCEDURE [lis_doc_documentoComentarios_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[documentoComentario] AS [doc_documentoComentario]
	FROM [doc_documentoComentario]
	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_documentoComentario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_doc_documentoComentario]
GO
CREATE PROCEDURE [aud_doc_documentoComentario]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [doc_documentoComentario].id as id_tabla,
	[doc_documentoComentario].id_usuario_modifico as id_usuario_modifico,
	[doc_documentoComentario].id_usuario_creo as id_usuario_creo,
	[doc_documentoComentario].fechaModificacion as fechaModificacion,
	[doc_documentoComentario].fechaCreacion as fechaCreacion,
	[doc_documentoComentario].active as active,
	[doc_documentoComentario].[documentoComentario] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [doc_documentoComentario]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_documentoComentario].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_documentoComentario].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'doc_documentoComentario'
-----------------------------------10/11/2011 02:28:51 p.m.