


IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_pendienteDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_pendienteDocumento]
GO
CREATE PROCEDURE [reg_doc_pendienteDocumento]
	@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],
		[pendienteDocumento] AS [pendienteDocumento],
		[pendienteDocumento_codigo] AS [pendienteDocumento_codigo],
		[cantidad] AS [cantidad],
		[id_documento] AS [id_documento],
		[id_catalogo] AS [id_catalogo],
		[id_tipoDocumento] AS [id_tipoDocumento],
		[olvidar] AS [olvidar],
		[id_reporteTecnico] AS [id_reporteTecnico],
		[id_tipoPendiente] AS [id_tipoPendiente]
	FROM [doc_pendienteDocumento]
	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_pendienteDocumento]')) DROP VIEW [dbo].[view_doc_pendienteDocumento]
GO
CREATE  VIEW [view_doc_pendienteDocumento] AS
SELECT 	[doc_pendienteDocumento].[id] AS [id],
		[doc_pendienteDocumento].[uid] AS [uid],
		[doc_pendienteDocumento].[eid] AS [eid],
		[doc_pendienteDocumento].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_pendienteDocumento].[id_usuario_creo] AS [id_usuario_creo],
		[doc_pendienteDocumento].[fechaModificacion] AS [fechaModificacion],
		[doc_pendienteDocumento].[fechaCreacion] AS [fechaCreacion],
		[doc_pendienteDocumento].[active] AS [active],
		[doc_pendienteDocumento].[pendienteDocumento] AS [pendienteDocumento],
		[doc_pendienteDocumento].[pendienteDocumento_codigo] AS [pendienteDocumento_codigo],
		[doc_pendienteDocumento].[cantidad] AS [cantidad],
		[doc_pendienteDocumento].[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_documento].[id_usuario_asignado] as [doc_documento_id_usuario_asignado],
[doc_documento].[id_usuario_enUso] as [doc_documento_id_usuario_enUso],
		[doc_pendienteDocumento].[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_pendienteDocumento].[id_tipoDocumento] AS [id_tipoDocumento],
[doc_tipoDocumento].[tipoDocumento] as [doc_tipoDocumento_tipoDocumento],
[doc_tipoDocumento].[tipoDocumento_codigo] as [doc_tipoDocumento_tipoDocumento_codigo],
[doc_tipoDocumento].[esSalida] as [doc_tipoDocumento_esSalida],
[doc_tipoDocumento].[mostrarBodega] as [doc_tipoDocumento_mostrarBodega],
[doc_tipoDocumento].[mostrarCentroCosto] as [doc_tipoDocumento_mostrarCentroCosto],
[doc_tipoDocumento].[mostrarIncoterm] as [doc_tipoDocumento_mostrarIncoterm],
[doc_tipoDocumento].[puedeSerMayor] as [doc_tipoDocumento_puedeSerMayor],
[doc_tipoDocumento].[puedeSerMenor] as [doc_tipoDocumento_puedeSerMenor],
[doc_tipoDocumento].[esUrgente] as [doc_tipoDocumento_esUrgente],
		[doc_pendienteDocumento].[olvidar] AS [olvidar],
		[doc_pendienteDocumento].[id_reporteTecnico] AS [id_reporteTecnico],
