

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_equ_detallePagoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_equ_detallePagoAlquiler]
GO
CREATE PROCEDURE [reg_equ_detallePagoAlquiler]
	@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],
		[detallePagoAlquiler] AS [detallePagoAlquiler],
		[detallePagoAlquiler_codigo] AS [detallePagoAlquiler_codigo],
		[valor] AS [valor],
		[horometro] AS [horometro],
		[id_pagoAlquiler] AS [id_pagoAlquiler],
		[id_equipo] AS [id_equipo],
		[valorMulta] AS [valorMulta],
		[facturado] AS [facturado],
		[fechaInicial_ff] AS [fechaInicial_ff],
		[fechaFin_ff] AS [fechaFin_ff],
		[id_documento] AS [id_documento],
		[id_itemDocumento] AS [id_itemDocumento]
	FROM [equ_detallePagoAlquiler]
	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_equ_detallePagoAlquiler]')) DROP VIEW [dbo].[view_equ_detallePagoAlquiler]
GO
CREATE  VIEW [view_equ_detallePagoAlquiler] AS
SELECT 	[equ_detallePagoAlquiler].[id] AS [id],
		[equ_detallePagoAlquiler].[uid] AS [uid],
		[equ_detallePagoAlquiler].[eid] AS [eid],
		[equ_detallePagoAlquiler].[id_usuario_modifico] AS [id_usuario_modifico],
		[equ_detallePagoAlquiler].[id_usuario_creo] AS [id_usuario_creo],
		[equ_detallePagoAlquiler].[fechaModificacion] AS [fechaModificacion],
		[equ_detallePagoAlquiler].[fechaCreacion] AS [fechaCreacion],
		[equ_detallePagoAlquiler].[active] AS [active],
		[equ_detallePagoAlquiler].[detallePagoAlquiler] AS [detallePagoAlquiler],
		[equ_detallePagoAlquiler].[detallePagoAlquiler_codigo] AS [detallePagoAlquiler_codigo],
		[equ_detallePagoAlquiler].[valor] AS [valor],
		[equ_detallePagoAlquiler].[horometro] AS [horometro],
		[equ_detallePagoAlquiler].[id_pagoAlquiler] AS [id_pagoAlquiler],
[equ_pagoAlquiler].[pagoAlquiler] as [equ_pagoAlquiler_pagoAlquiler],
[equ_pagoAlquiler].[pagoAlquiler_codigo] as [equ_pagoAlquiler_pagoAlquiler_codigo],
[equ_pagoAlquiler].[valorPorCobrar] as [equ_pagoAlquiler_valorPorCobrar],
[equ_pagoAlquiler].[valorFacturado] as [equ_pagoAlquiler_valorFacturado],
[equ_pagoAlquiler].[numeroFactura] as [equ_pagoAlquiler_numeroFactura],
[equ_pagoAlquiler].[fechaEsperadaPago_ff] as [equ_pagoAlquiler_fechaEsperadaPago_ff],
[equ_pagoAlquiler].[fecha_factura_ff] as [equ_pagoAlquiler_fecha_factura_ff],
[equ_pagoAlquiler].[id_documento.alquiler] as [equ_pagoAlquiler_id_documento.alquiler],
		[equ_detallePagoAlquiler].[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_detallePagoAlquiler].[valorMulta] AS [valorMulta],
		[equ_detallePagoAlquiler].[facturado] AS [facturado],
		[equ_detallePagoAlquiler].[fechaInicial_ff] AS [fechaInicial_ff],
		[equ_detallePagoAlquiler].[fechaFin_ff] AS [fechaFin_ff],
		[equ_detallePagoAlquiler].[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],
		[equ_detallePagoAlquiler].[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],
