---25/07/2012 08:15:14 p.m.
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_tax_nivelTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_tax_nivelTax]
GO
CREATE PROCEDURE [reg_tax_nivelTax]
	@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],
		[nivelTax] AS [nivelTax],
		[nivelTax_codigo] AS [nivelTax_codigo],
		[id_nivelTax] AS [id_nivelTax],
		[tabla] AS [tabla],
		[filtro] AS [filtro],
		[columnaPrincipal] AS [columnaPrincipal],
		[esEquipo] AS [esEquipo]
	FROM [tax_nivelTax]
	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_tax_nivelTax]')) DROP VIEW [dbo].[view_tax_nivelTax]
GO
CREATE  VIEW [view_tax_nivelTax] AS
SELECT 	[tax_nivelTax].[id] AS [id],
		[tax_nivelTax].[uid] AS [uid],
		[tax_nivelTax].[eid] AS [eid],
		[tax_nivelTax].[id_usuario_modifico] AS [id_usuario_modifico],
		[tax_nivelTax].[id_usuario_creo] AS [id_usuario_creo],
		[tax_nivelTax].[fechaModificacion] AS [fechaModificacion],
		[tax_nivelTax].[fechaCreacion] AS [fechaCreacion],
		[tax_nivelTax].[active] AS [active],
		[tax_nivelTax].[nivelTax] AS [nivelTax],
		[tax_nivelTax].[nivelTax_codigo] AS [nivelTax_codigo],
		[tax_nivelTax].[id_nivelTax] AS [id_nivelTax],
[tax_nivelTax_padre].[nivelTax] as [tax_nivelTax_padre_nivelTax],
[tax_nivelTax_padre].[nivelTax_codigo] as [tax_nivelTax_padre_nivelTax_codigo],
[tax_nivelTax_padre].[id_nivelTax] as [tax_nivelTax_padre_id_nivelTax],
[tax_nivelTax_padre].[tabla] as [tax_nivelTax_padre_tabla],
[tax_nivelTax_padre].[filtro] as [tax_nivelTax_padre_filtro],
[tax_nivelTax_padre].[columnaPrincipal] as [tax_nivelTax_padre_columnaPrincipal],
[tax_nivelTax_padre].[esEquipo] as [tax_nivelTax_padre_esEquipo],
		[tax_nivelTax].[tabla] AS [tabla],
		[tax_nivelTax].[filtro] AS [filtro],
		[tax_nivelTax].[columnaPrincipal] AS [columnaPrincipal],
		[tax_nivelTax].[esEquipo] AS [esEquipo],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [tax_nivelTax]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[tax_nivelTax].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[tax_nivelTax].[id_usuario_creo]
	INNER JOIN [tax_nivelTax] AS [tax_nivelTax_padre] ON [tax_nivelTax_padre].id=[tax_nivelTax].[id_nivelTax]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [tax_nivelTax].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [tax_nivelTax].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_tax_nivelTaxesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxesXusuario_modifico]
GO
CREATE PROCEDURE [sel_tax_nivelTaxesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_nivelTax]
	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_tax_nivelTaxesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxesXusuario_creo]
GO
CREATE PROCEDURE [sel_tax_nivelTaxesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_nivelTax]
	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_tax_nivelTaxesXnivelTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxesXnivelTax]
GO
CREATE PROCEDURE [sel_tax_nivelTaxesXnivelTax]
	@p_id_nivelTax INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_nivelTax]
	WHERE ([id_nivelTax]= @p_id_nivelTax)
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_tax_nivelTaxes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxes]
GO
CREATE PROCEDURE [sel_tax_nivelTaxes]
	
	@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_tax_nivelTax]
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_tax_nivelTaxes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_tax_nivelTaxes]
GO
CREATE PROCEDURE [lis_tax_nivelTaxes]
	AS
BEGIN
	SELECT id AS id,
[nivelTax] AS [tax_nivelTax]
	FROM [tax_nivelTax]
	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_tax_nivelTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_tax_nivelTax]