[ort_reporteTecnico].[reporteTecnico] as [ort_reporteTecnico_reporteTecnico],
[ort_reporteTecnico].[reporteTecnico_codigo] as [ort_reporteTecnico_reporteTecnico_codigo],
[ort_reporteTecnico].[numero] as [ort_reporteTecnico_numero],
[ort_reporteTecnico].[trabajos] as [ort_reporteTecnico_trabajos],
[ort_reporteTecnico].[recomendaciones] as [ort_reporteTecnico_recomendaciones],
[ort_reporteTecnico].[compromisos] as [ort_reporteTecnico_compromisos],
[ort_reporteTecnico].[id_gasto] as [ort_reporteTecnico_id_gasto],
[ort_reporteTecnico].[id_canalAtencion] as [ort_reporteTecnico_id_canalAtencion],
[doc_pendienteDocumento].[id_tipoPendiente] AS [id_tipoPendiente],
[doc_tipoPendiente].[tipoPendiente] as [doc_tipoPendiente_tipoPendiente],
[doc_tipoPendiente].[tipoPendiente_codigo] as [doc_tipoPendiente_tipoPendiente_codigo],
[cat_tipoCatalogo].tipoCatalogo as [cat_tipoCatalogo_tipocatalogo],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_pendienteDocumento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_pendienteDocumento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_pendienteDocumento].[id_usuario_creo]
	INNER JOIN [doc_documento] ON [doc_documento].id=[doc_pendienteDocumento].[id_documento]
	INNER JOIN [cat_catalogo] ON [cat_catalogo].id=[doc_pendienteDocumento].[id_catalogo]
	INNER JOIN [doc_tipoDocumento] ON [doc_tipoDocumento].id=[doc_pendienteDocumento].[id_tipoDocumento]
	INNER JOIN [ort_reporteTecnico] ON [ort_reporteTecnico].id=[doc_pendienteDocumento].[id_reporteTecnico]
	INNER JOIN [doc_tipoPendiente] ON [doc_tipoPendiente].id=[doc_pendienteDocumento].[id_tipoPendiente]
	INNER JOIN [cat_subtipoCatalogo] on [cat_subtipoCatalogo]. id = [cat_catalogo].id_subtipoCatalogo
	INNER JOIN [cat_tipoCatalogo] on [cat_tipoCatalogo].id = [cat_subtipoCatalogo].id_tipoCatalogo
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_pendienteDocumento].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [doc_pendienteDocumento].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_pendienteDocumentosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXusuario_modifico]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXusuario_creo]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXdocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXdocumento]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXdocumento]
	@p_id_documento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXcatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXcatalogo]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXcatalogo]
	@p_id_catalogo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXtipoDocumento]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXtipoDocumento]
	@p_id_tipoDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_pendienteDocumento]
	WHERE ([id_tipoDocumento]= @p_id_tipoDocumento)
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_pendienteDocumentosXreporteTecnico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXreporteTecnico]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXreporteTecnico]
	@p_id_reporteTecnico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_pendienteDocumento]
	WHERE ([id_reporteTecnico]= @p_id_reporteTecnico)
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_pendienteDocumentosXtipoPendiente]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXtipoPendiente]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXtipoPendiente]
	@p_id_tipoPendiente INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_pendienteDocumento]
	WHERE ([id_tipoPendiente]= @p_id_tipoPendiente)
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_pendienteDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentos]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentos]
	
	@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_pendienteDocumento]
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_pendienteDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_pendienteDocumentos]
GO
CREATE PROCEDURE [lis_doc_pendienteDocumentos]
	AS
BEGIN
	SELECT id AS id,
[pendienteDocumento] AS [doc_pendienteDocumento]
	FROM [doc_pendienteDocumento]
	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_pendienteDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_pendienteDocumento]
GO
CREATE PROCEDURE [upd_doc_pendienteDocumento]
	@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_pendienteDocumento varchar(300) = null,
		@p_pendienteDocumento_codigo varchar(100) = null,
		@p_cantidad float = null,
		@p_id_documento int = null,
		@p_id_catalogo int = null,
		@p_id_tipoDocumento int = null,
		@p_olvidar bit = null,
		@p_id_reporteTecnico int = null,
		@p_id_tipoPendiente int = null
AS
BEGIN
		UPDATE [doc_pendienteDocumento]
		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(),
			[pendienteDocumento] = isnull(@p_pendienteDocumento,[pendienteDocumento]),
			[pendienteDocumento_codigo] = isnull(@p_pendienteDocumento_codigo,[pendienteDocumento_codigo]),
			[cantidad] = isnull(@p_cantidad,[cantidad]),
			[id_documento] = isnull(@p_id_documento,[id_documento]),
			[id_catalogo] = isnull(@p_id_catalogo,[id_catalogo]),
			[id_tipoDocumento] = isnull(@p_id_tipoDocumento,[id_tipoDocumento]),
			[olvidar] = isnull(@p_olvidar,[olvidar]),
			[id_reporteTecnico] = isnull(@p_id_reporteTecnico,[id_reporteTecnico]),
			[id_tipoPendiente] = isnull(@p_id_tipoPendiente,[id_tipoPendiente])
		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_pendienteDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_pendienteDocumento]
