
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_alq_historicoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_alq_historicoAlquiler]
GO
CREATE PROCEDURE [reg_alq_historicoAlquiler]
	@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],
		[historicoAlquiler] AS [historicoAlquiler],
		[historicoAlquiler_codigo] AS [historicoAlquiler_codigo],
		[id_equipo] AS [id_equipo],
		[id_estadoEquipo] AS [id_estadoEquipo],
		[id_documento] AS [id_documento],
		[fechaEstado] AS [fechaEstado]
	FROM [alq_historicoAlquiler]
	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_historicoAlquiler]')) DROP VIEW [dbo].[view_alq_historicoAlquiler]
GO
CREATE  VIEW [view_alq_historicoAlquiler] AS
SELECT 	[alq_historicoAlquiler].[id] AS [id],
		[alq_historicoAlquiler].[uid] AS [uid],
		[alq_historicoAlquiler].[eid] AS [eid],
		[alq_historicoAlquiler].[id_usuario_modifico] AS [id_usuario_modifico],
		[alq_historicoAlquiler].[id_usuario_creo] AS [id_usuario_creo],
		[alq_historicoAlquiler].[fechaModificacion] AS [fechaModificacion],
		[alq_historicoAlquiler].[fechaCreacion] AS [fechaCreacion],
		[alq_historicoAlquiler].[active] AS [active],
		[alq_historicoAlquiler].[historicoAlquiler] AS [historicoAlquiler],
		[alq_historicoAlquiler].[historicoAlquiler_codigo] AS [historicoAlquiler_codigo],
		[alq_historicoAlquiler].[id_equipo] AS [id_equipo],
[equ_equipo].[equipo] as [equ_equipo_equipo],
[equ_equipo].[equipo_codigo] as [equ_equipo_equipo_codigo],
[equ_equipo].[equipo_serial] as [equ_equipo_equipo_serial],
[equ_equipo].[nombreContacto] as [equ_equipo_nombreContacto],
[equ_equipo].[telefonoContacto] as [equ_equipo_telefonoContacto],
[equ_equipo].[ubicacion] as [equ_equipo_ubicacion],
[equ_equipo].[observaciones] as [equ_equipo_observaciones],
[equ_equipo].[fechaPuestaMarcha_fh] as [equ_equipo_fechaPuestaMarcha_fh],
[equ_equipo].[vencimientoGarantiaFabrica_ff] as [equ_equipo_vencimientoGarantiaFabrica_ff],
[equ_equipo].[vencimientoGarantiaDistribuidor_ff] as [equ_equipo_vencimientoGarantiaDistribuidor_ff],
[equ_equipo].[horasGarantia] as [equ_equipo_horasGarantia],
[equ_equipo].[ultimaLectura_fh] as [equ_equipo_ultimaLectura_fh],
[equ_equipo].[horometroActual] as [equ_equipo_horometroActual],
[equ_equipo].[promedioHoras] as [equ_equipo_promedioHoras],
[equ_equipo].[costo] as [equ_equipo_costo],
[equ_equipo].[fechaImportacion_ff] as [equ_equipo_fechaImportacion_ff],
[equ_equipo].[garantiaCancelada] as [equ_equipo_garantiaCancelada],
[equ_equipo].[id_catalogo.equipo] as [equ_equipo_id_catalogo.equipo],
[equ_equipo].[id_sistema] as [equ_equipo_id_sistema],
[equ_equipo].[id_sucursal] as [equ_equipo_id_sucursal],
[equ_equipo].[id_zona] as [equ_equipo_id_zona],
[equ_equipo].[id_versionEquipo] as [equ_equipo_id_versionEquipo],
[equ_equipo].[id_tercero_comprador] as [equ_equipo_id_tercero_comprador],
[equ_equipo].[id_tercero] as [equ_equipo_id_tercero],
[equ_equipo].[id_tercero_servicio] as [equ_equipo_id_tercero_servicio],
[equ_equipo].[id_equipo] as [equ_equipo_id_equipo],
[equ_equipo].[id_estadoEquipo] as [equ_equipo_id_estadoEquipo],
[equ_equipo].[id_centroCosto] as [equ_equipo_id_centroCosto],
		[alq_historicoAlquiler].[id_estadoEquipo] AS [id_estadoEquipo],
[equ_estadoEquipo].[estadoEquipo] as [equ_estadoEquipo_estadoEquipo],
[equ_estadoEquipo].[estadoEquipo_codigo] as [equ_estadoEquipo_estadoEquipo_codigo],
[equ_estadoEquipo].[activo] as [equ_estadoEquipo_activo],
		[alq_historicoAlquiler].[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],
		[alq_historicoAlquiler].[fechaEstado] AS [fechaEstado],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [alq_historicoAlquiler]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[alq_historicoAlquiler].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[alq_historicoAlquiler].[id_usuario_creo]
	INNER JOIN [equ_equipo] ON [equ_equipo].id=[alq_historicoAlquiler].[id_equipo]
	INNER JOIN [equ_estadoEquipo] ON [equ_estadoEquipo].id=[alq_historicoAlquiler].[id_estadoEquipo]
	INNER JOIN [doc_documento] ON [doc_documento].id=[alq_historicoAlquiler].[id_documento]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [alq_historicoAlquiler].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [alq_historicoAlquiler].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_historicoAlquileresXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXusuario_modifico]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_historicoAlquiler]
	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_historicoAlquileresXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXusuario_creo]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_historicoAlquiler]
	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_historicoAlquileresXequipo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXequipo]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXequipo]
	@p_id_equipo INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_historicoAlquiler]
	WHERE ([id_equipo]= @p_id_equipo)
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_historicoAlquileresXestadoEquipo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXestadoEquipo]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXestadoEquipo]
	@p_id_estadoEquipo INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_historicoAlquiler]
	WHERE ([id_estadoEquipo]= @p_id_estadoEquipo)
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_historicoAlquileresXdocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXdocumento]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXdocumento]
	@p_id_documento INT
