

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_soporteItemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_soporteItemDocumento]
GO
CREATE PROCEDURE [reg_doc_soporteItemDocumento]
	@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],
		[soporteItemDocumento] AS [soporteItemDocumento],
		[soporteItemDocumento_codigo] AS [soporteItemDocumento_codigo],
		[duracionPlaneada] AS [duracionPlaneada],
		[Valor] AS [Valor],
		[Costo] AS [Costo],
		[id_itemDocumento] AS [id_itemDocumento],
		[id_usuario] AS [id_usuario],
		[duracionEjecutada] AS [duracionEjecutada],
		[horasOrdinales] AS [horasOrdinales],
		[horasFestivas] AS [horasFestivas],
		[horasNocturnas] AS [horasNocturnas],
		[periodo] AS [periodo]
	FROM [doc_soporteItemDocumento]
	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_soporteItemDocumento]')) DROP VIEW [dbo].[view_doc_soporteItemDocumento]
GO
CREATE  VIEW [view_doc_soporteItemDocumento] AS
SELECT 	[doc_soporteItemDocumento].[id] AS [id],
		[doc_soporteItemDocumento].[uid] AS [uid],
		[doc_soporteItemDocumento].[eid] AS [eid],
		[doc_soporteItemDocumento].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_soporteItemDocumento].[id_usuario_creo] AS [id_usuario_creo],
		[doc_soporteItemDocumento].[fechaModificacion] AS [fechaModificacion],
		[doc_soporteItemDocumento].[fechaCreacion] AS [fechaCreacion],
		[doc_soporteItemDocumento].[active] AS [active],
		[doc_soporteItemDocumento].[soporteItemDocumento] AS [soporteItemDocumento],
		[doc_soporteItemDocumento].[soporteItemDocumento_codigo] AS [soporteItemDocumento_codigo],
		[doc_soporteItemDocumento].[duracionPlaneada] AS [duracionPlaneada],
		[doc_soporteItemDocumento].[Valor] AS [Valor],
		[doc_soporteItemDocumento].[Costo] AS [Costo],
		[doc_soporteItemDocumento].[id_itemDocumento] AS [id_itemDocumento],
[doc_itemDocumento].[itemDocumento] as [doc_itemDocumento_itemDocumento],
[doc_itemDocumento].[itemDocumento_codigo] as [doc_itemDocumento_itemDocumento_codigo],
[doc_itemDocumento].[detalle] as [doc_itemDocumento_detalle],
[doc_itemDocumento].[horasOrdinales] as [doc_itemDocumento_horasOrdinales],
[doc_itemDocumento].[horasFestivas] as [doc_itemDocumento_horasFestivas],
[doc_itemDocumento].[horasNocturnas] as [doc_itemDocumento_horasNocturnas],
[doc_itemDocumento].[cantidadPlaneado] as [doc_itemDocumento_cantidadPlaneado],
[doc_itemDocumento].[cantidadEjecutado] as [doc_itemDocumento_cantidadEjecutado],
[doc_itemDocumento].[valorUnitarioPlaneado] as [doc_itemDocumento_valorUnitarioPlaneado],
[doc_itemDocumento].[valorUnitarioEjecutado] as [doc_itemDocumento_valorUnitarioEjecutado],
[doc_itemDocumento].[subtotalPlaneado] as [doc_itemDocumento_subtotalPlaneado],
[doc_itemDocumento].[subtotalEjecutado] as [doc_itemDocumento_subtotalEjecutado],
[doc_itemDocumento].[totalPlaneado] as [doc_itemDocumento_totalPlaneado],
[doc_itemDocumento].[totalEjecutado] as [doc_itemDocumento_totalEjecutado],
[doc_itemDocumento].[porciva] as [doc_itemDocumento_porciva],
[doc_itemDocumento].[ivaPlaneado] as [doc_itemDocumento_ivaPlaneado],
[doc_itemDocumento].[ivaEjecutado] as [doc_itemDocumento_ivaEjecutado],
[doc_itemDocumento].[porcdto] as [doc_itemDocumento_porcdto],
[doc_itemDocumento].[dtoPlaneado] as [doc_itemDocumento_dtoPlaneado],
[doc_itemDocumento].[dtoEjecutado] as [doc_itemDocumento_dtoEjecutado],
[doc_itemDocumento].[costear] as [doc_itemDocumento_costear],
[doc_itemDocumento].[esUrgente] as [doc_itemDocumento_esUrgente],
[doc_itemDocumento].[vencimientoGarantia_ff] as [doc_itemDocumento_vencimientoGarantia_ff],
[doc_itemDocumento].[horasGarantia] as [doc_itemDocumento_horasGarantia],
[doc_itemDocumento].[porcentajeCliente] as [doc_itemDocumento_porcentajeCliente],
[doc_itemDocumento].[porcentajeDistribuidor] as [doc_itemDocumento_porcentajeDistribuidor],
[doc_itemDocumento].[porcentajeFabricante] as [doc_itemDocumento_porcentajeFabricante],
[doc_itemDocumento].[afectoInventario] as [doc_itemDocumento_afectoInventario],
[doc_itemDocumento].[id_documento] as [doc_itemDocumento_id_documento],
[doc_itemDocumento].[id_itemDocumento] as [doc_itemDocumento_id_itemDocumento],
[doc_itemDocumento].[id_centroCosto] as [doc_itemDocumento_id_centroCosto],
[doc_itemDocumento].[id_catalogo] as [doc_itemDocumento_id_catalogo],
[doc_itemDocumento].[id_bodega] as [doc_itemDocumento_id_bodega],
[doc_itemDocumento].[id_incoterm] as [doc_itemDocumento_id_incoterm],
[doc_itemDocumento].[id_itemDocumento_superior] as [doc_itemDocumento_id_itemDocumento_superior],
[doc_itemDocumento].[costoPlaneado] as [doc_itemDocumento_costoPlaneado],
[doc_itemDocumento].[costoEjecutado] as [doc_itemDocumento_costoEjecutado],
[doc_itemDocumento].[id_listaprecio] as [doc_itemDocumento_id_listaprecio],
		[doc_soporteItemDocumento].[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],
