
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_alq_tipoTarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_alq_tipoTarifa]
GO
CREATE PROCEDURE [reg_alq_tipoTarifa]
	@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],
		[tipoTarifa] AS [tipoTarifa],
		[tipoTarifa_codigo] AS [tipoTarifa_codigo],
		[valor] AS [valor]
	FROM [alq_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 ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_alq_tipoTarifa]')) DROP VIEW [dbo].[view_alq_tipoTarifa]
GO
CREATE  VIEW [view_alq_tipoTarifa] AS
SELECT 	[alq_tipoTarifa].[id] AS [id],
		[alq_tipoTarifa].[uid] AS [uid],
		[alq_tipoTarifa].[eid] AS [eid],
		[alq_tipoTarifa].[id_usuario_modifico] AS [id_usuario_modifico],
		[alq_tipoTarifa].[id_usuario_creo] AS [id_usuario_creo],
		[alq_tipoTarifa].[fechaModificacion] AS [fechaModificacion],
		[alq_tipoTarifa].[fechaCreacion] AS [fechaCreacion],
		[alq_tipoTarifa].[active] AS [active],
		[alq_tipoTarifa].[tipoTarifa] AS [tipoTarifa],
		[alq_tipoTarifa].[tipoTarifa_codigo] AS [tipoTarifa_codigo],
		[alq_tipoTarifa].[valor] AS [valor],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [alq_tipoTarifa]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[alq_tipoTarifa].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[alq_tipoTarifa].[id_usuario_creo]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [alq_tipoTarifa].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [alq_tipoTarifa].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_alq_tipoTarifasXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tipoTarifasXusuario_modifico]
GO
CREATE PROCEDURE [sel_alq_tipoTarifasXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_tipoTarifa]
	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_alq_tipoTarifasXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tipoTarifasXusuario_creo]
GO
CREATE PROCEDURE [sel_alq_tipoTarifasXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_tipoTarifa]
	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_alq_tipoTarifas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tipoTarifas]
GO
CREATE PROCEDURE [sel_alq_tipoTarifas]
	
	@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_alq_tipoTarifa]
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_alq_tipoTarifas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_alq_tipoTarifas]
GO
CREATE PROCEDURE [lis_alq_tipoTarifas]
	AS
BEGIN
	SELECT id AS id,
[tipoTarifa] AS [alq_tipoTarifa]
	FROM [alq_tipoTarifa]
	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_alq_tipoTarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_alq_tipoTarifa]
GO
CREATE PROCEDURE [upd_alq_tipoTarifa]
	@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_tipoTarifa varchar(300) = null,
		@p_tipoTarifa_codigo varchar(100) = null,
		@p_valor decimal = null
AS
BEGIN
		UPDATE [alq_tipoTarifa]
		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(),
			[tipoTarifa] = isnull(@p_tipoTarifa,[tipoTarifa]),
			[tipoTarifa_codigo] = isnull(@p_tipoTarifa_codigo,[tipoTarifa_codigo]),
			[valor] = isnull(@p_valor,[valor])
		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_alq_tipoTarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_alq_tipoTarifa]
GO
CREATE PROCEDURE [ins_alq_tipoTarifa]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_tipoTarifa varchar(300),
		@p_tipoTarifa_codigo varchar(100),
		@p_valor decimal
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [alq_tipoTarifa]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[tipoTarifa],
			[tipoTarifa_codigo],
			[valor])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_tipoTarifa,
			@p_tipoTarifa_codigo,
			@p_valor)
		SET @v_id = scope_identity()
UPDATE [alq_tipoTarifa] 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_alq_tipoTarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_alq_tipoTarifa]
GO
CREATE PROCEDURE [act_alq_tipoTarifa]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [alq_tipoTarifa]
	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_alq_tipoTarifa_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_alq_tipoTarifa_m]
GO
CREATE PROCEDURE [reg_alq_tipoTarifa_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],
		[tipoTarifa] AS [tipoTarifa],
		[tipoTarifa_codigo] AS [tipoTarifa_codigo],
		[valor] AS [valor]
	FROM [alq_tipoTarifa]
	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_alq_tipoTarifasXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tipoTarifasXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_alq_tipoTarifasXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_tipoTarifa]
	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_alq_tipoTarifasXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tipoTarifasXusuario_creo_m]
GO
CREATE PROCEDURE [sel_alq_tipoTarifasXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_tipoTarifa]
	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_alq_tipoTarifas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tipoTarifas_m]
GO
CREATE PROCEDURE [sel_alq_tipoTarifas_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_alq_tipoTarifa]
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_alq_tipoTarifas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_alq_tipoTarifas_m]
GO
CREATE PROCEDURE [lis_alq_tipoTarifas_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[tipoTarifa] AS [alq_tipoTarifa]
	FROM [alq_tipoTarifa]
	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_alq_tipoTarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_alq_tipoTarifa]
GO
CREATE PROCEDURE [aud_alq_tipoTarifa]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [alq_tipoTarifa].id as id_tabla,
	[alq_tipoTarifa].id_usuario_modifico as id_usuario_modifico,
	[alq_tipoTarifa].id_usuario_creo as id_usuario_creo,
	[alq_tipoTarifa].fechaModificacion as fechaModificacion,
	[alq_tipoTarifa].fechaCreacion as fechaCreacion,
	[alq_tipoTarifa].active as active,
	[alq_tipoTarifa].[tipoTarifa] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

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