

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_seg_cargo_actividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_seg_cargo_actividad]
GO
CREATE PROCEDURE [reg_seg_cargo_actividad]
	@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],
		[cargo_actividad] AS [cargo_actividad],
		[id_cargo] AS [id_cargo],
		[id_catalogo.actividad] AS [id_catalogo.actividad]
	FROM [seg_cargo_actividad]
	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_seg_cargo_actividad]')) DROP VIEW [dbo].[view_seg_cargo_actividad]
GO
CREATE  VIEW [view_seg_cargo_actividad] AS
SELECT 	[seg_cargo_actividad].[id] AS [id],
		[seg_cargo_actividad].[uid] AS [uid],
		[seg_cargo_actividad].[eid] AS [eid],
		[seg_cargo_actividad].[id_usuario_modifico] AS [id_usuario_modifico],
		[seg_cargo_actividad].[id_usuario_creo] AS [id_usuario_creo],
		[seg_cargo_actividad].[fechaModificacion] AS [fechaModificacion],
		[seg_cargo_actividad].[fechaCreacion] AS [fechaCreacion],
		[seg_cargo_actividad].[active] AS [active],
		[seg_cargo_actividad].[cargo_actividad] AS [cargo_actividad],
		[seg_cargo_actividad].[id_cargo] AS [id_cargo],
[seg_cargo].[cargo] as [seg_cargo_cargo],
[seg_cargo].[cargo_codigo] as [seg_cargo_cargo_codigo],
[seg_cargo].[esTecnico] as [seg_cargo_esTecnico],
[seg_cargo].[esComercial] as [seg_cargo_esComercial],
[seg_cargo].[esCoordinador] as [seg_cargo_esCoordinador],
[seg_cargo].[valorHora] as [seg_cargo_valorHora],
[seg_cargo].[esAdministrativo] as [seg_cargo_esAdministrativo],
		[seg_cargo_actividad].[id_catalogo.actividad] AS [id_catalogo.actividad],
[cat_catalogo.actividad].[catalogo.actividad] as [cat_catalogo.actividad_catalogo.actividad],
[cat_catalogo.actividad].[esProductiva] as [cat_catalogo.actividad_esProductiva],
[cat_catalogo.actividad].[duracionEstimada] as [cat_catalogo.actividad_duracionEstimada],
[cat_catalogo.actividad].[procedimiento] as [cat_catalogo.actividad_procedimiento],
		[cat_catalogo_actividad].[catalogo_codigo] AS [cat_catalogo_actividad_catalogo_codigo],
		[cat_catalogo_actividad].[codigoInventario] AS [cat_catalogo_actividad_codigoInventario],
		[cat_catalogo_actividad].[precioVenta] AS [cat_catalogo_actividad_precioVenta],
		[cat_catalogo_actividad].[tiempoConsecucion] AS [cat_catalogo_actividad_tiempoConsecucion],
		[cat_catalogo_actividad].[esNacional] AS [cat_catalogo_actividad_esNacional],
		[cat_catalogo_actividad].[id_familia] AS [cat_catalogo_actividad_id_familia],
		[cat_catalogo_actividad].[id_subTipoCatalogo] AS [cat_catalogo_actividad_id_subTipoCatalogo],
		[cat_catalogo_actividad].[id_unidad] AS [cat_catalogo_actividad_id_unidad],
		[cat_catalogo_actividad].[id_impuesto] AS [cat_catalogo_actividad_id_impuesto],
		[cat_catalogo_actividad].[descripcion] AS [cat_catalogo_actividad_descripcion],
		[cat_catalogo_actividad].[bloquearCostear] AS [cat_catalogo_actividad_bloquearCostear],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [seg_cargo_actividad]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[seg_cargo_actividad].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[seg_cargo_actividad].[id_usuario_creo]
	INNER JOIN [seg_cargo] ON [seg_cargo].id=[seg_cargo_actividad].[id_cargo]
	INNER JOIN [cat_catalogo.actividad] ON [cat_catalogo.actividad].id=[seg_cargo_actividad].[id_catalogo.actividad]
	INNER JOIN [cat_catalogo] aS [cat_catalogo_actividad] ON [cat_catalogo.actividad].id = [cat_catalogo_actividad].id
	INNER JOIN [gen_empresa] AS empresaCodigo ON [seg_cargo_actividad].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_seg_cargo_actividadesXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXusuario_modifico]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_cargo_actividad]
	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_seg_cargo_actividadesXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXusuario_creo]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_cargo_actividad]
	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_seg_cargo_actividadesXcargo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXcargo]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXcargo]
	@p_id_cargo INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_cargo_actividad]
	WHERE ([id_cargo]= @p_id_cargo)
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_seg_cargo_actividadesXcatalogo_actividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXcatalogo_actividad]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXcatalogo_actividad]
	@p_id_catalogo_actividad INT
