

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_cat_tarifaCatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_cat_tarifaCatalogo]
GO
CREATE PROCEDURE [reg_cat_tarifaCatalogo]
	@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],
		[tarifaCatalogo] AS [tarifaCatalogo],
		[tarifaCatalogo_codigo] AS [tarifaCatalogo_codigo],
		[id_catalogo_tarifa] AS [id_catalogo_tarifa],
		[id_catalogo_elemento] AS [id_catalogo_elemento],
		[id_tipotarifa] AS [id_tipotarifa]
	FROM [cat_tarifaCatalogo]
	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_cat_tarifaCatalogo]')) DROP VIEW [dbo].[view_cat_tarifaCatalogo]
GO
CREATE  VIEW [view_cat_tarifaCatalogo] AS
SELECT 	[cat_tarifaCatalogo].[id] AS [id],
		[cat_tarifaCatalogo].[uid] AS [uid],
		[cat_tarifaCatalogo].[eid] AS [eid],
		[cat_tarifaCatalogo].[id_usuario_modifico] AS [id_usuario_modifico],
		[cat_tarifaCatalogo].[id_usuario_creo] AS [id_usuario_creo],
		[cat_tarifaCatalogo].[fechaModificacion] AS [fechaModificacion],
		[cat_tarifaCatalogo].[fechaCreacion] AS [fechaCreacion],
		[cat_tarifaCatalogo].[active] AS [active],
		[cat_tarifaCatalogo].[tarifaCatalogo] AS [tarifaCatalogo],
		[cat_tarifaCatalogo].[tarifaCatalogo_codigo] AS [tarifaCatalogo_codigo],
		[cat_tarifaCatalogo].[id_catalogo_tarifa] AS [id_catalogo_tarifa],
[cat_catalogo_tarifa].[catalogo] as [cat_catalogo_tarifa_catalogo],
[cat_catalogo_tarifa].[catalogo_codigo] as [cat_catalogo_tarifa_catalogo_codigo],
[cat_catalogo_tarifa].[codigoInventario] as [cat_catalogo_tarifa_codigoInventario],
[cat_catalogo_tarifa].[precioVenta] as [cat_catalogo_tarifa_precioVenta],
[cat_catalogo_tarifa].[tiempoConsecucion] as [cat_catalogo_tarifa_tiempoConsecucion],
[cat_catalogo_tarifa].[esNacional] as [cat_catalogo_tarifa_esNacional],
[cat_catalogo_tarifa].[id_familia] as [cat_catalogo_tarifa_id_familia],
[cat_catalogo_tarifa].[id_subTipoCatalogo] as [cat_catalogo_tarifa_id_subTipoCatalogo],
[cat_catalogo_tarifa].[id_unidad] as [cat_catalogo_tarifa_id_unidad],
[cat_catalogo_tarifa].[id_impuesto] as [cat_catalogo_tarifa_id_impuesto],
[cat_catalogo_tarifa].[descripcion] as [cat_catalogo_tarifa_descripcion],
[cat_catalogo_tarifa].[bloquearCostear] as [cat_catalogo_tarifa_bloquearCostear],
		[cat_tarifaCatalogo].[id_catalogo_elemento] AS [id_catalogo_elemento],
[cat_catalogo_elemento].[catalogo] as [cat_catalogo_elemento_catalogo],
[cat_catalogo_elemento].[catalogo_codigo] as [cat_catalogo_elemento_catalogo_codigo],
[cat_catalogo_elemento].[codigoInventario] as [cat_catalogo_elemento_codigoInventario],
[cat_catalogo_elemento].[precioVenta] as [cat_catalogo_elemento_precioVenta],
[cat_catalogo_elemento].[tiempoConsecucion] as [cat_catalogo_elemento_tiempoConsecucion],
[cat_catalogo_elemento].[esNacional] as [cat_catalogo_elemento_esNacional],
[cat_catalogo_elemento].[id_familia] as [cat_catalogo_elemento_id_familia],
[cat_catalogo_elemento].[id_subTipoCatalogo] as [cat_catalogo_elemento_id_subTipoCatalogo],
[cat_catalogo_elemento].[id_unidad] as [cat_catalogo_elemento_id_unidad],
[cat_catalogo_elemento].[id_impuesto] as [cat_catalogo_elemento_id_impuesto],
[cat_catalogo_elemento].[descripcion] as [cat_catalogo_elemento_descripcion],
[cat_catalogo_elemento].[bloquearCostear] as [cat_catalogo_elemento_bloquearCostear],
		[cat_tarifaCatalogo].[id_tipotarifa] AS [id_tipotarifa],
