IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_gas_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gas_detalleGasto]
GO
CREATE PROCEDURE [reg_gas_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],
		[detalleGasto] AS [detalleGasto],
		[detalleGasto_codigo] AS [detalleGasto_codigo],
		[fecha_ff] AS [fecha_ff],
		[valor] AS [valor],
		[cantidad] AS [cantidad],
		[id_gasto] AS [id_gasto],
		[id_catalogo] AS [id_catalogo],
		[id_documento.gasto] AS [id_documento.gasto]
	FROM [gas_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_detalleGasto]')) DROP VIEW [dbo].[view_gas_detalleGasto]
GO
CREATE  VIEW [view_gas_detalleGasto] AS
SELECT 	[gas_detalleGasto].[id] AS [id],
		[gas_detalleGasto].[uid] AS [uid],
		[gas_detalleGasto].[eid] AS [eid],
		[gas_detalleGasto].[id_usuario_modifico] AS [id_usuario_modifico],
		[gas_detalleGasto].[id_usuario_creo] AS [id_usuario_creo],
		[gas_detalleGasto].[fechaModificacion] AS [fechaModificacion],
		[gas_detalleGasto].[fechaCreacion] AS [fechaCreacion],
		[gas_detalleGasto].[active] AS [active],
		[gas_detalleGasto].[detalleGasto] AS [detalleGasto],
		[gas_detalleGasto].[detalleGasto_codigo] AS [detalleGasto_codigo],
		[gas_detalleGasto].[fecha_ff] AS [fecha_ff],
		[gas_detalleGasto].[valor] AS [valor],
		[gas_detalleGasto].[cantidad] AS [cantidad],
		[gas_detalleGasto].[id_gasto] AS [id_gasto],
[gas_gasto].[gasto] as [gas_gasto_gasto],
[gas_gasto].[gasto_codigo] as [gas_gasto_gasto_codigo],
[gas_gasto].[numero] as [gas_gasto_numero],
[gas_gasto].[fecha_ff] as [gas_gasto_fecha_ff],
[gas_gasto].[dias] as [gas_gasto_dias],
[gas_gasto].[valor] as [gas_gasto_valor],
[gas_gasto].[concepto] as [gas_gasto_concepto],
[gas_gasto].[consignado] as [gas_gasto_consignado],
[gas_gasto].[id_tipoGasto] as [gas_gasto_id_tipoGasto],
[gas_gasto].[id_usuario_aprobo] as [gas_gasto_id_usuario_aprobo],
[gas_gasto].[id_usuario_solicitante] as [gas_gasto_id_usuario_solicitante],
[gas_gasto].[id_estadoTipoDocumento] as [gas_gasto_id_estadoTipoDocumento],
		[gas_detalleGasto].[id_catalogo] AS [id_catalogo],
[cat_catalogo].[catalogo] as [cat_catalogo_catalogo],
[cat_catalogo].[catalogo_codigo] as [cat_catalogo_catalogo_codigo],
[cat_catalogo].[codigoInventario] as [cat_catalogo_codigoInventario],
[cat_catalogo].[precioVenta] as [cat_catalogo_precioVenta],
[cat_catalogo].[tiempoConsecucion] as [cat_catalogo_tiempoConsecucion],
[cat_catalogo].[esNacional] as [cat_catalogo_esNacional],
[cat_catalogo].[id_familia] as [cat_catalogo_id_familia],
[cat_catalogo].[id_subtipoCatalogo] as [cat_catalogo_id_subtipoCatalogo],
[cat_catalogo].[id_unidad] as [cat_catalogo_id_unidad],
[cat_catalogo].[id_impuesto] as [cat_catalogo_id_impuesto],
[cat_catalogo].[descripcion] as [cat_catalogo_descripcion],
[cat_catalogo].[bloquearCostear] as [cat_catalogo_bloquearCostear],
		[gas_detalleGasto].[id_documento.gasto] AS [id_documento.gasto],