GO
CREATE PROCEDURE [upd_tax_nivelTax]
	@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_nivelTax varchar(300) = null,
		@p_nivelTax_codigo varchar(100) = null,
		@p_id_nivelTax int = null,
		@p_tabla varchar(300) = null,
		@p_filtro varchar(300) = null,
		@p_columnaPrincipal varchar(300) = null,
		@p_esEquipo bit = null
AS
BEGIN
		UPDATE [tax_nivelTax]
		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(),
			[nivelTax] = isnull(@p_nivelTax,[nivelTax]),
			[nivelTax_codigo] = isnull(@p_nivelTax_codigo,[nivelTax_codigo]),
			[id_nivelTax] = isnull(@p_id_nivelTax,[id_nivelTax]),
			[tabla] = isnull(@p_tabla,[tabla]),
			[filtro] = isnull(@p_filtro,[filtro]),
			[columnaPrincipal] = isnull(@p_columnaPrincipal,[columnaPrincipal]),
			[esEquipo] = isnull(@p_esEquipo,[esEquipo])
		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_tax_nivelTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_tax_nivelTax]
GO
CREATE PROCEDURE [ins_tax_nivelTax]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_nivelTax varchar(300),
		@p_nivelTax_codigo varchar(100),
		@p_id_nivelTax int,
		@p_tabla varchar(300),
		@p_filtro varchar(300),
		@p_columnaPrincipal varchar(300),
		@p_esEquipo bit
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [tax_nivelTax]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[nivelTax],
			[nivelTax_codigo],
			[id_nivelTax],
			[tabla],
			[filtro],
			[columnaPrincipal],
			[esEquipo])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_nivelTax,
			@p_nivelTax_codigo,
			@p_id_nivelTax,
			@p_tabla,
			@p_filtro,
			@p_columnaPrincipal,
			@p_esEquipo)
		SET @v_id = scope_identity()
UPDATE [tax_nivelTax] 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_tax_nivelTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_tax_nivelTax]
GO
CREATE PROCEDURE [act_tax_nivelTax]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [tax_nivelTax]
	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_tax_nivelTax_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_tax_nivelTax_m]
GO
CREATE PROCEDURE [reg_tax_nivelTax_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],
		[nivelTax] AS [nivelTax],
		[nivelTax_codigo] AS [nivelTax_codigo],
		[id_nivelTax] AS [id_nivelTax],
		[tabla] AS [tabla],
		[filtro] AS [filtro],
		[columnaPrincipal] AS [columnaPrincipal],
		[esEquipo] AS [esEquipo]
	FROM [tax_nivelTax]
	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_tax_nivelTaxesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_tax_nivelTaxesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_nivelTax]
	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_tax_nivelTaxesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_tax_nivelTaxesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_nivelTax]
	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_tax_nivelTaxesXnivelTax_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxesXnivelTax_m]
GO
CREATE PROCEDURE [sel_tax_nivelTaxesXnivelTax_m]
	@p_id_nivelTax INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_nivelTax]
	WHERE ([id_nivelTax]= @p_id_nivelTax)
	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_tax_nivelTaxes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_nivelTaxes_m]
GO
CREATE PROCEDURE [sel_tax_nivelTaxes_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_tax_nivelTax]
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_tax_nivelTaxes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_tax_nivelTaxes_m]
GO
CREATE PROCEDURE [lis_tax_nivelTaxes_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[nivelTax] AS [tax_nivelTax]
	FROM [tax_nivelTax]
	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_tax_nivelTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_tax_nivelTax]
GO
CREATE PROCEDURE [aud_tax_nivelTax]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [tax_nivelTax].id as id_tabla,
	[tax_nivelTax].id_usuario_modifico as id_usuario_modifico,
	[tax_nivelTax].id_usuario_creo as id_usuario_creo,
	[tax_nivelTax].fechaModificacion as fechaModificacion,
	[tax_nivelTax].fechaCreacion as fechaCreacion,
	[tax_nivelTax].active as active,
	[tax_nivelTax].[nivelTax] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [tax_nivelTax]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[tax_nivelTax].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[tax_nivelTax].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'tax_nivelTax'
