IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_documento_catalogo_tempario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_documento_catalogo_tempario]
GO
CREATE PROCEDURE [reg_doc_documento_catalogo_tempario]
	@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],
		[documento_catalogo.tempario] AS [documento_catalogo.tempario],
		[id_catalogo.tempario] AS [id_catalogo.tempario],
		[id_documento] AS [id_documento],
		[id_itemDocumento] AS [id_itemDocumento]
	FROM [doc_documento_catalogo.tempario]
	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_documento_catalogo_tempario]')) DROP VIEW [dbo].[view_doc_documento_catalogo_tempario]
GO
CREATE  VIEW [view_doc_documento_catalogo_tempario] AS
SELECT 	[doc_documento_catalogo.tempario].[id] AS [id],
		[doc_documento_catalogo.tempario].[uid] AS [uid],
		[doc_documento_catalogo.tempario].[eid] AS [eid],
		[doc_documento_catalogo.tempario].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_documento_catalogo.tempario].[id_usuario_creo] AS [id_usuario_creo],
		[doc_documento_catalogo.tempario].[fechaModificacion] AS [fechaModificacion],
		[doc_documento_catalogo.tempario].[fechaCreacion] AS [fechaCreacion],
		[doc_documento_catalogo.tempario].[active] AS [active],
		[doc_documento_catalogo.tempario].[documento_catalogo.tempario] AS [documento_catalogo.tempario],
		[doc_documento_catalogo.tempario].[id_catalogo.tempario] AS [id_catalogo.tempario],
[cat_catalogo.tempario].[catalogo.tempario] as [cat_catalogo.tempario_catalogo.tempario],
[cat_catalogo.tempario].[duracionEstimada] as [cat_catalogo.tempario_duracionEstimada],
[cat_catalogo.tempario].[enTaller] as [cat_catalogo.tempario_enTaller],
[cat_catalogo.tempario].[esCiclico] as [cat_catalogo.tempario_esCiclico],
[cat_catalogo.tempario].[detieneEquipos] as [cat_catalogo.tempario_detieneEquipos],
[cat_catalogo.tempario].[horasDetencion] as [cat_catalogo.tempario_horasDetencion],
[cat_catalogo.tempario].[periodoHoras] as [cat_catalogo.tempario_periodoHoras],
[cat_catalogo.tempario].[facturaTodo] as [cat_catalogo.tempario_facturaTodo],
[cat_catalogo.tempario].[periodoDias] as [cat_catalogo.tempario_periodoDias],
[cat_catalogo.tempario].[porcGarantia] as [cat_catalogo.tempario_porcGarantia],
[cat_catalogo.tempario].[porcTropicalizacion] as [cat_catalogo.tempario_porcTropicalizacion],
[cat_catalogo.tempario].[id_tipoServicio] as [cat_catalogo.tempario_id_tipoServicio],
[cat_catalogo.tempario].[proyectar] as [cat_catalogo.tempario_proyectar],
[cat_catalogo.tempario].[incluirMenores] as [cat_catalogo.tempario_incluirMenores],
[cat_catalogo.tempario].[modoAjuste] as [cat_catalogo.tempario_modoAjuste],
		[cat_catalogo_tempario].[catalogo_codigo] AS [cat_catalogo_tempario_catalogo_codigo],
		[cat_catalogo_tempario].[codigoInventario] AS [cat_catalogo_tempario_codigoInventario],
		[cat_catalogo_tempario].[precioVenta] AS [cat_catalogo_tempario_precioVenta],
		[cat_catalogo_tempario].[tiempoConsecucion] AS [cat_catalogo_tempario_tiempoConsecucion],
		[cat_catalogo_tempario].[esNacional] AS [cat_catalogo_tempario_esNacional],
		[cat_catalogo_tempario].[id_familia] AS [cat_catalogo_tempario_id_familia],
		[cat_catalogo_tempario].[id_subtipoCatalogo] AS [cat_catalogo_tempario_id_subtipoCatalogo],
		[cat_catalogo_tempario].[id_unidad] AS [cat_catalogo_tempario_id_unidad],
		[cat_catalogo_tempario].[id_impuesto] AS [cat_catalogo_tempario_id_impuesto],
		[cat_catalogo_tempario].[descripcion] AS [cat_catalogo_tempario_descripcion],
		[cat_catalogo_tempario].[bloquearCostear] AS [cat_catalogo_tempario_bloquearCostear],
		[doc_documento_catalogo.tempario].[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_catalogo.tempario].[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_itemDocumento].[vrbase] as [doc_itemDocumento_vrbase],