[seg_usuario].[habilitado] as [seg_usuario_habilitado],
		[doc_soporteItemDocumento].[duracionEjecutada] AS [duracionEjecutada],
		[doc_soporteItemDocumento].[horasOrdinales] AS [horasOrdinales],
		[doc_soporteItemDocumento].[horasFestivas] AS [horasFestivas],
		[doc_soporteItemDocumento].[horasNocturnas] AS [horasNocturnas],
		[doc_soporteItemDocumento].[periodo] AS [periodo],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_soporteItemDocumento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_soporteItemDocumento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_soporteItemDocumento].[id_usuario_creo]
	INNER JOIN [doc_itemDocumento] ON [doc_itemDocumento].id=[doc_soporteItemDocumento].[id_itemDocumento]
	INNER JOIN [seg_usuario] ON [seg_usuario].id=[doc_soporteItemDocumento].[id_usuario]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_soporteItemDocumento].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [doc_soporteItemDocumento].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_soporteItemDocumentosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXusuario_modifico]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_soporteItemDocumento]
	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_soporteItemDocumentosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXusuario_creo]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_soporteItemDocumento]
	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_soporteItemDocumentosXitemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXitemDocumento]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXitemDocumento]
	@p_id_itemDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_soporteItemDocumento]
	WHERE ([id_itemDocumento]= @p_id_itemDocumento)
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_soporteItemDocumentosXusuario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXusuario]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXusuario]
	@p_id_usuario INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_soporteItemDocumento]
	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_soporteItemDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentos]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentos]
	
	@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_soporteItemDocumento]
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_soporteItemDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_soporteItemDocumentos]
GO
CREATE PROCEDURE [lis_doc_soporteItemDocumentos]
	AS
BEGIN
	SELECT id AS id,
[soporteItemDocumento] AS [doc_soporteItemDocumento]
	FROM [doc_soporteItemDocumento]
	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_soporteItemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_soporteItemDocumento]
GO
CREATE PROCEDURE [upd_doc_soporteItemDocumento]
	@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_soporteItemDocumento varchar(300) = null,
		@p_soporteItemDocumento_codigo varchar(100) = null,
		@p_duracionPlaneada float = null,
		@p_Valor money = null,
		@p_Costo money = null,
		@p_id_itemDocumento int = null,
		@p_id_usuario int = null,
		@p_duracionEjecutada float = null,
		@p_horasOrdinales float = null,
		@p_horasFestivas float = null,
		@p_horasNocturnas float = null,
		@p_periodo varchar(50) = null