[alq_tipoTarifa].[tipoTarifa] as [alq_tipoTarifa_tipoTarifa],
[alq_tipoTarifa].[tipoTarifa_codigo] as [alq_tipoTarifa_tipoTarifa_codigo],
[alq_tipoTarifa].[valor] as [alq_tipoTarifa_valor],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [cat_tarifaCatalogo]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[cat_tarifaCatalogo].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[cat_tarifaCatalogo].[id_usuario_creo]
	INNER JOIN [cat_catalogo] AS [cat_catalogo_tarifa] ON [cat_catalogo_tarifa].id=[cat_tarifaCatalogo].[id_catalogo_tarifa]
	INNER JOIN [cat_catalogo] AS [cat_catalogo_elemento] ON [cat_catalogo_elemento].id=[cat_tarifaCatalogo].[id_catalogo_elemento]
	INNER JOIN [alq_tipoTarifa] ON [alq_tipoTarifa].id=[cat_tarifaCatalogo].[id_tipotarifa]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [cat_tarifaCatalogo].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [cat_tarifaCatalogo].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_cat_tarifaCatalogosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXusuario_modifico]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_cat_tarifaCatalogo]
	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_cat_tarifaCatalogosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXusuario_creo]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_cat_tarifaCatalogo]
	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_cat_tarifaCatalogosXcatalogo_tarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXcatalogo_tarifa]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXcatalogo_tarifa]
	@p_id_catalogo_tarifa INT
AS
BEGIN
	SELECT * 
	FROM [view_cat_tarifaCatalogo]
	WHERE ([id_catalogo_tarifa]= @p_id_catalogo_tarifa)
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_cat_tarifaCatalogosXcatalogo_elemento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXcatalogo_elemento]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXcatalogo_elemento]
	@p_id_catalogo_elemento INT
AS
BEGIN
	SELECT * 
	FROM [view_cat_tarifaCatalogo]
	WHERE ([id_catalogo_elemento]= @p_id_catalogo_elemento)
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_cat_tarifaCatalogosXtipotarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXtipotarifa]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXtipotarifa]
	@p_id_tipotarifa INT
AS
BEGIN
	SELECT * 
	FROM [view_cat_tarifaCatalogo]
	WHERE ([id_tipotarifa]= @p_id_tipotarifa)
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_cat_tarifaCatalogos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogos]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogos]
	
	@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_cat_tarifaCatalogo]
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_cat_tarifaCatalogos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_cat_tarifaCatalogos]
GO
CREATE PROCEDURE [lis_cat_tarifaCatalogos]
	AS
BEGIN
	SELECT id AS id,
[tarifaCatalogo] AS [cat_tarifaCatalogo]
	FROM [cat_tarifaCatalogo]
	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_cat_tarifaCatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_cat_tarifaCatalogo]
GO
CREATE PROCEDURE [upd_cat_tarifaCatalogo]
	@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_tarifaCatalogo varchar(300) = null,
		@p_tarifaCatalogo_codigo varchar(100) = null,
		@p_id_catalogo_tarifa int = null,
		@p_id_catalogo_elemento int = null,
		@p_id_tipotarifa int = null
AS
BEGIN
		UPDATE [cat_tarifaCatalogo]
		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(),
			[tarifaCatalogo] = isnull(@p_tarifaCatalogo,[tarifaCatalogo]),
			[tarifaCatalogo_codigo] = isnull(@p_tarifaCatalogo_codigo,[tarifaCatalogo_codigo]),
			[id_catalogo_tarifa] = isnull(@p_id_catalogo_tarifa,[id_catalogo_tarifa]),
			[id_catalogo_elemento] = isnull(@p_id_catalogo_elemento,[id_catalogo_elemento]),
			[id_tipotarifa] = isnull(@p_id_tipotarifa,[id_tipotarifa])
		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_cat_tarifaCatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_cat_tarifaCatalogo]
