
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_tarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_alq_tarifa]
GO
CREATE PROCEDURE [reg_alq_tarifa]
	@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],
		[tarifa] AS [tarifa],
		[tarifa_codigo] AS [tarifa_codigo],
		[id_itemDocumento] AS [id_itemDocumento],
		[id_detalleAlquiler] AS [id_detalleAlquiler],
		[id_tipoTarifa] AS [id_tipoTarifa],
		[horasIncluidas] AS [horasIncluidas]
	FROM [alq_tarifa]
	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_tarifa]')) DROP VIEW [dbo].[view_alq_tarifa]
GO
CREATE  VIEW [view_alq_tarifa] AS
SELECT 	[alq_tarifa].[id] AS [id],
		[alq_tarifa].[uid] AS [uid],
		[alq_tarifa].[eid] AS [eid],
		[alq_tarifa].[id_usuario_modifico] AS [id_usuario_modifico],
		[alq_tarifa].[id_usuario_creo] AS [id_usuario_creo],
		[alq_tarifa].[fechaModificacion] AS [fechaModificacion],
		[alq_tarifa].[fechaCreacion] AS [fechaCreacion],
		[alq_tarifa].[active] AS [active],
		[alq_tarifa].[tarifa] AS [tarifa],
		[alq_tarifa].[tarifa_codigo] AS [tarifa_codigo],
		[alq_tarifa].[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],
		[alq_tarifa].[id_detalleAlquiler] AS [id_detalleAlquiler],
[equ_detalleAlquiler].[detalleAlquiler] as [equ_detalleAlquiler_detalleAlquiler],
[equ_detalleAlquiler].[detalleAlquiler_codigo] as [equ_detalleAlquiler_detalleAlquiler_codigo],
[equ_detalleAlquiler].[fechaDevolucion_ff] as [equ_detalleAlquiler_fechaDevolucion_ff],
[equ_detalleAlquiler].[valorHora] as [equ_detalleAlquiler_valorHora],
[equ_detalleAlquiler].[ValorHoraStandBy] as [equ_detalleAlquiler_ValorHoraStandBy],
[equ_detalleAlquiler].[valorPeriodo] as [equ_detalleAlquiler_valorPeriodo],
[equ_detalleAlquiler].[horometro] as [equ_detalleAlquiler_horometro],
[equ_detalleAlquiler].[valorMulta] as [equ_detalleAlquiler_valorMulta],
[equ_detalleAlquiler].[fechaDespacho_ff] as [equ_detalleAlquiler_fechaDespacho_ff],
[equ_detalleAlquiler].[id_equipo] as [equ_detalleAlquiler_id_equipo],
[equ_detalleAlquiler].[id_documento.alquiler] as [equ_detalleAlquiler_id_documento.alquiler],
[equ_detalleAlquiler].[id_sucursal] as [equ_detalleAlquiler_id_sucursal],
[equ_detalleAlquiler].[id_tercero] as [equ_detalleAlquiler_id_tercero],
[equ_detalleAlquiler].[fechaUltimaFactura_fh] as [equ_detalleAlquiler_fechaUltimaFactura_fh],
[equ_detalleAlquiler].[valorMes] as [equ_detalleAlquiler_valorMes],
[equ_detalleAlquiler].[fechaInicioFactura_fh] as [equ_detalleAlquiler_fechaInicioFactura_fh],
[equ_detalleAlquiler].[cantidadSolicitada] as [equ_detalleAlquiler_cantidadSolicitada],
[equ_detalleAlquiler].[cantidadAlquilada] as [equ_detalleAlquiler_cantidadAlquilada],
[equ_detalleAlquiler].[id_catalogo] as [equ_detalleAlquiler_id_catalogo],
		[alq_tarifa].[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],
		[alq_tarifa].[horasIncluidas] AS [horasIncluidas],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [alq_tarifa]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[alq_tarifa].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[alq_tarifa].[id_usuario_creo]
	INNER JOIN [doc_itemDocumento] ON [doc_itemDocumento].id=[alq_tarifa].[id_itemDocumento]
	INNER JOIN [equ_detalleAlquiler] ON [equ_detalleAlquiler].id=[alq_tarifa].[id_detalleAlquiler]
	INNER JOIN [alq_tipoTarifa] ON [alq_tipoTarifa].id=[alq_tarifa].[id_tipoTarifa]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [alq_tarifa].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [alq_tarifa].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_tarifasXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXusuario_modifico]
GO
CREATE PROCEDURE [sel_alq_tarifasXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_tarifa]
	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_tarifasXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXusuario_creo]
GO
CREATE PROCEDURE [sel_alq_tarifasXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_tarifa]
	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_tarifasXitemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXitemDocumento]
GO
CREATE PROCEDURE [sel_alq_tarifasXitemDocumento]
	@p_id_itemDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_tarifa]
	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_alq_tarifasXdetalleAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXdetalleAlquiler]