AS
BEGIN
	SELECT * 
	FROM [view_seg_cargo_actividad]
	WHERE ([id_catalogo.actividad]= @p_id_catalogo_actividad)
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_seg_cargo_actividades]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividades]
GO
CREATE PROCEDURE [sel_seg_cargo_actividades]
	
	@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_seg_cargo_actividad]
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_seg_cargo_actividades]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_seg_cargo_actividades]
GO
CREATE PROCEDURE [lis_seg_cargo_actividades]
	AS
BEGIN
	SELECT id AS id,
[cargo_actividad] AS [seg_cargo_actividad]
	FROM [seg_cargo_actividad]
	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_seg_cargo_actividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_seg_cargo_actividad]
GO
CREATE PROCEDURE [upd_seg_cargo_actividad]
	@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_cargo_actividad varchar(300) = null,
		@p_id_cargo int = null,
		@p_id_catalogo_actividad int = null
AS
BEGIN
		UPDATE [seg_cargo_actividad]
		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(),
			[cargo_actividad] = isnull(@p_cargo_actividad,[cargo_actividad]),
			[id_cargo] = isnull(@p_id_cargo,[id_cargo]),
			[id_catalogo.actividad] = isnull(@p_id_catalogo_actividad,[id_catalogo.actividad])
		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_seg_cargo_actividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_seg_cargo_actividad]
GO
CREATE PROCEDURE [ins_seg_cargo_actividad]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_cargo_actividad varchar(300),
		@p_id_cargo int,
		@p_id_catalogo_actividad int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [seg_cargo_actividad]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[cargo_actividad],
			[id_cargo],
			[id_catalogo.actividad])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_cargo_actividad,
			@p_id_cargo,
			@p_id_catalogo_actividad)
		SET @v_id = scope_identity()
UPDATE [seg_cargo_actividad] 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_seg_cargo_actividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_seg_cargo_actividad]
GO
CREATE PROCEDURE [act_seg_cargo_actividad]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [seg_cargo_actividad]
	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_seg_cargo_actividad_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_seg_cargo_actividad_m]
GO
CREATE PROCEDURE [reg_seg_cargo_actividad_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],
		[cargo_actividad] AS [cargo_actividad],
		[id_cargo] AS [id_cargo],
		[id_catalogo.actividad] AS [id_catalogo.actividad]
	FROM [seg_cargo_actividad]
	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_seg_cargo_actividadesXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_cargo_actividad]
	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_seg_cargo_actividadesXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXusuario_creo_m]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_cargo_actividad]
	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_seg_cargo_actividadesXcargo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXcargo_m]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXcargo_m]
	@p_id_cargo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_cargo_actividad]
	WHERE ([id_cargo]= @p_id_cargo)
	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_seg_cargo_actividadesXcatalogo_actividad_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividadesXcatalogo_actividad_m]
GO
CREATE PROCEDURE [sel_seg_cargo_actividadesXcatalogo_actividad_m]
	@p_id_catalogo_actividad INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_seg_cargo_actividad]
	WHERE ([id_catalogo.actividad]= @p_id_catalogo_actividad)
	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_seg_cargo_actividades_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_seg_cargo_actividades_m]
GO
CREATE PROCEDURE [sel_seg_cargo_actividades_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_seg_cargo_actividad]
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_seg_cargo_actividades_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_seg_cargo_actividades_m]
GO
CREATE PROCEDURE [lis_seg_cargo_actividades_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[cargo_actividad] AS [seg_cargo_actividad]
	FROM [seg_cargo_actividad]
	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_seg_cargo_actividad]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_seg_cargo_actividad]
GO
CREATE PROCEDURE [aud_seg_cargo_actividad]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [seg_cargo_actividad].id as id_tabla,
	[seg_cargo_actividad].id_usuario_modifico as id_usuario_modifico,
	[seg_cargo_actividad].id_usuario_creo as id_usuario_creo,
	[seg_cargo_actividad].fechaModificacion as fechaModificacion,
	[seg_cargo_actividad].fechaCreacion as fechaCreacion,
	[seg_cargo_actividad].active as active,
	[seg_cargo_actividad].[cargo_actividad] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [seg_cargo_actividad]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[seg_cargo_actividad].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[seg_cargo_actividad].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'seg_cargo_actividad'
-----------------------------------2/23/2017 10:47:20 AM