AS
BEGIN
	SELECT * 
	FROM [view_alq_historicoAlquiler]
	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_alq_historicoAlquileres]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileres]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileres]
	
	@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_historicoAlquiler]
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_historicoAlquileres]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_alq_historicoAlquileres]
GO
CREATE PROCEDURE [lis_alq_historicoAlquileres]
	AS
BEGIN
	SELECT id AS id,
[historicoAlquiler] AS [alq_historicoAlquiler]
	FROM [alq_historicoAlquiler]
	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_historicoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_alq_historicoAlquiler]
GO
CREATE PROCEDURE [upd_alq_historicoAlquiler]
	@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_historicoAlquiler varchar(300) = null,
		@p_historicoAlquiler_codigo varchar(100) = null,
		@p_id_equipo int = null,
		@p_id_estadoEquipo int = null,
		@p_id_documento int = null,
		@p_fechaEstado smalldatetime = null
AS
BEGIN
		UPDATE [alq_historicoAlquiler]
		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(),
			[historicoAlquiler] = isnull(@p_historicoAlquiler,[historicoAlquiler]),
			[historicoAlquiler_codigo] = isnull(@p_historicoAlquiler_codigo,[historicoAlquiler_codigo]),
			[id_equipo] = isnull(@p_id_equipo,[id_equipo]),
			[id_estadoEquipo] = isnull(@p_id_estadoEquipo,[id_estadoEquipo]),
			[id_documento] = isnull(@p_id_documento,[id_documento]),
			[fechaEstado] = isnull(@p_fechaEstado,[fechaEstado])
		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_historicoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_alq_historicoAlquiler]
GO
CREATE PROCEDURE [ins_alq_historicoAlquiler]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_historicoAlquiler varchar(300),
		@p_historicoAlquiler_codigo varchar(100),
		@p_id_equipo int,
		@p_id_estadoEquipo int,
		@p_id_documento int,
		@p_fechaEstado smalldatetime
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [alq_historicoAlquiler]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[historicoAlquiler],
			[historicoAlquiler_codigo],
			[id_equipo],
			[id_estadoEquipo],
			[id_documento],
			[fechaEstado])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_historicoAlquiler,
			@p_historicoAlquiler_codigo,
			@p_id_equipo,
			@p_id_estadoEquipo,
			@p_id_documento,
			@p_fechaEstado)
		SET @v_id = scope_identity()
UPDATE [alq_historicoAlquiler] 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_historicoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_alq_historicoAlquiler]
GO
CREATE PROCEDURE [act_alq_historicoAlquiler]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [alq_historicoAlquiler]
	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_historicoAlquiler_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_alq_historicoAlquiler_m]
GO
CREATE PROCEDURE [reg_alq_historicoAlquiler_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],
		[historicoAlquiler] AS [historicoAlquiler],
		[historicoAlquiler_codigo] AS [historicoAlquiler_codigo],
		[id_equipo] AS [id_equipo],
		[id_estadoEquipo] AS [id_estadoEquipo],
		[id_documento] AS [id_documento],
		[fechaEstado] AS [fechaEstado]
	FROM [alq_historicoAlquiler]
	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_historicoAlquileresXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_historicoAlquiler]
	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_historicoAlquileresXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXusuario_creo_m]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_historicoAlquiler]
	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_historicoAlquileresXequipo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXequipo_m]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXequipo_m]
	@p_id_equipo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_historicoAlquiler]
	WHERE ([id_equipo]= @p_id_equipo)
	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_historicoAlquileresXestadoEquipo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXestadoEquipo_m]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXestadoEquipo_m]
	@p_id_estadoEquipo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_historicoAlquiler]
	WHERE ([id_estadoEquipo]= @p_id_estadoEquipo)
	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_historicoAlquileresXdocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileresXdocumento_m]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileresXdocumento_m]
	@p_id_documento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_alq_historicoAlquiler]
	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_alq_historicoAlquileres_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_alq_historicoAlquileres_m]
GO
CREATE PROCEDURE [sel_alq_historicoAlquileres_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_historicoAlquiler]
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_historicoAlquileres_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_alq_historicoAlquileres_m]
GO
CREATE PROCEDURE [lis_alq_historicoAlquileres_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[historicoAlquiler] AS [alq_historicoAlquiler]
	FROM [alq_historicoAlquiler]
	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_historicoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_alq_historicoAlquiler]
GO
CREATE PROCEDURE [aud_alq_historicoAlquiler]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [alq_historicoAlquiler].id as id_tabla,
	[alq_historicoAlquiler].id_usuario_modifico as id_usuario_modifico,
	[alq_historicoAlquiler].id_usuario_creo as id_usuario_creo,
	[alq_historicoAlquiler].fechaModificacion as fechaModificacion,
	[alq_historicoAlquiler].fechaCreacion as fechaCreacion,
	[alq_historicoAlquiler].active as active,
	[alq_historicoAlquiler].[historicoAlquiler] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [alq_historicoAlquiler]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[alq_historicoAlquiler].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[alq_historicoAlquiler].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'alq_historicoAlquiler'
-----------------------------------19/04/2018 11:05:45