GO
CREATE PROCEDURE [ins_doc_pendienteDocumento]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_pendienteDocumento varchar(300),
		@p_pendienteDocumento_codigo varchar(100),
		@p_cantidad float,
		@p_id_documento int,
		@p_id_catalogo int,
		@p_id_tipoDocumento int,
		@p_olvidar bit,
		@p_id_reporteTecnico int,
		@p_id_tipoPendiente int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_pendienteDocumento]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[pendienteDocumento],
			[pendienteDocumento_codigo],
			[cantidad],
			[id_documento],
			[id_catalogo],
			[id_tipoDocumento],
			[olvidar],
			[id_reporteTecnico],
			[id_tipoPendiente])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_pendienteDocumento,
			@p_pendienteDocumento_codigo,
			@p_cantidad,
			@p_id_documento,
			@p_id_catalogo,
			@p_id_tipoDocumento,
			@p_olvidar,
			@p_id_reporteTecnico,
			@p_id_tipoPendiente)
		SET @v_id = scope_identity()
UPDATE [doc_pendienteDocumento] 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_pendienteDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_doc_pendienteDocumento]
GO
CREATE PROCEDURE [act_doc_pendienteDocumento]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [doc_pendienteDocumento]
	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_pendienteDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_pendienteDocumento_m]
GO
CREATE PROCEDURE [reg_doc_pendienteDocumento_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],
		[pendienteDocumento] AS [pendienteDocumento],
		[pendienteDocumento_codigo] AS [pendienteDocumento_codigo],
		[cantidad] AS [cantidad],
		[id_documento] AS [id_documento],
		[id_catalogo] AS [id_catalogo],
		[id_tipoDocumento] AS [id_tipoDocumento],
		[olvidar] AS [olvidar],
		[id_reporteTecnico] AS [id_reporteTecnico],
		[id_tipoPendiente] AS [id_tipoPendiente]
	FROM [doc_pendienteDocumento]
	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_pendienteDocumentosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXdocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXdocumento_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXdocumento_m]
	@p_id_documento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXcatalogo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXcatalogo_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXcatalogo_m]
	@p_id_catalogo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_pendienteDocumento]
	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_pendienteDocumentosXtipoDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXtipoDocumento_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXtipoDocumento_m]
	@p_id_tipoDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_pendienteDocumento]
	WHERE ([id_tipoDocumento]= @p_id_tipoDocumento)
	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_pendienteDocumentosXreporteTecnico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXreporteTecnico_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXreporteTecnico_m]
	@p_id_reporteTecnico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_pendienteDocumento]
	WHERE ([id_reporteTecnico]= @p_id_reporteTecnico)
	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_pendienteDocumentosXtipoPendiente_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentosXtipoPendiente_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentosXtipoPendiente_m]
	@p_id_tipoPendiente INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_pendienteDocumento]
	WHERE ([id_tipoPendiente]= @p_id_tipoPendiente)
	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_pendienteDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_pendienteDocumentos_m]
GO
CREATE PROCEDURE [sel_doc_pendienteDocumentos_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_pendienteDocumento]
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_pendienteDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_pendienteDocumentos_m]
GO
CREATE PROCEDURE [lis_doc_pendienteDocumentos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[pendienteDocumento] AS [doc_pendienteDocumento]
	FROM [doc_pendienteDocumento]
	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_pendienteDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_doc_pendienteDocumento]
GO
CREATE PROCEDURE [aud_doc_pendienteDocumento]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [doc_pendienteDocumento].id as id_tabla,
	[doc_pendienteDocumento].id_usuario_modifico as id_usuario_modifico,
	[doc_pendienteDocumento].id_usuario_creo as id_usuario_creo,
	[doc_pendienteDocumento].fechaModificacion as fechaModificacion,
	[doc_pendienteDocumento].fechaCreacion as fechaCreacion,
	[doc_pendienteDocumento].active as active,
	[doc_pendienteDocumento].[pendienteDocumento] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [doc_pendienteDocumento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_pendienteDocumento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_pendienteDocumento].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'doc_pendienteDocumento'
-----------------------------------2/12/2020 3:26:10 p. m.