GO
CREATE PROCEDURE [sel_alq_tarifasXdetalleAlquiler]
	@p_id_detalleAlquiler INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_tarifa]
	WHERE ([id_detalleAlquiler]= @p_id_detalleAlquiler)
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_tarifasXtipoTarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXtipoTarifa]
GO
CREATE PROCEDURE [sel_alq_tarifasXtipoTarifa]
	@p_id_tipoTarifa INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_tarifa]
	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_alq_tarifas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifas]
GO
CREATE PROCEDURE [sel_alq_tarifas]
	
	@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_tarifa]
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_tarifas]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_alq_tarifas]
GO
CREATE PROCEDURE [lis_alq_tarifas]
	AS
BEGIN
	SELECT id AS id,
[tarifa] AS [alq_tarifa]
	FROM [alq_tarifa]
	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_tarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_alq_tarifa]
GO
CREATE PROCEDURE [upd_alq_tarifa]
	@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_tarifa varchar(300) = null,
		@p_tarifa_codigo varchar(100) = null,
		@p_id_itemDocumento int = null,
		@p_id_detalleAlquiler int = null,
		@p_id_tipoTarifa int = null,
		@p_horasIncluidas float = null
AS
BEGIN
		UPDATE [alq_tarifa]
		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(),
			[tarifa] = isnull(@p_tarifa,[tarifa]),
			[tarifa_codigo] = isnull(@p_tarifa_codigo,[tarifa_codigo]),
			[id_itemDocumento] = isnull(@p_id_itemDocumento,[id_itemDocumento]),
			[id_detalleAlquiler] = isnull(@p_id_detalleAlquiler,[id_detalleAlquiler]),
			[id_tipoTarifa] = isnull(@p_id_tipoTarifa,[id_tipoTarifa]),
			[horasIncluidas] = isnull(@p_horasIncluidas,[horasIncluidas])
		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_tarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_alq_tarifa]
GO
CREATE PROCEDURE [ins_alq_tarifa]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_tarifa varchar(300),
		@p_tarifa_codigo varchar(100),
		@p_id_itemDocumento int,
		@p_id_detalleAlquiler int,
		@p_id_tipoTarifa int,
		@p_horasIncluidas float
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [alq_tarifa]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[tarifa],
			[tarifa_codigo],
			[id_itemDocumento],
			[id_detalleAlquiler],
			[id_tipoTarifa],
			[horasIncluidas])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_tarifa,
			@p_tarifa_codigo,
			@p_id_itemDocumento,
			@p_id_detalleAlquiler,
			@p_id_tipoTarifa,
			@p_horasIncluidas)
		SET @v_id = scope_identity()
UPDATE [alq_tarifa] 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_tarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_alq_tarifa]
GO
CREATE PROCEDURE [act_alq_tarifa]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [alq_tarifa]
	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_tarifa_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_alq_tarifa_m]
GO
CREATE PROCEDURE [reg_alq_tarifa_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],
		[tarifa] AS [tarifa],
		[tarifa_codigo] AS [tarifa_codigo],
		[id_itemDocumento] AS [id_itemDocumento],
		[id_detalleAlquiler] AS [id_detalleAlquiler],
		[id_tipoTarifa] AS [id_tipoTarifa],
		[horasIncluidas] AS [horasIncluidas]
	FROM [alq_tarifa]
	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_tarifasXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_alq_tarifasXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_tarifa]
	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_tarifasXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXusuario_creo_m]
GO
CREATE PROCEDURE [sel_alq_tarifasXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_tarifa]
	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_tarifasXitemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXitemDocumento_m]
GO
CREATE PROCEDURE [sel_alq_tarifasXitemDocumento_m]
	@p_id_itemDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_tarifa]
	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_alq_tarifasXdetalleAlquiler_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXdetalleAlquiler_m]
GO
CREATE PROCEDURE [sel_alq_tarifasXdetalleAlquiler_m]
	@p_id_detalleAlquiler INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_tarifa]
	WHERE ([id_detalleAlquiler]= @p_id_detalleAlquiler)
	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_tarifasXtipoTarifa_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifasXtipoTarifa_m]
GO
CREATE PROCEDURE [sel_alq_tarifasXtipoTarifa_m]
	@p_id_tipoTarifa INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_tarifa]
	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_alq_tarifas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_tarifas_m]
GO
CREATE PROCEDURE [sel_alq_tarifas_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_tarifa]
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_tarifas_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_alq_tarifas_m]
GO
CREATE PROCEDURE [lis_alq_tarifas_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[tarifa] AS [alq_tarifa]
	FROM [alq_tarifa]
	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_tarifa]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_alq_tarifa]
GO
CREATE PROCEDURE [aud_alq_tarifa]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [alq_tarifa].id as id_tabla,
	[alq_tarifa].id_usuario_modifico as id_usuario_modifico,
	[alq_tarifa].id_usuario_creo as id_usuario_creo,
	[alq_tarifa].fechaModificacion as fechaModificacion,
	[alq_tarifa].fechaCreacion as fechaCreacion,
	[alq_tarifa].active as active,
	[alq_tarifa].[tarifa] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [alq_tarifa]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[alq_tarifa].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[alq_tarifa].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'alq_tarifa'
-----------------------------------17/02/2015 12:16:02