

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_gas_documento_ot_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gas_documento_ot_detalleGasto]
GO
CREATE PROCEDURE [reg_gas_documento_ot_detalleGasto]
	@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],
		[documento.ot_detalleGasto] AS [documento.ot_detalleGasto],
		[id_detalleGasto] AS [id_detalleGasto],
		[id_documento.ot] AS [id_documento.ot],
		[id_itemDocumento] AS [id_itemDocumento]
	FROM [gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGasto]')) DROP VIEW [dbo].[view_gas_documento_ot_detalleGasto]
GO
CREATE  VIEW [view_gas_documento_ot_detalleGasto] AS
SELECT 	[gas_documento.ot_detalleGasto].[id] AS [id],
		[gas_documento.ot_detalleGasto].[uid] AS [uid],
		[gas_documento.ot_detalleGasto].[eid] AS [eid],
		[gas_documento.ot_detalleGasto].[id_usuario_modifico] AS [id_usuario_modifico],
		[gas_documento.ot_detalleGasto].[id_usuario_creo] AS [id_usuario_creo],
		[gas_documento.ot_detalleGasto].[fechaModificacion] AS [fechaModificacion],
		[gas_documento.ot_detalleGasto].[fechaCreacion] AS [fechaCreacion],
		[gas_documento.ot_detalleGasto].[active] AS [active],
		[gas_documento.ot_detalleGasto].[documento.ot_detalleGasto] AS [documento.ot_detalleGasto],
		[gas_documento.ot_detalleGasto].[id_detalleGasto] AS [id_detalleGasto],
[gas_detalleGasto].[detalleGasto] as [gas_detalleGasto_detalleGasto],
[gas_detalleGasto].[detalleGasto_codigo] as [gas_detalleGasto_detalleGasto_codigo],
[gas_detalleGasto].[fecha_ff] as [gas_detalleGasto_fecha_ff],
[gas_detalleGasto].[valor] as [gas_detalleGasto_valor],
[gas_detalleGasto].[cantidad] as [gas_detalleGasto_cantidad],
[gas_detalleGasto].[id_gasto] as [gas_detalleGasto_id_gasto],
[gas_detalleGasto].[id_catalogo] as [gas_detalleGasto_id_catalogo],
		[gas_documento.ot_detalleGasto].[id_documento.ot] AS [id_documento.ot],