[doc_itemDocumento].[id_listaprecio] as [doc_itemDocumento_id_listaprecio],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [equ_detallePagoAlquiler]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[equ_detallePagoAlquiler].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[equ_detallePagoAlquiler].[id_usuario_creo]
	INNER JOIN [equ_pagoAlquiler] ON [equ_pagoAlquiler].id=[equ_detallePagoAlquiler].[id_pagoAlquiler]
	INNER JOIN [equ_equipo] ON [equ_equipo].id=[equ_detallePagoAlquiler].[id_equipo]
	INNER JOIN [doc_documento] ON [doc_documento].id=[equ_detallePagoAlquiler].[id_documento]
	INNER JOIN [doc_itemDocumento] ON [doc_itemDocumento].id=[equ_detallePagoAlquiler].[id_itemDocumento]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [equ_detallePagoAlquiler].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [equ_detallePagoAlquiler].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_equ_detallePagoAlquileresXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXusuario_modifico]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXusuario_creo]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXpagoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXpagoAlquiler]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXpagoAlquiler]
	@p_id_pagoAlquiler INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_detallePagoAlquiler]
	WHERE ([id_pagoAlquiler]= @p_id_pagoAlquiler)
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_equ_detallePagoAlquileresXequipo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXequipo]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXequipo]
	@p_id_equipo INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXdocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXdocumento]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXdocumento]
	@p_id_documento INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXitemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXitemDocumento]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXitemDocumento]
	@p_id_itemDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileres]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileres]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileres]
	
	@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_equ_detallePagoAlquiler]
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_equ_detallePagoAlquileres]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_equ_detallePagoAlquileres]
GO
CREATE PROCEDURE [lis_equ_detallePagoAlquileres]
	AS
BEGIN
	SELECT id AS id,
[detallePagoAlquiler] AS [equ_detallePagoAlquiler]
	FROM [equ_detallePagoAlquiler]
	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_equ_detallePagoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_equ_detallePagoAlquiler]
GO
CREATE PROCEDURE [upd_equ_detallePagoAlquiler]
	@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_detallePagoAlquiler varchar(300) = null,
		@p_detallePagoAlquiler_codigo varchar(100) = null,
		@p_valor money = null,
		@p_horometro float = null,
		@p_id_pagoAlquiler int = null,
		@p_id_equipo int = null,
		@p_valorMulta float = null,
		@p_facturado bit = null,
		@p_fechaInicial_ff smalldatetime = null,
		@p_fechaFin_ff smalldatetime = null,
		@p_id_documento int = null,
		@p_id_itemDocumento int = null
AS
BEGIN
		UPDATE [equ_detallePagoAlquiler]
		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(),
			[detallePagoAlquiler] = isnull(@p_detallePagoAlquiler,[detallePagoAlquiler]),
			[detallePagoAlquiler_codigo] = isnull(@p_detallePagoAlquiler_codigo,[detallePagoAlquiler_codigo]),
			[valor] = isnull(@p_valor,[valor]),
			[horometro] = isnull(@p_horometro,[horometro]),
			[id_pagoAlquiler] = isnull(@p_id_pagoAlquiler,[id_pagoAlquiler]),
			[id_equipo] = isnull(@p_id_equipo,[id_equipo]),
			[valorMulta] = isnull(@p_valorMulta,[valorMulta]),
			[facturado] = isnull(@p_facturado,[facturado]),
			[fechaInicial_ff] = isnull(@p_fechaInicial_ff,[fechaInicial_ff]),
			[fechaFin_ff] = isnull(@p_fechaFin_ff,[fechaFin_ff]),
			[id_documento] = isnull(@p_id_documento,[id_documento]),
			[id_itemDocumento] = isnull(@p_id_itemDocumento,[id_itemDocumento])
		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_equ_detallePagoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_equ_detallePagoAlquiler]