AS
BEGIN
		UPDATE [doc_soporteItemDocumento]
		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(),
			[soporteItemDocumento] = isnull(@p_soporteItemDocumento,[soporteItemDocumento]),
			[soporteItemDocumento_codigo] = isnull(@p_soporteItemDocumento_codigo,[soporteItemDocumento_codigo]),
			[duracionPlaneada] = isnull(@p_duracionPlaneada,[duracionPlaneada]),
			[Valor] = isnull(@p_Valor,[Valor]),
			[Costo] = isnull(@p_Costo,[Costo]),
			[id_itemDocumento] = isnull(@p_id_itemDocumento,[id_itemDocumento]),
			[id_usuario] = isnull(@p_id_usuario,[id_usuario]),
			[duracionEjecutada] = isnull(@p_duracionEjecutada,[duracionEjecutada]),
			[horasOrdinales] = isnull(@p_horasOrdinales,[horasOrdinales]),
			[horasFestivas] = isnull(@p_horasFestivas,[horasFestivas]),
			[horasNocturnas] = isnull(@p_horasNocturnas,[horasNocturnas]),
			[periodo] = isnull(@p_periodo,[periodo])
		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_soporteItemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_soporteItemDocumento]
GO
CREATE PROCEDURE [ins_doc_soporteItemDocumento]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_soporteItemDocumento varchar(300),
		@p_soporteItemDocumento_codigo varchar(100),
		@p_duracionPlaneada float,
		@p_Valor money,
		@p_Costo money,
		@p_id_itemDocumento int,
		@p_id_usuario int,
		@p_duracionEjecutada float,
		@p_horasOrdinales float,
		@p_horasFestivas float,
		@p_horasNocturnas float,
		@p_periodo varchar(50)
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_soporteItemDocumento]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[soporteItemDocumento],
			[soporteItemDocumento_codigo],
			[duracionPlaneada],
			[Valor],
			[Costo],
			[id_itemDocumento],
			[id_usuario],
			[duracionEjecutada],
			[horasOrdinales],
			[horasFestivas],
			[horasNocturnas],
			[periodo])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_soporteItemDocumento,
			@p_soporteItemDocumento_codigo,
			@p_duracionPlaneada,
			@p_Valor,
			@p_Costo,
			@p_id_itemDocumento,
			@p_id_usuario,
			@p_duracionEjecutada,
			@p_horasOrdinales,
			@p_horasFestivas,
			@p_horasNocturnas,
			@p_periodo)
		SET @v_id = scope_identity()
UPDATE [doc_soporteItemDocumento] 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_soporteItemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_doc_soporteItemDocumento]
GO
CREATE PROCEDURE [act_doc_soporteItemDocumento]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [doc_soporteItemDocumento]
	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_soporteItemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_soporteItemDocumento_m]
GO
CREATE PROCEDURE [reg_doc_soporteItemDocumento_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],
		[soporteItemDocumento] AS [soporteItemDocumento],
		[soporteItemDocumento_codigo] AS [soporteItemDocumento_codigo],
		[duracionPlaneada] AS [duracionPlaneada],
		[Valor] AS [Valor],
		[Costo] AS [Costo],
		[id_itemDocumento] AS [id_itemDocumento],
		[id_usuario] AS [id_usuario],
		[duracionEjecutada] AS [duracionEjecutada],
		[horasOrdinales] AS [horasOrdinales],
		[horasFestivas] AS [horasFestivas],
		[horasNocturnas] AS [horasNocturnas],
		[periodo] AS [periodo]
	FROM [doc_soporteItemDocumento]
	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_soporteItemDocumentosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_soporteItemDocumento]
	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_soporteItemDocumentosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_soporteItemDocumento]
	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_soporteItemDocumentosXitemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXitemDocumento_m]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXitemDocumento_m]
	@p_id_itemDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_soporteItemDocumento]
	WHERE ([id_itemDocumento]= @p_id_itemDocumento)
	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_soporteItemDocumentosXusuario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentosXusuario_m]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentosXusuario_m]
	@p_id_usuario INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_soporteItemDocumento]
	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_soporteItemDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_soporteItemDocumentos_m]
GO
CREATE PROCEDURE [sel_doc_soporteItemDocumentos_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_soporteItemDocumento]
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_soporteItemDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_soporteItemDocumentos_m]
GO
CREATE PROCEDURE [lis_doc_soporteItemDocumentos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[soporteItemDocumento] AS [doc_soporteItemDocumento]
	FROM [doc_soporteItemDocumento]
	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_soporteItemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_doc_soporteItemDocumento]
GO
CREATE PROCEDURE [aud_doc_soporteItemDocumento]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [doc_soporteItemDocumento].id as id_tabla,
	[doc_soporteItemDocumento].id_usuario_modifico as id_usuario_modifico,
	[doc_soporteItemDocumento].id_usuario_creo as id_usuario_creo,
	[doc_soporteItemDocumento].fechaModificacion as fechaModificacion,
	[doc_soporteItemDocumento].fechaCreacion as fechaCreacion,
	[doc_soporteItemDocumento].active as active,
	[doc_soporteItemDocumento].[soporteItemDocumento] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

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