--------------------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_tax_objetoTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_tax_objetoTax]
GO
CREATE PROCEDURE [reg_tax_objetoTax]
	@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],
		[objetoTax] AS [objetoTax],
		[objetoTax_codigo] AS [objetoTax_codigo],
		[tabla] AS [tabla],
		[id_tablaTax] AS [id_tablaTax],
		[id_objTax] AS [id_objTax],
		[id_nivelTax] AS [id_nivelTax],
		[orden] AS [orden]
	FROM [tax_objetoTax]
	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_tax_objetoTax]')) DROP VIEW [dbo].[view_tax_objetoTax]
GO
CREATE  VIEW [view_tax_objetoTax] AS
SELECT 	[tax_objetoTax].[id] AS [id],
		[tax_objetoTax].[uid] AS [uid],
		[tax_objetoTax].[eid] AS [eid],
		[tax_objetoTax].[id_usuario_modifico] AS [id_usuario_modifico],
		[tax_objetoTax].[id_usuario_creo] AS [id_usuario_creo],
		[tax_objetoTax].[fechaModificacion] AS [fechaModificacion],
		[tax_objetoTax].[fechaCreacion] AS [fechaCreacion],
		[tax_objetoTax].[active] AS [active],
		[tax_objetoTax].[objetoTax] AS [objetoTax],
		[tax_objetoTax].[objetoTax_codigo] AS [objetoTax_codigo],
		[tax_objetoTax].[tabla] AS [tabla],
		[tax_objetoTax].[id_tablaTax] AS [id_tablaTax],
		[tax_objetoTax].[id_objTax] AS [id_objTax],
		[tax_objetoTax].[id_nivelTax] AS [id_nivelTax],
[tax_nivelTax].[nivelTax] as [tax_nivelTax_nivelTax],
[tax_nivelTax].[nivelTax_codigo] as [tax_nivelTax_nivelTax_codigo],
[tax_nivelTax].[id_nivelTax] as [tax_nivelTax_id_nivelTax],
[tax_nivelTax].[tabla] as [tax_nivelTax_tabla],
[tax_nivelTax].[filtro] as [tax_nivelTax_filtro],
[tax_nivelTax].[columnaPrincipal] as [tax_nivelTax_columnaPrincipal],
[tax_nivelTax].[esEquipo] as [tax_nivelTax_esEquipo],
		[tax_objetoTax].[orden] AS [orden],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [tax_objetoTax]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[tax_objetoTax].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[tax_objetoTax].[id_usuario_creo]
	INNER JOIN [tax_nivelTax] ON [tax_nivelTax].id=[tax_objetoTax].[id_nivelTax]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [tax_objetoTax].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [tax_objetoTax].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_tax_objetoTaxesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXusuario_modifico]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_objetoTax]
	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_tax_objetoTaxesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXusuario_creo]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_objetoTax]
	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_tax_objetoTaxesXtablaTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXtablaTax]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXtablaTax]
	@p_id_tablaTax INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_objetoTax]
	WHERE ([id_tablaTax]= @p_id_tablaTax)
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_tax_objetoTaxesXobjTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXobjTax]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXobjTax]
	@p_id_objTax INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_objetoTax]
	WHERE ([id_objTax]= @p_id_objTax)
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_tax_objetoTaxesXnivelTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXnivelTax]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXnivelTax]
	@p_id_nivelTax INT
AS
BEGIN
	SELECT * 
	FROM [view_tax_objetoTax]
	WHERE ([id_nivelTax]= @p_id_nivelTax)
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_tax_objetoTaxes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxes]
GO
CREATE PROCEDURE [sel_tax_objetoTaxes]
	
	@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_tax_objetoTax]
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_tax_objetoTaxes]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_tax_objetoTaxes]
GO
CREATE PROCEDURE [lis_tax_objetoTaxes]
	AS
BEGIN
	SELECT id AS id,
[objetoTax] AS [tax_objetoTax]
	FROM [tax_objetoTax]
	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_tax_objetoTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_tax_objetoTax]
GO
CREATE PROCEDURE [upd_tax_objetoTax]
	@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_objetoTax varchar(300) = null,
		@p_objetoTax_codigo varchar(100) = null,
		@p_tabla varchar(300) = null,
		@p_id_tablaTax int = null,
		@p_id_objTax int = null,
		@p_id_nivelTax int = null,
		@p_orden int = null