GO
CREATE PROCEDURE [ins_cat_tarifaCatalogo]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_tarifaCatalogo varchar(300),
		@p_tarifaCatalogo_codigo varchar(100),
		@p_id_catalogo_tarifa int,
		@p_id_catalogo_elemento int,
		@p_id_tipotarifa int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [cat_tarifaCatalogo]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[tarifaCatalogo],
			[tarifaCatalogo_codigo],
			[id_catalogo_tarifa],
			[id_catalogo_elemento],
			[id_tipotarifa])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_tarifaCatalogo,
			@p_tarifaCatalogo_codigo,
			@p_id_catalogo_tarifa,
			@p_id_catalogo_elemento,
			@p_id_tipotarifa)
		SET @v_id = scope_identity()
UPDATE [cat_tarifaCatalogo] 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_cat_tarifaCatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_cat_tarifaCatalogo]
GO
CREATE PROCEDURE [act_cat_tarifaCatalogo]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [cat_tarifaCatalogo]
	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_cat_tarifaCatalogo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_cat_tarifaCatalogo_m]
GO
CREATE PROCEDURE [reg_cat_tarifaCatalogo_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],
		[tarifaCatalogo] AS [tarifaCatalogo],
		[tarifaCatalogo_codigo] AS [tarifaCatalogo_codigo],
		[id_catalogo_tarifa] AS [id_catalogo_tarifa],
		[id_catalogo_elemento] AS [id_catalogo_elemento],
		[id_tipotarifa] AS [id_tipotarifa]
	FROM [cat_tarifaCatalogo]
	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_cat_tarifaCatalogosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cat_tarifaCatalogo]
	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_cat_tarifaCatalogosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cat_tarifaCatalogo]
	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_cat_tarifaCatalogosXcatalogo_tarifa_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXcatalogo_tarifa_m]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXcatalogo_tarifa_m]
	@p_id_catalogo_tarifa INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cat_tarifaCatalogo]
	WHERE ([id_catalogo_tarifa]= @p_id_catalogo_tarifa)
	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_cat_tarifaCatalogosXcatalogo_elemento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXcatalogo_elemento_m]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXcatalogo_elemento_m]
	@p_id_catalogo_elemento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cat_tarifaCatalogo]
	WHERE ([id_catalogo_elemento]= @p_id_catalogo_elemento)
	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_cat_tarifaCatalogosXtipotarifa_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogosXtipotarifa_m]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogosXtipotarifa_m]
	@p_id_tipotarifa INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_cat_tarifaCatalogo]
	WHERE ([id_tipotarifa]= @p_id_tipotarifa)
	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_cat_tarifaCatalogos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_cat_tarifaCatalogos_m]
GO
CREATE PROCEDURE [sel_cat_tarifaCatalogos_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_cat_tarifaCatalogo]
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_cat_tarifaCatalogos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_cat_tarifaCatalogos_m]
GO
CREATE PROCEDURE [lis_cat_tarifaCatalogos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[tarifaCatalogo] AS [cat_tarifaCatalogo]
	FROM [cat_tarifaCatalogo]
	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_cat_tarifaCatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_cat_tarifaCatalogo]
GO
CREATE PROCEDURE [aud_cat_tarifaCatalogo]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [cat_tarifaCatalogo].id as id_tabla,
	[cat_tarifaCatalogo].id_usuario_modifico as id_usuario_modifico,
	[cat_tarifaCatalogo].id_usuario_creo as id_usuario_creo,
	[cat_tarifaCatalogo].fechaModificacion as fechaModificacion,
	[cat_tarifaCatalogo].fechaCreacion as fechaCreacion,
	[cat_tarifaCatalogo].active as active,
	[cat_tarifaCatalogo].[tarifaCatalogo] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [cat_tarifaCatalogo]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[cat_tarifaCatalogo].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[cat_tarifaCatalogo].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'cat_tarifaCatalogo'
-----------------------------------20/10/2015 15:10:15