Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
8| Name | Data Type | Length | Description |
|---|---|---|---|
| @accion | varchar | 30 | |
| @p_gestion | int | 4 | |
| @p_cliente | int | 4 | |
| @p_contraparte | int | 4 | |
| @p_desde | date | 3 | |
| @p_hasta | date | 3 | |
| @p_vigente | tinyint | 1 | |
| @p_user_id | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
/*
exec LN_gestiones_ 'insert',null,null,7,'2018-05-15','2019-05-14',null,1063064806
*/
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_gestiones_
-- Add the parameters for the stored procedure here
@accion varchar(30),
@p_gestion int OUTPUT,
@p_cliente int,
@p_contraparte int,
@p_desde date,
@p_hasta date,
@p_vigente tinyint,
@p_user_id int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @gestion int = 0
DECLARE @cliente int = 0
DECLARE @vigente tinyint
DECLARE @log varchar(1000)
-- Insert statements for procedure here
if (@accion = 'insert' or @accion = 'insert_desde_otro_sp') begin
/* la accion insert devuelve un int con el id de gestión generada o 0 si no la genera por
superposición de vigencias o contraparte/cliente no existente */
if (@p_contraparte > 0 and @p_desde is not null and @p_hasta is not null) begin
if not exists ( select gestion from LN_gestiones
where contraparte = @p_contraparte
and (desde between @p_desde AND @p_hasta OR
hasta between @p_desde AND @p_hasta OR
(desde < @p_desde and hasta > @p_hasta) OR
(desde > @p_desde and hasta < @p_hasta)) ) begin
SELECT @cliente = cliente FROM LN_contrapartes WHERE contraparte = @p_contraparte
if (@cliente > 0) begin
if (@p_desde < GETDATE() AND @p_hasta > GETDATE())
SET @vigente = 1
else
SET @vigente = 0
INSERT INTO LN_gestiones
(cliente, contraparte, desde, hasta, vigente, created, created_by)
VALUES
(@cliente, @p_contraparte, @p_desde, @p_hasta, @vigente, GETDATE(), @p_user_id)
SET @gestion = SCOPE_IDENTITY()
end
end
SELECT @p_gestion = @gestion
if (@accion = 'insert') SELECT @gestion AS gestion
end
end else
if (@accion = 'update') begin
if not exists ( select gestion from LN_gestiones
where contraparte = @p_contraparte
and (desde between @p_desde AND @p_hasta OR
hasta between @p_desde AND @p_hasta OR
(desde < @p_desde and hasta > @p_hasta) OR
(desde > @p_desde and hasta < @p_hasta))
and gestion <> @p_gestion ) begin
if (@p_desde < GETDATE() AND @p_hasta > GETDATE())
SET @vigente = 1
else
SET @vigente = 0
UPDATE LN_gestiones SET
desde = @p_desde,
hasta = @p_hasta,
vigente = @vigente
WHERE gestion = @p_gestion
end
end else
if (@accion = 'delete') begin
DELETE FROM LN_gestiones
WHERE gestion = @p_gestion
end else
if (@accion = 'select') begin
SELECT LN_gestiones.gestion, LN_gestiones.cliente, LN_gestiones.contraparte,
CONVERT(VARCHAR, LN_gestiones.desde, 103) AS desde,
CONVERT(VARCHAR, LN_gestiones.hasta, 103) AS hasta,
LN_gestiones.vigente,
clientes.nombre_cliente, padrones.identificador, identificadores.abreviatura,
padrones.numero, padrones.identificacion, padrones.nombre_persona,
country.country_name
FROM LN_gestiones
INNER JOIN clientes ON LN_gestiones.cliente = clientes.cliente
INNER JOIN LN_contrapartes ON LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
WHERE LN_gestiones.gestion = @p_gestion
ORDER BY padrones.nombre_persona, LN_gestiones.desde
end else
if (@accion = 'verificar_gestion_activa') begin
/*
select contraparte, gestion, desde, hasta,
convert(varchar,desde,103) as fecha_desde,
convert(varchar,hasta,103) as fecha_hasta
from LN_gestiones
where contraparte = @p_contraparte
and desde <= GETDATE()
and hasta >= GETDATE()
*/
select LN_gestiones.contraparte, LN_gestiones.gestion, desde, hasta,
convert(varchar,desde,103) as fecha_desde,
convert(varchar,hasta,103) as fecha_hasta,ln_demo.informe,informes.estado_informe
from LN_gestiones left join ln_demo on ln_gestiones.gestion = ln_demo.gestion
left join informes on ln_demo.informe = informes.informe
where LN_gestiones.contraparte = @p_contraparte
and desde <= GETDATE()
and hasta >= GETDATE()
end else
if (@accion = 'upload_inquiro_vitae') begin
-- Se hizo el upload en backend del informe de inquiro vitae
select @cliente = LN_contrapartes.cliente,
@log = 'Se subió en backend el informe Inquiro Vitae del candidato '
+ padrones.nombre_persona + ' (' + identificadores.abreviatura
+ ' ' + padrones.identificacion + ')'
from LN_contrapartes inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
where LN_contrapartes.contraparte = @p_contraparte
UPDATE LN_gestiones SET iv_informe = 1 WHERE contraparte = @p_contraparte AND gestion = @p_gestion
--- Trazabilidad
INSERT INTO trazabilidad
(texto, cliente, accion, id_plataforma, contraparte, user_id, created)
VALUES
(@log, @cliente, 'UPLOAD_INFORME_INQUIRO_VITAE', 'INQUIRO', @p_contraparte, @p_user_id, GETDATE())
end else
if (@accion = 'delete_inquiro_vitae') begin
-- Se eliminó en backend el informe de inquiro vitae
select @cliente = LN_contrapartes.cliente,
@log = 'Se eliminó en backend el informe Inquiro Vitae del candidato '
+ padrones.nombre_persona + ' (' + identificadores.abreviatura
+ ' ' + padrones.identificacion + ')'
from LN_contrapartes inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
where LN_contrapartes.contraparte = @p_contraparte
UPDATE LN_gestiones SET iv_informe = 0 WHERE contraparte = @p_contraparte AND gestion = @p_gestion
--- Trazabilidad
INSERT INTO trazabilidad
(texto, cliente, accion, id_plataforma, contraparte, user_id, created)
VALUES
(@log, @cliente, 'DELETE_INFORME_INQUIRO_VITAE', 'INQUIRO', @p_contraparte, @p_user_id, GETDATE())
end else
begin
/* Search */
IF (@p_cliente > 0 AND @p_contraparte IS NULL)
SELECT LN_gestiones.gestion, LN_gestiones.cliente, LN_gestiones.contraparte,
CONVERT(VARCHAR, LN_gestiones.desde, 103) AS desde,
CONVERT(VARCHAR, LN_gestiones.hasta, 103) AS hasta,
LN_gestiones.vigente,
clientes.nombre_cliente, padrones.identificador, identificadores.abreviatura,
padrones.numero, padrones.identificacion, padrones.nombre_persona,
country.country_name
FROM LN_gestiones
INNER JOIN clientes ON LN_gestiones.cliente = clientes.cliente
INNER JOIN LN_contrapartes ON LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
WHERE LN_gestiones.cliente = @p_cliente
AND LN_gestiones.vigente = @p_vigente
ORDER BY padrones.nombre_persona, LN_gestiones.desde
ELSE
IF (@p_contraparte > 0)
SELECT LN_gestiones.gestion, LN_gestiones.cliente, LN_gestiones.contraparte,
CONVERT(VARCHAR, LN_gestiones.desde, 103) AS desde,
CONVERT(VARCHAR, LN_gestiones.hasta, 103) AS hasta,
LN_gestiones.vigente,
clientes.nombre_cliente, padrones.identificador, identificadores.abreviatura,
padrones.numero, padrones.identificacion, padrones.nombre_persona,
country.country_name
FROM LN_gestiones
INNER JOIN clientes ON LN_gestiones.cliente = clientes.cliente
INNER JOIN LN_contrapartes ON LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
WHERE LN_gestiones.contraparte = @p_contraparte
AND LN_gestiones.vigente = @p_vigente
ORDER BY padrones.nombre_persona, LN_gestiones.desde
end
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
/*
exec LN_gestiones_ 'insert',null,null,7,'2018-05-15','2019-05-14',null,1063064806
*/
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_gestiones_
-- Add the parameters for the stored procedure here
@accion varchar(30),
@p_gestion int OUTPUT,
@p_cliente int,
@p_contraparte int,
@p_desde date,
@p_hasta date,
@p_vigente tinyint,
@p_user_id int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @gestion int = 0
DECLARE @cliente int = 0
DECLARE @vigente tinyint
DECLARE @log varchar(1000)
-- Insert statements for procedure here
if (@accion = 'insert' or @accion = 'insert_desde_otro_sp') begin
/* la accion insert devuelve un int con el id de gestión generada o 0 si no la genera por
superposición de vigencias o contraparte/cliente no existente */
if (@p_contraparte > 0 and @p_desde is not null and @p_hasta is not null) begin
if not exists ( select gestion from LN_gestiones
where contraparte = @p_contraparte
and (desde between @p_desde AND @p_hasta OR
hasta between @p_desde AND @p_hasta OR
(desde < @p_desde and hasta > @p_hasta) OR
(desde > @p_desde and hasta < @p_hasta)) ) begin
SELECT @cliente = cliente FROM LN_contrapartes WHERE contraparte = @p_contraparte
if (@cliente > 0) begin
if (@p_desde < GETDATE() AND @p_hasta > GETDATE())
SET @vigente = 1
else
SET @vigente = 0
INSERT INTO LN_gestiones
(cliente, contraparte, desde, hasta, vigente, created, created_by)
VALUES
(@cliente, @p_contraparte, @p_desde, @p_hasta, @vigente, GETDATE(), @p_user_id)
SET @gestion = SCOPE_IDENTITY()
end
end
SELECT @p_gestion = @gestion
if (@accion = 'insert') SELECT @gestion AS gestion
end
end else
if (@accion = 'update') begin
if not exists ( select gestion from LN_gestiones
where contraparte = @p_contraparte
and (desde between @p_desde AND @p_hasta OR
hasta between @p_desde AND @p_hasta OR
(desde < @p_desde and hasta > @p_hasta) OR
(desde > @p_desde and hasta < @p_hasta))
and gestion <> @p_gestion ) begin
if (@p_desde < GETDATE() AND @p_hasta > GETDATE())
SET @vigente = 1
else
SET @vigente = 0
UPDATE LN_gestiones SET
desde = @p_desde,
hasta = @p_hasta,
vigente = @vigente
WHERE gestion = @p_gestion
end
end else
if (@accion = 'delete') begin
DELETE FROM LN_gestiones
WHERE gestion = @p_gestion
end else
if (@accion = 'select') begin
SELECT LN_gestiones.gestion, LN_gestiones.cliente, LN_gestiones.contraparte,
CONVERT(VARCHAR, LN_gestiones.desde, 103) AS desde,
CONVERT(VARCHAR, LN_gestiones.hasta, 103) AS hasta,
LN_gestiones.vigente,
clientes.nombre_cliente, padrones.identificador, identificadores.abreviatura,
padrones.numero, padrones.identificacion, padrones.nombre_persona,
country.country_name
FROM LN_gestiones
INNER JOIN clientes ON LN_gestiones.cliente = clientes.cliente
INNER JOIN LN_contrapartes ON LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
WHERE LN_gestiones.gestion = @p_gestion
ORDER BY padrones.nombre_persona, LN_gestiones.desde
end else
if (@accion = 'verificar_gestion_activa') begin
/*
select contraparte, gestion, desde, hasta,
convert(varchar,desde,103) as fecha_desde,
convert(varchar,hasta,103) as fecha_hasta
from LN_gestiones
where contraparte = @p_contraparte
and desde <= GETDATE()
and hasta >= GETDATE()
*/
select LN_gestiones.contraparte, LN_gestiones.gestion, desde, hasta,
convert(varchar,desde,103) as fecha_desde,
convert(varchar,hasta,103) as fecha_hasta,ln_demo.informe,informes.estado_informe
from LN_gestiones left join ln_demo on ln_gestiones.gestion = ln_demo.gestion
left join informes on ln_demo.informe = informes.informe
where LN_gestiones.contraparte = @p_contraparte
and desde <= GETDATE()
and hasta >= GETDATE()
end else
if (@accion = 'upload_inquiro_vitae') begin
-- Se hizo el upload en backend del informe de inquiro vitae
select @cliente = LN_contrapartes.cliente,
@log = 'Se subió en backend el informe Inquiro Vitae del candidato '
+ padrones.nombre_persona + ' (' + identificadores.abreviatura
+ ' ' + padrones.identificacion + ')'
from LN_contrapartes inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
where LN_contrapartes.contraparte = @p_contraparte
UPDATE LN_gestiones SET iv_informe = 1 WHERE contraparte = @p_contraparte AND gestion = @p_gestion
--- Trazabilidad
INSERT INTO trazabilidad
(texto, cliente, accion, id_plataforma, contraparte, user_id, created)
VALUES
(@log, @cliente, 'UPLOAD_INFORME_INQUIRO_VITAE', 'INQUIRO', @p_contraparte, @p_user_id, GETDATE())
end else
if (@accion = 'delete_inquiro_vitae') begin
-- Se eliminó en backend el informe de inquiro vitae
select @cliente = LN_contrapartes.cliente,
@log = 'Se eliminó en backend el informe Inquiro Vitae del candidato '
+ padrones.nombre_persona + ' (' + identificadores.abreviatura
+ ' ' + padrones.identificacion + ')'
from LN_contrapartes inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
where LN_contrapartes.contraparte = @p_contraparte
UPDATE LN_gestiones SET iv_informe = 0 WHERE contraparte = @p_contraparte AND gestion = @p_gestion
--- Trazabilidad
INSERT INTO trazabilidad
(texto, cliente, accion, id_plataforma, contraparte, user_id, created)
VALUES
(@log, @cliente, 'DELETE_INFORME_INQUIRO_VITAE', 'INQUIRO', @p_contraparte, @p_user_id, GETDATE())
end else
begin
/* Search */
IF (@p_cliente > 0 AND @p_contraparte IS NULL)
SELECT LN_gestiones.gestion, LN_gestiones.cliente, LN_gestiones.contraparte,
CONVERT(VARCHAR, LN_gestiones.desde, 103) AS desde,
CONVERT(VARCHAR, LN_gestiones.hasta, 103) AS hasta,
LN_gestiones.vigente,
clientes.nombre_cliente, padrones.identificador, identificadores.abreviatura,
padrones.numero, padrones.identificacion, padrones.nombre_persona,
country.country_name
FROM LN_gestiones
INNER JOIN clientes ON LN_gestiones.cliente = clientes.cliente
INNER JOIN LN_contrapartes ON LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
WHERE LN_gestiones.cliente = @p_cliente
AND LN_gestiones.vigente = @p_vigente
ORDER BY padrones.nombre_persona, LN_gestiones.desde
ELSE
IF (@p_contraparte > 0)
SELECT LN_gestiones.gestion, LN_gestiones.cliente, LN_gestiones.contraparte,
CONVERT(VARCHAR, LN_gestiones.desde, 103) AS desde,
CONVERT(VARCHAR, LN_gestiones.hasta, 103) AS hasta,
LN_gestiones.vigente,
clientes.nombre_cliente, padrones.identificador, identificadores.abreviatura,
padrones.numero, padrones.identificacion, padrones.nombre_persona,
country.country_name
FROM LN_gestiones
INNER JOIN clientes ON LN_gestiones.cliente = clientes.cliente
INNER JOIN LN_contrapartes ON LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
WHERE LN_gestiones.contraparte = @p_contraparte
AND LN_gestiones.vigente = @p_vigente
ORDER BY padrones.nombre_persona, LN_gestiones.desde
end
END
GO