[doc_itemDocumento].[vrenlista] as [doc_itemDocumento_vrenlista],
[doc_itemDocumento].[porcdescuento] as [doc_itemDocumento_porcdescuento],
[doc_itemDocumento].[cantAuxiliar] as [doc_itemDocumento_cantAuxiliar],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_documento_catalogo.tempario]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_documento_catalogo.tempario].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_documento_catalogo.tempario].[id_usuario_creo]
	INNER JOIN [cat_catalogo.tempario] ON [cat_catalogo.tempario].id=[doc_documento_catalogo.tempario].[id_catalogo.tempario]
	INNER JOIN [cat_catalogo] aS [cat_catalogo_tempario] ON [cat_catalogo.tempario].id = [cat_catalogo_tempario].id
	INNER JOIN [doc_documento] ON [doc_documento].id=[doc_documento_catalogo.tempario].[id_documento]
	INNER JOIN [doc_itemDocumento] ON [doc_itemDocumento].id=[doc_documento_catalogo.tempario].[id_itemDocumento]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_documento_catalogo.tempario].eid = [empresaCodigo].[codigo] and empresaCodigo.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_documento_catalogo_tempariosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXusuario_modifico]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_tempariosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXusuario_creo]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_tempariosXcatalogo_tempario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXcatalogo_tempario]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXcatalogo_tempario]
	@p_id_catalogo_tempario INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documento_catalogo.tempario]
	WHERE ([id_catalogo.tempario]= @p_id_catalogo_tempario)
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_documento_catalogo_tempariosXdocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXdocumento]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXdocumento]
	@p_id_documento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_tempariosXitemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXitemDocumento]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXitemDocumento]
	@p_id_itemDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_temparios]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_temparios]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_temparios]
	
	@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_documento_catalogo_tempario]
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_documento_catalogo_temparios]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_documento_catalogo_temparios]
GO
CREATE PROCEDURE [lis_doc_documento_catalogo_temparios]
	AS
BEGIN
	SELECT id AS id,
[documento_catalogo.tempario] AS [doc_documento_catalogo.tempario]
	FROM [doc_documento_catalogo.tempario]
	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_documento_catalogo_tempario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_documento_catalogo_tempario]
GO
CREATE PROCEDURE [upd_doc_documento_catalogo_tempario]
	@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_documento_catalogo_tempario varchar(300) = null,
		@p_id_catalogo_tempario int = null,
		@p_id_documento int = null,
		@p_id_itemDocumento int = null
AS
BEGIN
		UPDATE [doc_documento_catalogo.tempario]
		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(),
			[documento_catalogo.tempario] = isnull(@p_documento_catalogo_tempario,[documento_catalogo.tempario]),
			[id_catalogo.tempario] = isnull(@p_id_catalogo_tempario,[id_catalogo.tempario]),
			[id_documento] = isnull(@p_id_documento,[id_documento]),
			[id_itemDocumento] = isnull(@p_id_itemDocumento,[id_itemDocumento])
		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_documento_catalogo_tempario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_documento_catalogo_tempario]
GO
CREATE PROCEDURE [ins_doc_documento_catalogo_tempario]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_documento_catalogo_tempario varchar(300),
		@p_id_catalogo_tempario int,
		@p_id_documento int,
		@p_id_itemDocumento int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_documento_catalogo.tempario]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[documento_catalogo.tempario],
			[id_catalogo.tempario],
			[id_documento],
			[id_itemDocumento])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_documento_catalogo_tempario,
			@p_id_catalogo_tempario,
			@p_id_documento,
			@p_id_itemDocumento)
		SET @v_id = scope_identity()
UPDATE [doc_documento_catalogo.tempario] 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_documento_catalogo_tempario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_doc_documento_catalogo_tempario]
GO
CREATE PROCEDURE [act_doc_documento_catalogo_tempario]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [doc_documento_catalogo.tempario]
	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_documento_catalogo_tempario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_documento_catalogo_tempario_m]
GO
CREATE PROCEDURE [reg_doc_documento_catalogo_tempario_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],
		[documento_catalogo.tempario] AS [documento_catalogo.tempario],
		[id_catalogo.tempario] AS [id_catalogo.tempario],
		[id_documento] AS [id_documento],
		[id_itemDocumento] AS [id_itemDocumento]
	FROM [doc_documento_catalogo.tempario]
	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_documento_catalogo_tempariosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_tempariosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_tempariosXcatalogo_tempario_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXcatalogo_tempario_m]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXcatalogo_tempario_m]
	@p_id_catalogo_tempario INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documento_catalogo.tempario]
	WHERE ([id_catalogo.tempario]= @p_id_catalogo_tempario)
	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_documento_catalogo_tempariosXdocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXdocumento_m]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXdocumento_m]
	@p_id_documento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_tempariosXitemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_tempariosXitemDocumento_m]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_tempariosXitemDocumento_m]
	@p_id_itemDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_documento_catalogo.tempario]
	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_documento_catalogo_temparios_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_catalogo_temparios_m]
GO
CREATE PROCEDURE [sel_doc_documento_catalogo_temparios_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_documento_catalogo_tempario]
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_documento_catalogo_temparios_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_documento_catalogo_temparios_m]
GO
CREATE PROCEDURE [lis_doc_documento_catalogo_temparios_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[documento_catalogo.tempario] AS [doc_documento_catalogo.tempario]
	FROM [doc_documento_catalogo.tempario]
	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_documento_catalogo_tempario]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_doc_documento_catalogo_tempario]
GO
CREATE PROCEDURE [aud_doc_documento_catalogo_tempario]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [doc_documento_catalogo.tempario].id as id_tabla,
	[doc_documento_catalogo.tempario].id_usuario_modifico as id_usuario_modifico,
	[doc_documento_catalogo.tempario].id_usuario_creo as id_usuario_creo,
	[doc_documento_catalogo.tempario].fechaModificacion as fechaModificacion,
	[doc_documento_catalogo.tempario].fechaCreacion as fechaCreacion,
	[doc_documento_catalogo.tempario].active as active,
	[doc_documento_catalogo.tempario].[documento_catalogo.tempario] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [doc_documento_catalogo.tempario]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_documento_catalogo.tempario].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_documento_catalogo.tempario].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'doc_documento_catalogo.tempario'
-----------------------------------30/08/2017 14:37:05