[doc_documento.gasto].[documento.gasto] as [doc_documento.gasto_documento.gasto],
[doc_documento.gasto].[fecha_ff] as [doc_documento.gasto_fecha_ff],
[doc_documento.gasto].[dias] as [doc_documento.gasto_dias],
[doc_documento.gasto].[concepto] as [doc_documento.gasto_concepto],
[doc_documento.gasto].[consignado] as [doc_documento.gasto_consignado],
		[doc_documento_gasto].[documento_codigo] AS [doc_documento_gasto_documento_codigo],
		[doc_documento_gasto].[documento_numero] AS [doc_documento_gasto_documento_numero],
		[doc_documento_gasto].[prefijo] AS [doc_documento_gasto_prefijo],
		[doc_documento_gasto].[subtotal] AS [doc_documento_gasto_subtotal],
		[doc_documento_gasto].[descuento] AS [doc_documento_gasto_descuento],
		[doc_documento_gasto].[iva] AS [doc_documento_gasto_iva],
		[doc_documento_gasto].[total] AS [doc_documento_gasto_total],
		[doc_documento_gasto].[costo] AS [doc_documento_gasto_costo],
		[doc_documento_gasto].[rentabilidad] AS [doc_documento_gasto_rentabilidad],
		[doc_documento_gasto].[trm] AS [doc_documento_gasto_trm],
		[doc_documento_gasto].[fecha_fh] AS [doc_documento_gasto_fecha_fh],
		[doc_documento_gasto].[fechaSugerida_fh] AS [doc_documento_gasto_fechaSugerida_fh],
		[doc_documento_gasto].[fechaCierre_ff] AS [doc_documento_gasto_fechaCierre_ff],
		[doc_documento_gasto].[fechaLimite_fh] AS [doc_documento_gasto_fechaLimite_fh],
		[doc_documento_gasto].[id_subtipoDocumento] AS [doc_documento_gasto_id_subtipoDocumento],
		[doc_documento_gasto].[id_tercero_cliente] AS [doc_documento_gasto_id_tercero_cliente],
		[doc_documento_gasto].[id_documento] AS [doc_documento_gasto_id_documento],
		[doc_documento_gasto].[id_tercero_proveedor] AS [doc_documento_gasto_id_tercero_proveedor],
		[doc_documento_gasto].[id_prioridadDocumento] AS [doc_documento_gasto_id_prioridadDocumento],
		[doc_documento_gasto].[id_moneda] AS [doc_documento_gasto_id_moneda],
		[doc_documento_gasto].[id_estadoTipoDocumento] AS [doc_documento_gasto_id_estadoTipoDocumento],
		[doc_documento_gasto].[id_motivoestado] AS [doc_documento_gasto_id_motivoestado],
		[doc_documento_gasto].[subtotalPlaneado] AS [doc_documento_gasto_subtotalPlaneado],
		[doc_documento_gasto].[descuentoPlaneado] AS [doc_documento_gasto_descuentoPlaneado],
		[doc_documento_gasto].[ivaPlaneado] AS [doc_documento_gasto_ivaPlaneado],
		[doc_documento_gasto].[totalPlaneado] AS [doc_documento_gasto_totalPlaneado],
		[doc_documento_gasto].[costoPlaneado] AS [doc_documento_gasto_costoPlaneado],
		[doc_documento_gasto].[id_usuario_asignado] AS [doc_documento_gasto_id_usuario_asignado],
		[doc_documento_gasto].[id_usuario_enUso] AS [doc_documento_gasto_id_usuario_enUso],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [gas_detalleGasto]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gas_detalleGasto].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gas_detalleGasto].[id_usuario_creo]
	INNER JOIN [gas_gasto] ON [gas_gasto].id=[gas_detalleGasto].[id_gasto]
	INNER JOIN [cat_catalogo] ON [cat_catalogo].id=[gas_detalleGasto].[id_catalogo]
	INNER JOIN [doc_documento.gasto] ON [doc_documento.gasto].id=[gas_detalleGasto].[id_documento.gasto]
	INNER JOIN [doc_documento] aS [doc_documento_gasto] ON [doc_documento.gasto].id = [doc_documento_gasto].id
	INNER JOIN [gen_empresa] AS empresaCodigo ON [gas_detalleGasto].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [gas_detalleGasto].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_detalleGastosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXusuario_modifico]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_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_detalleGastosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXusuario_creo]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_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_detalleGastosXgasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXgasto]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXgasto]
	@p_id_gasto INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_detalleGasto]
	WHERE ([id_gasto]= @p_id_gasto)
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_detalleGastosXcatalogo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXcatalogo]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXcatalogo]
	@p_id_catalogo INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_detalleGasto]
	WHERE ([id_catalogo]= @p_id_catalogo)
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_detalleGastosXdocumento_gasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXdocumento_gasto]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXdocumento_gasto]
	@p_id_documento_gasto INT
AS
BEGIN
	SELECT * 
	FROM [view_gas_detalleGasto]
	WHERE ([id_documento.gasto]= @p_id_documento_gasto)
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_detalleGastos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastos]
GO
CREATE PROCEDURE [sel_gas_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_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_detalleGastos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gas_detalleGastos]
GO
CREATE PROCEDURE [lis_gas_detalleGastos]
	AS
BEGIN
	SELECT id AS id,
[detalleGasto] AS [gas_detalleGasto]
	FROM [gas_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_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_gas_detalleGasto]