AS
BEGIN
		UPDATE [tax_objetoTax]
		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(),
			[objetoTax] = isnull(@p_objetoTax,[objetoTax]),
			[objetoTax_codigo] = isnull(@p_objetoTax_codigo,[objetoTax_codigo]),
			[tabla] = isnull(@p_tabla,[tabla]),
			[id_tablaTax] = isnull(@p_id_tablaTax,[id_tablaTax]),
			[id_objTax] = isnull(@p_id_objTax,[id_objTax]),
			[id_nivelTax] = isnull(@p_id_nivelTax,[id_nivelTax]),
			[orden] = isnull(@p_orden,[orden])
		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_tax_objetoTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_tax_objetoTax]
GO
CREATE PROCEDURE [ins_tax_objetoTax]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_objetoTax varchar(300),
		@p_objetoTax_codigo varchar(100),
		@p_tabla varchar(300),
		@p_id_tablaTax int,
		@p_id_objTax int,
		@p_id_nivelTax int,
		@p_orden int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [tax_objetoTax]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[objetoTax],
			[objetoTax_codigo],
			[tabla],
			[id_tablaTax],
			[id_objTax],
			[id_nivelTax],
			[orden])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_objetoTax,
			@p_objetoTax_codigo,
			@p_tabla,
			@p_id_tablaTax,
			@p_id_objTax,
			@p_id_nivelTax,
			@p_orden)
		SET @v_id = scope_identity()
UPDATE [tax_objetoTax] 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_tax_objetoTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_tax_objetoTax]
GO
CREATE PROCEDURE [act_tax_objetoTax]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [tax_objetoTax]
	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_tax_objetoTax_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_tax_objetoTax_m]
GO
CREATE PROCEDURE [reg_tax_objetoTax_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],
		[objetoTax] AS [objetoTax],
		[objetoTax_codigo] AS [objetoTax_codigo],
		[tabla] AS [tabla],
		[id_tablaTax] AS [id_tablaTax],
		[id_objTax] AS [id_objTax],
		[id_nivelTax] AS [id_nivelTax],
		[orden] AS [orden]
	FROM [tax_objetoTax]
	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_tax_objetoTaxesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_objetoTax]
	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_tax_objetoTaxesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_objetoTax]
	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_tax_objetoTaxesXtablaTax_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXtablaTax_m]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXtablaTax_m]
	@p_id_tablaTax INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_objetoTax]
	WHERE ([id_tablaTax]= @p_id_tablaTax)
	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_tax_objetoTaxesXobjTax_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXobjTax_m]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXobjTax_m]
	@p_id_objTax INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_objetoTax]
	WHERE ([id_objTax]= @p_id_objTax)
	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_tax_objetoTaxesXnivelTax_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxesXnivelTax_m]
GO
CREATE PROCEDURE [sel_tax_objetoTaxesXnivelTax_m]
	@p_id_nivelTax INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_tax_objetoTax]
	WHERE ([id_nivelTax]= @p_id_nivelTax)
	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_tax_objetoTaxes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_tax_objetoTaxes_m]
GO
CREATE PROCEDURE [sel_tax_objetoTaxes_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_tax_objetoTax]
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_tax_objetoTaxes_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_tax_objetoTaxes_m]
GO
CREATE PROCEDURE [lis_tax_objetoTaxes_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[objetoTax] AS [tax_objetoTax]
	FROM [tax_objetoTax]
	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_tax_objetoTax]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_tax_objetoTax]
GO
CREATE PROCEDURE [aud_tax_objetoTax]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [tax_objetoTax].id as id_tabla,
	[tax_objetoTax].id_usuario_modifico as id_usuario_modifico,
	[tax_objetoTax].id_usuario_creo as id_usuario_creo,
	[tax_objetoTax].fechaModificacion as fechaModificacion,
	[tax_objetoTax].fechaCreacion as fechaCreacion,
	[tax_objetoTax].active as active,
	[tax_objetoTax].[objetoTax] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [tax_objetoTax]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[tax_objetoTax].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[tax_objetoTax].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'tax_objetoTax'
--------------------------------