GO
CREATE PROCEDURE [ins_equ_detallePagoAlquiler]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_detallePagoAlquiler varchar(300),
		@p_detallePagoAlquiler_codigo varchar(100),
		@p_valor money,
		@p_horometro float,
		@p_id_pagoAlquiler int,
		@p_id_equipo int,
		@p_valorMulta float,
		@p_facturado bit,
		@p_fechaInicial_ff smalldatetime,
		@p_fechaFin_ff smalldatetime,
		@p_id_documento int,
		@p_id_itemDocumento int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [equ_detallePagoAlquiler]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[detallePagoAlquiler],
			[detallePagoAlquiler_codigo],
			[valor],
			[horometro],
			[id_pagoAlquiler],
			[id_equipo],
			[valorMulta],
			[facturado],
			[fechaInicial_ff],
			[fechaFin_ff],
			[id_documento],
			[id_itemDocumento])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_detallePagoAlquiler,
			@p_detallePagoAlquiler_codigo,
			@p_valor,
			@p_horometro,
			@p_id_pagoAlquiler,
			@p_id_equipo,
			@p_valorMulta,
			@p_facturado,
			@p_fechaInicial_ff,
			@p_fechaFin_ff,
			@p_id_documento,
			@p_id_itemDocumento)
		SET @v_id = scope_identity()
UPDATE [equ_detallePagoAlquiler] 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_equ_detallePagoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_equ_detallePagoAlquiler]
GO
CREATE PROCEDURE [act_equ_detallePagoAlquiler]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [equ_detallePagoAlquiler]
	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_equ_detallePagoAlquiler_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_equ_detallePagoAlquiler_m]
GO
CREATE PROCEDURE [reg_equ_detallePagoAlquiler_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],
		[detallePagoAlquiler] AS [detallePagoAlquiler],
		[detallePagoAlquiler_codigo] AS [detallePagoAlquiler_codigo],
		[valor] AS [valor],
		[horometro] AS [horometro],
		[id_pagoAlquiler] AS [id_pagoAlquiler],
		[id_equipo] AS [id_equipo],
		[valorMulta] AS [valorMulta],
		[facturado] AS [facturado],
		[fechaInicial_ff] AS [fechaInicial_ff],
		[fechaFin_ff] AS [fechaFin_ff],
		[id_documento] AS [id_documento],
		[id_itemDocumento] AS [id_itemDocumento]
	FROM [equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXusuario_creo_m]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXpagoAlquiler_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXpagoAlquiler_m]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXpagoAlquiler_m]
	@p_id_pagoAlquiler INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_detallePagoAlquiler]
	WHERE ([id_pagoAlquiler]= @p_id_pagoAlquiler)
	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_equ_detallePagoAlquileresXequipo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXequipo_m]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXequipo_m]
	@p_id_equipo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXdocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXdocumento_m]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXdocumento_m]
	@p_id_documento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileresXitemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileresXitemDocumento_m]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileresXitemDocumento_m]
	@p_id_itemDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_equ_detallePagoAlquiler]
	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_equ_detallePagoAlquileres_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_equ_detallePagoAlquileres_m]
GO
CREATE PROCEDURE [sel_equ_detallePagoAlquileres_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_equ_detallePagoAlquiler]
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_equ_detallePagoAlquileres_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_equ_detallePagoAlquileres_m]
GO
CREATE PROCEDURE [lis_equ_detallePagoAlquileres_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[detallePagoAlquiler] AS [equ_detallePagoAlquiler]
	FROM [equ_detallePagoAlquiler]
	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_equ_detallePagoAlquiler]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_equ_detallePagoAlquiler]
GO
CREATE PROCEDURE [aud_equ_detallePagoAlquiler]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [equ_detallePagoAlquiler].id as id_tabla,
	[equ_detallePagoAlquiler].id_usuario_modifico as id_usuario_modifico,
	[equ_detallePagoAlquiler].id_usuario_creo as id_usuario_creo,
	[equ_detallePagoAlquiler].fechaModificacion as fechaModificacion,
	[equ_detallePagoAlquiler].fechaCreacion as fechaCreacion,
	[equ_detallePagoAlquiler].active as active,
	[equ_detallePagoAlquiler].[detallePagoAlquiler] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [equ_detallePagoAlquiler]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[equ_detallePagoAlquiler].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[equ_detallePagoAlquiler].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'equ_detallePagoAlquiler'
-----------------------------------07/04/2016 13:54:57