GO
CREATE PROCEDURE [upd_gas_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_detalleGasto varchar(300) = null,
		@p_detalleGasto_codigo varchar(100) = null,
		@p_fecha_ff smalldatetime = null,
		@p_valor float = null,
		@p_cantidad float = null,
		@p_id_gasto int = null,
		@p_id_catalogo int = null,
		@p_id_documento_gasto int = null
AS
BEGIN
		UPDATE [gas_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(),
			[detalleGasto] = isnull(@p_detalleGasto,[detalleGasto]),
			[detalleGasto_codigo] = isnull(@p_detalleGasto_codigo,[detalleGasto_codigo]),
			[fecha_ff] = isnull(@p_fecha_ff,[fecha_ff]),
			[valor] = isnull(@p_valor,[valor]),
			[cantidad] = isnull(@p_cantidad,[cantidad]),
			[id_gasto] = isnull(@p_id_gasto,[id_gasto]),
			[id_catalogo] = isnull(@p_id_catalogo,[id_catalogo]),
			[id_documento.gasto] = isnull(@p_id_documento_gasto,[id_documento.gasto])
		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_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_gas_detalleGasto]
GO
CREATE PROCEDURE [ins_gas_detalleGasto]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_detalleGasto varchar(300),
		@p_detalleGasto_codigo varchar(100),
		@p_fecha_ff smalldatetime,
		@p_valor float,
		@p_cantidad float,
		@p_id_gasto int,
		@p_id_catalogo int,
		@p_id_documento_gasto int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [gas_detalleGasto]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[detalleGasto],
			[detalleGasto_codigo],
			[fecha_ff],
			[valor],
			[cantidad],
			[id_gasto],
			[id_catalogo],
			[id_documento.gasto])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_detalleGasto,
			@p_detalleGasto_codigo,
			@p_fecha_ff,
			@p_valor,
			@p_cantidad,
			@p_id_gasto,
			@p_id_catalogo,
			@p_id_documento_gasto)
		SET @v_id = scope_identity()
UPDATE [gas_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_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_gas_detalleGasto]
GO
CREATE PROCEDURE [act_gas_detalleGasto]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [gas_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_detalleGasto_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gas_detalleGasto_m]
GO
CREATE PROCEDURE [reg_gas_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],
		[detalleGasto] AS [detalleGasto],
		[detalleGasto_codigo] AS [detalleGasto_codigo],
		[fecha_ff] AS [fecha_ff],
		[valor] AS [valor],
		[cantidad] AS [cantidad],
		[id_gasto] AS [id_gasto],
		[id_catalogo] AS [id_catalogo],
		[id_documento.gasto] AS [id_documento.gasto]
	FROM [gas_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_detalleGastosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_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_detalleGastosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_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_detalleGastosXgasto_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXgasto_m]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXgasto_m]
	@p_id_gasto INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_detalleGasto]
	WHERE ([id_gasto]= @p_id_gasto)
	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_detalleGastosXcatalogo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXcatalogo_m]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXcatalogo_m]
	@p_id_catalogo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_detalleGasto]
	WHERE ([id_catalogo]= @p_id_catalogo)
	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_detalleGastosXdocumento_gasto_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastosXdocumento_gasto_m]
GO
CREATE PROCEDURE [sel_gas_detalleGastosXdocumento_gasto_m]
	@p_id_documento_gasto INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gas_detalleGasto]
	WHERE ([id_documento.gasto]= @p_id_documento_gasto)
	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_detalleGastos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gas_detalleGastos_m]
GO
CREATE PROCEDURE [sel_gas_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_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_detalleGastos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gas_detalleGastos_m]
GO
CREATE PROCEDURE [lis_gas_detalleGastos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[detalleGasto] AS [gas_detalleGasto]
	FROM [gas_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_detalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_gas_detalleGasto]
GO
CREATE PROCEDURE [aud_gas_detalleGasto]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [gas_detalleGasto].id as id_tabla,
	[gas_detalleGasto].id_usuario_modifico as id_usuario_modifico,
	[gas_detalleGasto].id_usuario_creo as id_usuario_creo,
	[gas_detalleGasto].fechaModificacion as fechaModificacion,
	[gas_detalleGasto].fechaCreacion as fechaCreacion,
	[gas_detalleGasto].active as active,
	[gas_detalleGasto].[detalleGasto] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [gas_detalleGasto]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gas_detalleGasto].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gas_detalleGasto].[id_usuario_creo]
	where ' + @p_filtro)
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_doc_documento_otesXdetalleGasto]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_documento_otesXdetalleGasto]
GO
CREATE PROCEDURE [sel_doc_documento_otesXdetalleGasto]
	@p_id_gas_detalleGasto INT
AS
BEGIN
	SELECT 	[gas_documento.ot_detalleGasto].[id] AS [I_id],
		[gas_documento.ot_detalleGasto].[uid] AS [I_uid],
		[gas_documento.ot_detalleGasto].[eid] AS [I_eid],
		[gas_documento.ot_detalleGasto].[fechaModificacion] AS [I_fechaModificacion],
		[gas_documento.ot_detalleGasto].[fechaCreacion] AS [I_fechaCreacion],
		[gas_documento.ot_detalleGasto].[active] AS [I_active],
		[gas_documento.ot_detalleGasto].[documento.ot_detalleGasto] AS [I_documento.ot_detalleGasto]
	FROM gas_documento.ot_detalleGasto INNER JOIN doc_documento.ot
	 ON [gas_documento.ot_detalleGasto].[id_documento.ot] = [doc_documento.ot].id
	WHERE	([gas_documento.ot_detalleGasto].[id_detalleGasto]= @p_id_gas_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].[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,
		@p_id_documento_gasto 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],
			[id_documento.gasto])
		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,
			@p_id_documento_gasto)
		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].[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,
		@p_id_documento_gasto 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]),
			[id_documento.gasto] = isnull(@p_id_documento_gasto,[id_documento.gasto])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'gas_detalleGasto'
-----------------------------------13/07/2020 10:11:08