[doc_documento.ot].[documento.ot] as [doc_documento.ot_documento.ot],
[doc_documento.ot].[motivoServicio] as [doc_documento.ot_motivoServicio],
[doc_documento.ot].[enTaller] as [doc_documento.ot_enTaller],
[doc_documento.ot].[diagnosticoInicial] as [doc_documento.ot_diagnosticoInicial],
[doc_documento.ot].[contacto] as [doc_documento.ot_contacto],
[doc_documento.ot].[cargo] as [doc_documento.ot_cargo],
[doc_documento.ot].[telefono] as [doc_documento.ot_telefono],
[doc_documento.ot].[fax] as [doc_documento.ot_fax],
[doc_documento.ot].[email] as [doc_documento.ot_email],
[doc_documento.ot].[direccionUbicacion] as [doc_documento.ot_direccionUbicacion],
[doc_documento.ot].[duracionEstimada] as [doc_documento.ot_duracionEstimada],
[doc_documento.ot].[fechaGarantia_ff] as [doc_documento.ot_fechaGarantia_ff],
[doc_documento.ot].[fechaCompromiso_fh] as [doc_documento.ot_fechaCompromiso_fh],
[doc_documento.ot].[trabajos] as [doc_documento.ot_trabajos],
[doc_documento.ot].[recomendaciones] as [doc_documento.ot_recomendaciones],
[doc_documento.ot].[compromisos] as [doc_documento.ot_compromisos],
[doc_documento.ot].[reclamacionFabrica] as [doc_documento.ot_reclamacionFabrica],
[doc_documento.ot].[porcentajeCliente] as [doc_documento.ot_porcentajeCliente],
[doc_documento.ot].[porcentajeDistribuidor] as [doc_documento.ot_porcentajeDistribuidor],
[doc_documento.ot].[porcentajeFabricante] as [doc_documento.ot_porcentajeFabricante],
[doc_documento.ot].[segunTempario] as [doc_documento.ot_segunTempario],
[doc_documento.ot].[distribuyeCentros] as [doc_documento.ot_distribuyeCentros],
[doc_documento.ot].[id_tipoServicio] as [doc_documento.ot_id_tipoServicio],
[doc_documento.ot].[id_equipo] as [doc_documento.ot_id_equipo],
[doc_documento.ot].[id_usuario_coordinador] as [doc_documento.ot_id_usuario_coordinador],
[doc_documento.ot].[id_motivoCancelacion] as [doc_documento.ot_id_motivoCancelacion],
[doc_documento.ot].[id_sucursal] as [doc_documento.ot_id_sucursal],
[doc_documento.ot].[id_sistema] as [doc_documento.ot_id_sistema],
[doc_documento.ot].[id_departamentoSolicitud] as [doc_documento.ot_id_departamentoSolicitud],
[doc_documento.ot].[id_contrato] as [doc_documento.ot_id_contrato],
[doc_documento.ot].[id_zona] as [doc_documento.ot_id_zona],
		[doc_documento_ot].[documento_codigo] AS [doc_documento_ot_documento_codigo],
		[doc_documento_ot].[documento_numero] AS [doc_documento_ot_documento_numero],
		[doc_documento_ot].[prefijo] AS [doc_documento_ot_prefijo],
		[doc_documento_ot].[subtotal] AS [doc_documento_ot_subtotal],
		[doc_documento_ot].[descuento] AS [doc_documento_ot_descuento],
		[doc_documento_ot].[iva] AS [doc_documento_ot_iva],
		[doc_documento_ot].[total] AS [doc_documento_ot_total],
		[doc_documento_ot].[costo] AS [doc_documento_ot_costo],
		[doc_documento_ot].[rentabilidad] AS [doc_documento_ot_rentabilidad],
		[doc_documento_ot].[trm] AS [doc_documento_ot_trm],
		[doc_documento_ot].[fecha_fh] AS [doc_documento_ot_fecha_fh],
		[doc_documento_ot].[fechaSugerida_fh] AS [doc_documento_ot_fechaSugerida_fh],
		[doc_documento_ot].[fechaCierre_ff] AS [doc_documento_ot_fechaCierre_ff],
		[doc_documento_ot].[fechaLimite_fh] AS [doc_documento_ot_fechaLimite_fh],
		[doc_documento_ot].[id_subtipoDocumento] AS [doc_documento_ot_id_subtipoDocumento],
		[doc_documento_ot].[id_tercero_cliente] AS [doc_documento_ot_id_tercero_cliente],
		[doc_documento_ot].[id_documento] AS [doc_documento_ot_id_documento],
		[doc_documento_ot].[id_tercero_proveedor] AS [doc_documento_ot_id_tercero_proveedor],
		[doc_documento_ot].[id_prioridadDocumento] AS [doc_documento_ot_id_prioridadDocumento],
		[doc_documento_ot].[id_moneda] AS [doc_documento_ot_id_moneda],
		[doc_documento_ot].[id_estadoTipoDocumento] AS [doc_documento_ot_id_estadoTipoDocumento],
		[doc_documento_ot].[id_motivoestado] AS [doc_documento_ot_id_motivoestado],
		[doc_documento_ot].[subtotalPlaneado] AS [doc_documento_ot_subtotalPlaneado],
		[doc_documento_ot].[descuentoPlaneado] AS [doc_documento_ot_descuentoPlaneado],
		[doc_documento_ot].[ivaPlaneado] AS [doc_documento_ot_ivaPlaneado],
		[doc_documento_ot].[totalPlaneado] AS [doc_documento_ot_totalPlaneado],
		[doc_documento_ot].[costoPlaneado] AS [doc_documento_ot_costoPlaneado],
		[gas_documento.ot_detalleGasto].[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 [gas_documento.ot_detalleGasto]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gas_documento.ot_detalleGasto].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gas_documento.ot_detalleGasto].[id_usuario_creo]
	INNER JOIN [gas_detalleGasto] ON [gas_detalleGasto].id=[gas_documento.ot_detalleGasto].[id_detalleGasto]
	INNER JOIN [doc_documento.ot] ON [doc_documento.ot].id=[gas_documento.ot_detalleGasto].[id_documento.ot]
	INNER JOIN [doc_documento] aS [doc_documento_ot] ON [doc_documento.ot].id = [doc_documento_ot].id
	INNER JOIN [doc_itemDocumento] ON [doc_itemDocumento].id=[gas_documento.ot_detalleGasto].[id_itemDocumento]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [gas_documento.ot_detalleGasto].eid = [empresaCodigo].[codigo] and empresaCodigo.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_gas_documento_ot_detalleGastosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXusuario_modifico]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGastosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXusuario_creo]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGastosXdetalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXdetalleGasto]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXdetalleGasto]
	@p_id_detalleGasto INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_documento.ot_detalleGasto]
	WHERE ([id_detalleGasto]= @p_id_detalleGasto)
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_gas_documento_ot_detalleGastosXdocumento_ot]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXdocumento_ot]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXdocumento_ot]
	@p_id_documento_ot INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_documento.ot_detalleGasto]
	WHERE ([id_documento.ot]= @p_id_documento_ot)
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_gas_documento_ot_detalleGastosXitemDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXitemDocumento]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXitemDocumento]
	@p_id_itemDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGastos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastos]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastos]
	
	@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_gas_documento_ot_detalleGasto]
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_gas_documento_ot_detalleGastos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gas_documento_ot_detalleGastos]
GO
CREATE PROCEDURE [lis_gas_documento_ot_detalleGastos]
	AS
