
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_gen_detalleRegistroEnvio]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gen_detalleRegistroEnvio]
GO
CREATE PROCEDURE [reg_gen_detalleRegistroEnvio]
	@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],
		[detalleRegistroEnvio] AS [detalleRegistroEnvio],
		[detalleRegistroEnvio_codigo] AS [detalleRegistroEnvio_codigo],
		[email] AS [email],
		[enviado] AS [enviado],
		[enviar] AS [enviar],
		[id_registroEnvio] AS [id_registroEnvio],
		[idObjeto] AS [idObjeto]
	FROM [gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnvio]')) DROP VIEW [dbo].[view_gen_detalleRegistroEnvio]
GO
CREATE  VIEW [view_gen_detalleRegistroEnvio] AS
SELECT 	[gen_detalleRegistroEnvio].[id] AS [id],
		[gen_detalleRegistroEnvio].[uid] AS [uid],
		[gen_detalleRegistroEnvio].[eid] AS [eid],
		[gen_detalleRegistroEnvio].[id_usuario_modifico] AS [id_usuario_modifico],
		[gen_detalleRegistroEnvio].[id_usuario_creo] AS [id_usuario_creo],
		[gen_detalleRegistroEnvio].[fechaModificacion] AS [fechaModificacion],
		[gen_detalleRegistroEnvio].[fechaCreacion] AS [fechaCreacion],
		[gen_detalleRegistroEnvio].[active] AS [active],
		[gen_detalleRegistroEnvio].[detalleRegistroEnvio] AS [detalleRegistroEnvio],
		[gen_detalleRegistroEnvio].[detalleRegistroEnvio_codigo] AS [detalleRegistroEnvio_codigo],
		[gen_detalleRegistroEnvio].[email] AS [email],
		[gen_detalleRegistroEnvio].[enviado] AS [enviado],
		[gen_detalleRegistroEnvio].[enviar] AS [enviar],
		[gen_detalleRegistroEnvio].[id_registroEnvio] AS [id_registroEnvio],
[gen_registroEnvio].[registroEnvio] as [gen_registroEnvio_registroEnvio],
[gen_registroEnvio].[registroEnvio_codigo] as [gen_registroEnvio_registroEnvio_codigo],
[gen_registroEnvio].[tabla] as [gen_registroEnvio_tabla],
[gen_registroEnvio].[reintentar] as [gen_registroEnvio_reintentar],
[gen_registroEnvio].[id_envioCorreo] as [gen_registroEnvio_id_envioCorreo],
[gen_registroEnvio].[id_registroEnvio] as [gen_registroEnvio_id_registroEnvio],
		[gen_detalleRegistroEnvio].[idObjeto] AS [idObjeto],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [gen_detalleRegistroEnvio]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gen_detalleRegistroEnvio].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gen_detalleRegistroEnvio].[id_usuario_creo]
	INNER JOIN [gen_registroEnvio] ON [gen_registroEnvio].id=[gen_detalleRegistroEnvio].[id_registroEnvio]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [gen_detalleRegistroEnvio].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [gen_detalleRegistroEnvio].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_gen_detalleRegistroEnviosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnviosXusuario_modifico]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnviosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnviosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnviosXusuario_creo]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnviosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnviosXregistroEnvio]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnviosXregistroEnvio]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnviosXregistroEnvio]
	@p_id_registroEnvio INT
AS
BEGIN
	SELECT * 
	FROM [view_gen_detalleRegistroEnvio]
	WHERE ([id_registroEnvio]= @p_id_registroEnvio)
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_gen_detalleRegistroEnvios]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnvios]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnvios]
	
	@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_gen_detalleRegistroEnvio]
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_gen_detalleRegistroEnvios]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gen_detalleRegistroEnvios]
GO
CREATE PROCEDURE [lis_gen_detalleRegistroEnvios]
	AS
BEGIN
	SELECT id AS id,
[detalleRegistroEnvio] AS [gen_detalleRegistroEnvio]
	FROM [gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnvio]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_gen_detalleRegistroEnvio]
GO
CREATE PROCEDURE [upd_gen_detalleRegistroEnvio]
	@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_detalleRegistroEnvio varchar(300) = null,
		@p_detalleRegistroEnvio_codigo varchar(100) = null,
		@p_email varchar(200) = null,
		@p_enviado bit = null,
		@p_enviar bit = null,
		@p_id_registroEnvio int = null,
		@p_idObjeto int = null