BEGIN
	SELECT id AS id,
[documento.ot_detalleGasto] AS [gas_documento.ot_detalleGasto]
	FROM [gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_gas_documento_ot_detalleGasto]
GO
CREATE PROCEDURE [upd_gas_documento_ot_detalleGasto]
	@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_documento_ot_detalleGasto varchar(300) = null,
		@p_id_detalleGasto int = null,
		@p_id_documento_ot int = null,
		@p_id_itemDocumento int = null
AS
BEGIN
		UPDATE [gas_documento.ot_detalleGasto]
		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(),
			[documento.ot_detalleGasto] = isnull(@p_documento_ot_detalleGasto,[documento.ot_detalleGasto]),
			[id_detalleGasto] = isnull(@p_id_detalleGasto,[id_detalleGasto]),
			[id_documento.ot] = isnull(@p_id_documento_ot,[id_documento.ot]),
			[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_gas_documento_ot_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_gas_documento_ot_detalleGasto]
GO
CREATE PROCEDURE [ins_gas_documento_ot_detalleGasto]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_documento_ot_detalleGasto varchar(300),
		@p_id_detalleGasto int,
		@p_id_documento_ot int,
		@p_id_itemDocumento int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [gas_documento.ot_detalleGasto]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[documento.ot_detalleGasto],
			[id_detalleGasto],
			[id_documento.ot],
			[id_itemDocumento])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_documento_ot_detalleGasto,
			@p_id_detalleGasto,
			@p_id_documento_ot,
			@p_id_itemDocumento)
		SET @v_id = scope_identity()
UPDATE [gas_documento.ot_detalleGasto] 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_gas_documento_ot_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_gas_documento_ot_detalleGasto]
GO
CREATE PROCEDURE [act_gas_documento_ot_detalleGasto]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGasto_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gas_documento_ot_detalleGasto_m]
GO
CREATE PROCEDURE [reg_gas_documento_ot_detalleGasto_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],
		[documento.ot_detalleGasto] AS [documento.ot_detalleGasto],
		[id_detalleGasto] AS [id_detalleGasto],
		[id_documento.ot] AS [id_documento.ot],
		[id_itemDocumento] AS [id_itemDocumento]
	FROM [gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGastosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGastosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGastosXdetalleGasto_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXdetalleGasto_m]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXdetalleGasto_m]
	@p_id_detalleGasto INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_documento.ot_detalleGasto]
	WHERE ([id_detalleGasto]= @p_id_detalleGasto)
	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_gas_documento_ot_detalleGastosXdocumento_ot_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXdocumento_ot_m]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXdocumento_ot_m]
	@p_id_documento_ot INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_documento.ot_detalleGasto]
	WHERE ([id_documento.ot]= @p_id_documento_ot)
	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_gas_documento_ot_detalleGastosXitemDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastosXitemDocumento_m]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastosXitemDocumento_m]
	@p_id_itemDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGastos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_documento_ot_detalleGastos_m]
GO
CREATE PROCEDURE [sel_gas_documento_ot_detalleGastos_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_gas_documento_ot_detalleGasto]
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_gas_documento_ot_detalleGastos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gas_documento_ot_detalleGastos_m]
GO
CREATE PROCEDURE [lis_gas_documento_ot_detalleGastos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[documento.ot_detalleGasto] AS [gas_documento.ot_detalleGasto]
	FROM [gas_documento.ot_detalleGasto]
	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_gas_documento_ot_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_gas_documento_ot_detalleGasto]
GO
CREATE PROCEDURE [aud_gas_documento_ot_detalleGasto]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [gas_documento.ot_detalleGasto].id as id_tabla,
	[gas_documento.ot_detalleGasto].id_usuario_modifico as id_usuario_modifico,
	[gas_documento.ot_detalleGasto].id_usuario_creo as id_usuario_creo,
	[gas_documento.ot_detalleGasto].fechaModificacion as fechaModificacion,
	[gas_documento.ot_detalleGasto].fechaCreacion as fechaCreacion,
	[gas_documento.ot_detalleGasto].active as active,
	[gas_documento.ot_detalleGasto].[documento.ot_detalleGasto] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [gas_documento.ot_detalleGasto]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gas_documento.ot_detalleGasto].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gas_documento.ot_detalleGasto].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'gas_documento.ot_detalleGasto'
-----------------------------------07/04/2016 11:36:24