AS
BEGIN
		UPDATE [gen_detalleRegistroEnvio]
		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(),
			[detalleRegistroEnvio] = isnull(@p_detalleRegistroEnvio,[detalleRegistroEnvio]),
			[detalleRegistroEnvio_codigo] = isnull(@p_detalleRegistroEnvio_codigo,[detalleRegistroEnvio_codigo]),
			[email] = isnull(@p_email,[email]),
			[enviado] = isnull(@p_enviado,[enviado]),
			[enviar] = isnull(@p_enviar,[enviar]),
			[id_registroEnvio] = isnull(@p_id_registroEnvio,[id_registroEnvio]),
			[idObjeto] = isnull(@p_idObjeto,[idObjeto])
		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_gen_detalleRegistroEnvio]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_gen_detalleRegistroEnvio]
GO
CREATE PROCEDURE [ins_gen_detalleRegistroEnvio]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_detalleRegistroEnvio varchar(300),
		@p_detalleRegistroEnvio_codigo varchar(100),
		@p_email varchar(200),
		@p_enviado bit,
		@p_enviar bit,
		@p_id_registroEnvio int,
		@p_idObjeto int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [gen_detalleRegistroEnvio]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[detalleRegistroEnvio],
			[detalleRegistroEnvio_codigo],
			[email],
			[enviado],
			[enviar],
			[id_registroEnvio],
			[idObjeto])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_detalleRegistroEnvio,
			@p_detalleRegistroEnvio_codigo,
			@p_email,
			@p_enviado,
			@p_enviar,
			@p_id_registroEnvio,
			@p_idObjeto)
		SET @v_id = scope_identity()
UPDATE [gen_detalleRegistroEnvio] 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_gen_detalleRegistroEnvio]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_gen_detalleRegistroEnvio]
GO
CREATE PROCEDURE [act_gen_detalleRegistroEnvio]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnvio_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_gen_detalleRegistroEnvio_m]
GO
CREATE PROCEDURE [reg_gen_detalleRegistroEnvio_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],
		[detalleRegistroEnvio] AS [detalleRegistroEnvio],
		[detalleRegistroEnvio_codigo] AS [detalleRegistroEnvio_codigo],
		[email] AS [email],
		[enviado] AS [enviado],
		[enviar] AS [enviar],
		[id_registroEnvio] AS [id_registroEnvio],
		[idObjeto] AS [idObjeto]
	FROM [gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnviosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnviosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnviosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnviosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnviosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnviosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnviosXregistroEnvio_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnviosXregistroEnvio_m]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnviosXregistroEnvio_m]
	@p_id_registroEnvio INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_gen_detalleRegistroEnvio]
	WHERE ([id_registroEnvio]= @p_id_registroEnvio)
	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_gen_detalleRegistroEnvios_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_gen_detalleRegistroEnvios_m]
GO
CREATE PROCEDURE [sel_gen_detalleRegistroEnvios_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_gen_detalleRegistroEnvio]
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_gen_detalleRegistroEnvios_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_gen_detalleRegistroEnvios_m]
GO
CREATE PROCEDURE [lis_gen_detalleRegistroEnvios_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[detalleRegistroEnvio] AS [gen_detalleRegistroEnvio]
	FROM [gen_detalleRegistroEnvio]
	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_gen_detalleRegistroEnvio]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_gen_detalleRegistroEnvio]
GO
CREATE PROCEDURE [aud_gen_detalleRegistroEnvio]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [gen_detalleRegistroEnvio].id as id_tabla,
	[gen_detalleRegistroEnvio].id_usuario_modifico as id_usuario_modifico,
	[gen_detalleRegistroEnvio].id_usuario_creo as id_usuario_creo,
	[gen_detalleRegistroEnvio].fechaModificacion as fechaModificacion,
	[gen_detalleRegistroEnvio].fechaCreacion as fechaCreacion,
	[gen_detalleRegistroEnvio].active as active,
	[gen_detalleRegistroEnvio].[detalleRegistroEnvio] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [gen_detalleRegistroEnvio]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[gen_detalleRegistroEnvio].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[gen_detalleRegistroEnvio].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'gen_detalleRegistroEnvio'
-----------------------------------3/08/2017 4:09:18 p. m.