Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
5| Name | Data Type | Length | Description |
|---|---|---|---|
| @IDCliente | int | 4 | |
| @StepID | int | 4 | |
| @fechaProceso | date | 3 | |
| @Proceso | smallint | 2 | |
| @Tipo | varchar | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/* para buscar los empleos de los empleados:
select distinct a.cuil as cuil_empleado,
p2.nombre_persona as empleado,
a.cuit as cuit_empleador,
p.nombre_persona as empleador,
a.periodo as periodo,
a.remimp as sueldo
from empleados a
inner join padrones p on p.identificacion = a.cuit
inner join padrones p2 on p2.identificacion = a.cuil
where a.cuil in (select distinct cuil from
screening_empleados c where c.cliente = 1659303046 and c.tipo_reg = 'EMP')
and a.periodo = (select max(periodo) from empleados b
where b.cuit = a.cuit and b.cuil = a.cuil
and periodo >= '1801')
*/
CREATE OR ALTER PROCEDURE dbo.screening_empleados_ok
@IDCliente int,
@StepID int,
@fechaProceso date,
@Proceso smallint,
@Tipo varchar(3)
AS
/*
Paso 1: Busca PARTICIPACIONES de los empleados en sociedades en las tablas sociedades_constituciones,relaciones y edictos, que el cuit del edicto sea el del empleado
Paso 2: trabajo con los familiares de empleados
Paso 55: los proveedores que no pudieron aperturarse (no siempre es necesario correr este paso)
exec screening_empleados_ok 1659303046,1,null,1,'EMP'
exec screening_empleados_ok 1659303046,2,null,1,'FAM'
*/
BEGIN
if(@StepID=55) /*INSERTO TODOS LOS EMPLEADOS QUE NO PUDIERON APERTURARSE COMO N/A PARA GARANTIZAR QUE TODOS HAYAN SIDO ANALIZADOS*/
BEGIN
insert into screening_empleados_out (cliente,razon_social,cuit,titulo,cargo,tipo_reg,nro_proceso)
select @IDCliente as cliente,nombre_empleado as razon_social_prov,cuil as cuit_prov,'N/A' as titulo,'N/A' as cargo,'N/A' as tipo_reg,@Proceso as nro_proceso
from screening_EMPLEADOS where cliente = @IDCliente and nro_proceso = @Proceso AND tipo_reg= @Tipo
AND CUIL NOT IN (select distinct cuit from screening_empleados_out where Cliente = @IDCliente and nro_proceso = @Proceso AND tipo_reg not like '%_F%')
END
if(@StepID=0)
BEGIN
/* REGISTROS DE VINVULADOS POR AFIP DE FAMILIARES DE EMPLEADOS */
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
SELECT 'VENDORID' AS vendorid,
'ACCIONISTAS FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,
screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,
screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg = 'EDICTO_F')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
UNION ALL
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE VINVULADOS POR AFIP DE FAMILIARES DE EMPLEADOS */
SELECT 'VENDORID' AS vendorid,
'VINCULACIONES AFIP FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg = 'AFIP_F')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
UNION ALL
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE ACCIONISTAS DE FAMILIARES DE EMPLEADOS */
SELECT 'VENDORID' AS vendorid,
'ACCIONISTAS FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg = 'ACCIONIS_F')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
UNION ALL
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE PARTICIPACIONES SOCIETARIAS DE FAMILIARES DE EMPLEADOS */
SELECT 'VENDORID' AS vendorid,
'VINCULACIONES SOCIETARIAS FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg in ('SOCCONS1_F','DIREC_F') )
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
union all
/* REGISTROS DE EMPLEADOS SIN DATOS DE APERTURA*/
SELECT 'VENDORID' AS vendorid,
'N/A' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,
screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,
screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg = 'N/A')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
and not exists (select * from screening_empleados_out b where b.cliente = @IDCliente and b.nro_proceso = @Proceso and b.cuit = screening_empleados_out.cuit and b.tipo_reg != 'N/A' and b.tipo_reg not like '%_F')
union all
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE EMPLEADOS VINCULADOS A EMPRESAS POR AFIP*/
SELECT 'VENDORID' AS vendorid,
'VINCULACIONES SOCIETARIAS' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg in ('SOC_CONS_1','DIRECTOR'))
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
union all
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE EMPLEADOS VINCULADOS A EMPRESAS POR AFIP*/
SELECT 'VENDORID' AS vendorid,
'AFIP' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg = 'AFIP')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
union all
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE EMPLEADOS ACCIONISTAS DE EMPRESAS */
SELECT 'VENDORID' AS vendorid,
'ACCIONISTA' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg = 'ACCIONISTA' )
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
order by LEGALNAME,LINKEDPERSONORENTITY,PERSON_TYPE
END
if (@StepID=1)
begin
--------------------------------------------------------------------------------------------------------------------
/* Paso 1: Busca PARTICIPACIONES de los empleados en sociedades en las tablas sociedades_constituciones,relaciones y edictos, que el cuit del edicto sea el del empleado : */
--------------------------------------------------------------------------------------------------------------------
insert into screening_empleados_out (razon_social,cuit,cliente,created,titulo,cargo,soc_vinculada,cuit_soc_vinculada,
nombre_integrante,cuit_integrante,nombre_familiar,cuit_familiar,contenido_archivo,fecha_publicacion,tipo_reg,nro_proceso)
select DISTINCT screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo,'ACCIONISTA' AS cargo,
/*
p1.nombre_persona as soc_vinculada,p1.identificacion as soc_vinculada,
*/
iif(substring(accionistas.cuit_acc,1,1)='2',p2.nombre_persona,null) as soc_vinculada,
iif(substring(accionistas.cuit_acc,1,1)='2',p2.identificacion,null) as cuit_soc_vinculada,
/*
P2.nombre_persona AS nombre_integrante,accionistas.cuit_acc as cuit_integrante,
*/
iif(substring(accionistas.cuit_acc,1,1)='3',p2.nombre_persona,null) as nombre_integrante,
iif(substring(accionistas.cuit_acc,1,1)='3',accionistas.cuit_acc,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null AS contenido_archivo,getdate() AS fecha_publicacion,
tipo_reg = 'ACCIONISTA',@Proceso AS nro_proceso
from screening_empleados
inner join accionistas on screening_empleados.cuil = accionistas.cuit_acc
inner join padrones p1 on accionistas.cuit_acc = p1.identificacion
left join padrones p2 on accionistas.cuit_sociedad = p2.identificacion
where accionistas.cuit_acc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso and screening_empleados.tipo_reg = @Tipo)
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
UNION ALL
select DISTINCT screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo,
cargos.car_nombre AS cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
null as nombre_integrante,
null as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null AS contenido_archivo,getdate() AS fecha_publicacion,
tipo_reg = 'DIRECTOR',
@Proceso AS nro_proceso
from screening_empleados
inner join socios on ltrim(rtrim(screening_empleados.cuil)) = socios.c01_cuit_soc and socios.visible = 1 and isnull(c01_cuit,'') != ''
inner join cargos on cargos.car_codigo = socios.car_codigo
left join padrones p2 on socios.c01_cuit = p2.identificacion
where socios.c01_cuit_soc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso and screening_empleados.tipo_reg = @Tipo)
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
UNION ALL
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES EDICTOS COMO EMPRESAS */
select screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuit_prov,screening_empleados.cliente,getdate() as created,
NULL as titulo, NULL as cargo,
iif(substring(edictos.cuit_integrante,1,1)='3',padrones.nombre_persona,null) as soc_vinculada,
iif(substring(edictos.cuit_integrante,1,1)='3',edictos.cuit_integrante,null) as cuit_soc_vinculada,
iif(substring(edictos.cuit_integrante,1,1)='2',padrones.nombre_persona,null) as nombre_integrante,
iif(substring(edictos.cuit_integrante,1,1)='2',edictos.cuit_integrante,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
edictos.texto as contenido_archivo,edictos.fecha_boletin as fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join edictos on screening_empleados.cuil = edictos.cuit_sociedad
left join padrones on edictos.cuit_integrante = padrones.identificacion
left join padrones p2 on EDICTOS.cuit_sociedad = p2.identificacion
and cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
UNION ALL
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES EDICTOS PERSONAS */
select screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuit_prov,screening_empleados.cliente,getdate() as created,
NULL as titulo, NULL as cargo,
iif(substring(edictos.cuit_sociedad,1,1)='3',P2.nombre_persona,null) as soc_vinculada,
iif(substring(edictos.cuit_sociedad,1,1)='3',edictos.cuit_sociedad,null) as cuit_soc_vinculada,
iif(substring(edictos.cuit_integrante,1,1)='2',null,'a') as nombre_integrante,
iif(substring(edictos.cuit_integrante,1,1)='2',null,'a') as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
edictos.texto as contenido_archivo,edictos.fecha_boletin as fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join edictos on screening_empleados.cuil = edictos.cuit_integrante
inner join padrones on edictos.cuit_integrante = padrones.identificacion
left join padrones p2 on EDICTOS.cuit_sociedad = p2.identificacion
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES CONSTITUCIONES COMO PERSONAS*/
select screening_empleados.nombre_empleado AS empleado ,screening_empleados.cuil AS cuil,
screening_empleados.cliente,
getdate() as created,
sociedades_constituciones.titulo, sociedades_constituciones.cargo,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.razon_social,null) as soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.documento_soc,null) as cuit_soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.nombre_integrante,null) as nombre_integrante,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.cuit_int,null) AS cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
sociedades_constituciones.contenido_archivo,sociedades_constituciones.fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join sociedades_constituciones on (screening_empleados.cuil = sociedades_constituciones.cuit_integrante)
left join padrones p2 on sociedades_constituciones.documento_soc = p2.identificacion
where screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
/*
and sociedades_constituciones.nombre_integrante <> '' and sociedades_constituciones.nombre_integrante is not null
*/
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES CONSTITUCIONES COMO PERSONAS*/
select screening_empleados.nombre_empleado AS empleado ,screening_empleados.cuil AS cuil,
screening_empleados.cliente,
getdate() as created,
sociedades_constituciones.titulo, sociedades_constituciones.cargo,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.razon_social,null) as soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.documento_soc,null) as cuit_soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.nombre_integrante,null) as nombre_integrante,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.cuit_int,null) AS cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
sociedades_constituciones.contenido_archivo,sociedades_constituciones.fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join sociedades_constituciones on (screening_empleados.cuil = sociedades_constituciones.cuit_int)
left join padrones p2 on sociedades_constituciones.documento_soc = p2.identificacion
where screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
/*
and sociedades_constituciones.nombre_integrante <> '' and sociedades_constituciones.nombre_integrante is not null
*/
union all
select p2.nombre_persona as empleado,p2.identificacion AS cuil,
screening_empleados.cliente,
getdate() as created,
tp1.relacion as titulo, tsp1.subrelacion as cargo,
iif(substring(p3.identificacion,1,1)='3',p3.nombre_persona,null) as soc_vinculada,
iif(substring(p3.identificacion,1,1)='3',p3.identificacion,null) as cuit_soc_vinculada,
iif(substring(p3.identificacion,1,1)='2',p3.nombre_persona,null) as nombre_integrante,
iif(substring(p3.identificacion,1,1)='2',p3.identificacion,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null as contenido_archivo,relaciones.fecha_relacion,'AFIP' as tipo_reg /*SOC_CONS_1*/,@Proceso AS nro_proceso
from screening_empleados
inner join relaciones on screening_empleados.cuil = relaciones.cuita
inner join padrones p3 on relaciones.cuita = p3.identificacion
inner join padrones p2 on relaciones.cuitb = p2.identificacion
inner join tipos_relaciones tp1 on tp1.id_tipo_relacion = relaciones.id_tipo_relacion
inner join tipos_subrelaciones tsp1 on tsp1.id_subrelacion = relaciones.id_tipo_subrelacion
where cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
and relaciones.id_tipo_relacion in (1,2)
union all
/*buscamos sobre la tabla relaciones como personas */
select p2.nombre_persona as empleado,p2.identificacion AS cuil,
screening_empleados.cliente,
getdate() as created,
tp1.relacion as titulo, tsp1.subrelacion as cargo,
iif(substring(p3.identificacion,1,1)='3',p3.nombre_persona,null) as soc_vinculada,
iif(substring(p3.identificacion,1,1)='3',p3.identificacion,null) as cuit_soc_vinculada,
iif(substring(p3.identificacion,1,1)='2',p3.nombre_persona,null) as nombre_integrante,
iif(substring(p3.identificacion,1,1)='2',p3.identificacion,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null as contenido_archivo,relaciones.fecha_relacion,'AFIP' as tipo_reg /*SOC_CONS_1*/,@Proceso AS nro_proceso
from screening_empleados
inner join relaciones on screening_empleados.cuil = relaciones.cuitb
inner join padrones p3 on relaciones.cuita = p3.identificacion
inner join padrones p2 on relaciones.cuitb = p2.identificacion
inner join tipos_relaciones tp1 on tp1.id_tipo_relacion = relaciones.id_tipo_relacion
inner join tipos_subrelaciones tsp1 on tsp1.id_subrelacion = relaciones.id_tipo_subrelacion
where cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
and relaciones.id_tipo_relacion in (1,2)
order by empleado
end
if (@StepID=2) /* trabajo con los familiares de empleados*/
begin
insert into screening_empleados_out (razon_social,cuit,cliente,created,titulo,cargo,soc_vinculada,cuit_soc_vinculada,
nombre_integrante,cuit_integrante,nombre_familiar,cuit_familiar,contenido_archivo,fecha_publicacion,tipo_reg,nro_proceso)
/* relaciones */
select
ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente,
getdate() as created,
tp1.relacion as titulo, tsp1.subrelacion as cargo,
iif(substring(p3.identificacion,1,1)='3',p3.nombre_persona,null) as soc_vinculada,
iif(substring(p3.identificacion,1,1)='3',p3.identificacion,null) as cuit_soc_vinculada,
p2.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
p2.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
null as contenido_archivo,relaciones.fecha_relacion,'AFIP_F' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join relaciones on screening_empleados.cuil = relaciones.cuitb
inner join padrones p3 on relaciones.cuita = p3.identificacion
inner join padrones p2 on screening_empleados.cuil = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
inner join tipos_relaciones tp1 on tp1.id_tipo_relacion = relaciones.id_tipo_relacion
inner join tipos_subrelaciones tsp1 on tsp1.id_subrelacion = relaciones.id_tipo_subrelacion
where cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where nro_proceso = @Proceso and tipo_reg = 'EMP')
/*
and relaciones.id_tipo_relacion in (1,2)
*/
union all
/* accionistas */
select DISTINCT
ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo,'ACCIONISTA' AS cargo,
iif(substring(accionistas.cuit_acc,1,1)='2',p2.nombre_persona,null) as soc_vinculada,
iif(substring(accionistas.cuit_acc,1,1)='2',p2.identificacion,null) as cuit_soc_vinculada,
p1.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
p1.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
null as contenido_archivo,null as fecha_relacion,
tipo_reg = 'ACCIONIS_F',@Proceso AS nro_proceso
from screening_empleados
inner join accionistas on screening_empleados.cuil = accionistas.cuit_acc
inner join padrones p1 on accionistas.cuit_acc = p1.identificacion
inner join padrones p2 on accionistas.cuit_sociedad = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
where accionistas.cuit_acc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = 'FAM')
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where nro_proceso = @Proceso and tipo_reg = 'EMP')
union all
select DISTINCT
ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo, cargos.car_nombre AS cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
p1.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
p1.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
null as contenido_archivo,null as fecha_relacion,
tipo_reg = 'DIREC_F',
@Proceso AS nro_proceso
from screening_empleados
inner join socios on ltrim(rtrim(screening_empleados.cuil)) = socios.c01_cuit_soc and socios.visible = 1 and isnull(c01_cuit,'') != ''
inner join cargos on cargos.car_codigo = socios.car_codigo
inner join padrones p1 on socios.c01_cuit_soc = p1.identificacion and p1.habilitado = 1
inner join padrones p2 on socios.c01_cuit = p2.identificacion and p2.habilitado = 1
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
where socios.c01_cuit_soc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = 'FAM')
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where nro_proceso = @Proceso and tipo_reg = 'EMP')
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES CONSTITUCIONES COMO PERSONAS*/
select ptit.nombre_persona as empleado,ptit.identificacion as cuil,
/*
screening_empleados.nombre_empleado AS empleado ,screening_empleados.cuil AS cuil,
*/
screening_empleados.cliente,
getdate() as created,
sociedades_constituciones.titulo, sociedades_constituciones.cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
padrones.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
padrones.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
sociedades_constituciones.contenido_archivo,sociedades_constituciones.fecha_publicacion,
'SOCCONS1_F' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join sociedades_constituciones on (screening_empleados.cuil = sociedades_constituciones.cuit_int)
inner join padrones on screening_empleados.cuil = padrones.identificacion
left join padrones p2 on sociedades_constituciones.documento_soc = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
where screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where cliente = @IDCliente and nro_proceso = @Proceso and tipo_reg = 'EMP')
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES EDICTOS PARA FAMILIARES */
select ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente,getdate() as created,
NULL as titulo, null as cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
padrones.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
padrones.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
edictos.texto as contenido_archivo,edictos.fecha_boletin as fecha_publicacion
,'EDICTO_F' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join edictos on screening_empleados.cuil = edictos.cuit_integrante
left join padrones on edictos.cuit_integrante = padrones.identificacion
left join padrones p2 on EDICTOS.cuit_sociedad = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
and cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where cliente = @IDCliente and nro_proceso = @Proceso and tipo_reg = 'EMP')
end
END
GO
GO
/* para buscar los empleos de los empleados:
select distinct a.cuil as cuil_empleado,
p2.nombre_persona as empleado,
a.cuit as cuit_empleador,
p.nombre_persona as empleador,
a.periodo as periodo,
a.remimp as sueldo
from empleados a
inner join padrones p on p.identificacion = a.cuit
inner join padrones p2 on p2.identificacion = a.cuil
where a.cuil in (select distinct cuil from
screening_empleados c where c.cliente = 1659303046 and c.tipo_reg = 'EMP')
and a.periodo = (select max(periodo) from empleados b
where b.cuit = a.cuit and b.cuil = a.cuil
and periodo >= '1801')
*/
CREATE OR ALTER PROCEDURE dbo.screening_empleados_ok
@IDCliente int,
@StepID int,
@fechaProceso date,
@Proceso smallint,
@Tipo varchar(3)
AS
/*
Paso 1: Busca PARTICIPACIONES de los empleados en sociedades en las tablas sociedades_constituciones,relaciones y edictos, que el cuit del edicto sea el del empleado
Paso 2: trabajo con los familiares de empleados
Paso 55: los proveedores que no pudieron aperturarse (no siempre es necesario correr este paso)
exec screening_empleados_ok 1659303046,1,null,1,'EMP'
exec screening_empleados_ok 1659303046,2,null,1,'FAM'
*/
BEGIN
if(@StepID=55) /*INSERTO TODOS LOS EMPLEADOS QUE NO PUDIERON APERTURARSE COMO N/A PARA GARANTIZAR QUE TODOS HAYAN SIDO ANALIZADOS*/
BEGIN
insert into screening_empleados_out (cliente,razon_social,cuit,titulo,cargo,tipo_reg,nro_proceso)
select @IDCliente as cliente,nombre_empleado as razon_social_prov,cuil as cuit_prov,'N/A' as titulo,'N/A' as cargo,'N/A' as tipo_reg,@Proceso as nro_proceso
from screening_EMPLEADOS where cliente = @IDCliente and nro_proceso = @Proceso AND tipo_reg= @Tipo
AND CUIL NOT IN (select distinct cuit from screening_empleados_out where Cliente = @IDCliente and nro_proceso = @Proceso AND tipo_reg not like '%_F%')
END
if(@StepID=0)
BEGIN
/* REGISTROS DE VINVULADOS POR AFIP DE FAMILIARES DE EMPLEADOS */
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
SELECT 'VENDORID' AS vendorid,
'ACCIONISTAS FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,
screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,
screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg = 'EDICTO_F')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
UNION ALL
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE VINVULADOS POR AFIP DE FAMILIARES DE EMPLEADOS */
SELECT 'VENDORID' AS vendorid,
'VINCULACIONES AFIP FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg = 'AFIP_F')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
UNION ALL
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE ACCIONISTAS DE FAMILIARES DE EMPLEADOS */
SELECT 'VENDORID' AS vendorid,
'ACCIONISTAS FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg = 'ACCIONIS_F')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
UNION ALL
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE PARTICIPACIONES SOCIETARIAS DE FAMILIARES DE EMPLEADOS */
SELECT 'VENDORID' AS vendorid,
'VINCULACIONES SOCIETARIAS FAMILIARES' AS PERSON_TYPE,
screening_empleados_out.cuit_familiar as TAXID,screening_empleados_out.nombre_familiar as LEGALNAME,
/*SOC_VINCULADA as LINKEDPERSONORENTITY,*/
iif(soc_vinculada is null, padrones.nombre_persona,soc_vinculada) as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit AS PARENT_TAX_ID,screening_empleados_out.razon_social AS PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
LEFT JOIN padrones on screening_empleados_out.CUIT_SOC_VINCULADA = padrones.identificacion
where (screening_empleados_out.tipo_reg in ('SOCCONS1_F','DIREC_F') )
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
/*
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
*/
union all
/* REGISTROS DE EMPLEADOS SIN DATOS DE APERTURA*/
SELECT 'VENDORID' AS vendorid,
'N/A' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,
screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,
screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg = 'N/A')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
and not exists (select * from screening_empleados_out b where b.cliente = @IDCliente and b.nro_proceso = @Proceso and b.cuit = screening_empleados_out.cuit and b.tipo_reg != 'N/A' and b.tipo_reg not like '%_F')
union all
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE EMPLEADOS VINCULADOS A EMPRESAS POR AFIP*/
SELECT 'VENDORID' AS vendorid,
'VINCULACIONES SOCIETARIAS' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg in ('SOC_CONS_1','DIRECTOR'))
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
union all
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE EMPLEADOS VINCULADOS A EMPRESAS POR AFIP*/
SELECT 'VENDORID' AS vendorid,
'AFIP' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg = 'AFIP')
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
union all
/*
declare @IDCliente int = 1659303046,
@StepID int = 0,
@fechaProceso date = '2018-06-04',
@Proceso smallint = '1',
@Tipo varchar(3) = 'EMP'
*/
/* REGISTROS DE EMPLEADOS ACCIONISTAS DE EMPRESAS */
SELECT 'VENDORID' AS vendorid,
'ACCIONISTA' AS PERSON_TYPE,
screening_empleados_out.cuit AS TAXID,screening_empleados_out.razon_social AS LEGALNAME,
SOC_VINCULADA as LINKEDPERSONORENTITY,
CUIT_SOC_VINCULADA as LINKTAXID,
screening_empleados_out.cuit_familiar as PARENT_TAX_ID,screening_empleados_out.nombre_familiar as PARENT_NAME,
iif(IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo) is null,'N/A',IIF(screening_empleados_out.cargo is null,titulo,screening_empleados_out.cargo)) as POSITIONRELATION,
-- busca en la tabla de pep
iif(SPWSBRG.cuit is null,'NO','YES') AS PEPSANCTIONSLIST,
iif(SPWSBRG.cargo is null,'NO',isnull(rtrim(ltrim(SPWSBRG.cargo)),'') + ' ' + iif(rtrim(ltrim(SPWSBRG.lugar))='NULL','',lugar)) AS POSITIONROLE,
iif(SPWSBRG.estado is null,'NO', SPWSBRG.estado) AS ESTATUS,
null as FECHADEFUNCION /*, + 'DATO AFIP' AS FUENTE*/
,SPWSBRG.cuit,SPWSBRG.razon_social,rtrim(ltrim(SPWSBRG.cargo)) + ' ' + rtrim(ltrim(SPWSBRG.lugar)) as cargo,
SPWSBRG.estado,
SPWSBRG.url2 as fecha_desde,
SPWSBRG.column9 as fecha_hasta
FROM screening_empleados_out
INNER join screening_empleados on (screening_empleados_out.cuit = screening_empleados.cuil AND screening_empleados.cliente= @IDCliente and screening_empleados.nro_proceso = @Proceso AND screening_empleados.tipo_reg = @Tipo)
LEFT JOIN screening_pep_ws_brg SPWSBRG ON (screening_empleados_out.cuit_integrante = SPWSBRG.cuit OR screening_empleados_out.cuit = SPWSBRG.cuit OR screening_empleados_out.cuit_soc_vinculada = SPWSBRG.cuit)
where (screening_empleados_out.tipo_reg = 'ACCIONISTA' )
AND screening_empleados_out.cliente = @IDCliente
and screening_empleados_out.nro_proceso = @Proceso
AND screening_empleados_out.cuit IN (SELECT DISTINCT CUIL FROM screening_empleados WHERE CLIENTE = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = @Tipo)
order by LEGALNAME,LINKEDPERSONORENTITY,PERSON_TYPE
END
if (@StepID=1)
begin
--------------------------------------------------------------------------------------------------------------------
/* Paso 1: Busca PARTICIPACIONES de los empleados en sociedades en las tablas sociedades_constituciones,relaciones y edictos, que el cuit del edicto sea el del empleado : */
--------------------------------------------------------------------------------------------------------------------
insert into screening_empleados_out (razon_social,cuit,cliente,created,titulo,cargo,soc_vinculada,cuit_soc_vinculada,
nombre_integrante,cuit_integrante,nombre_familiar,cuit_familiar,contenido_archivo,fecha_publicacion,tipo_reg,nro_proceso)
select DISTINCT screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo,'ACCIONISTA' AS cargo,
/*
p1.nombre_persona as soc_vinculada,p1.identificacion as soc_vinculada,
*/
iif(substring(accionistas.cuit_acc,1,1)='2',p2.nombre_persona,null) as soc_vinculada,
iif(substring(accionistas.cuit_acc,1,1)='2',p2.identificacion,null) as cuit_soc_vinculada,
/*
P2.nombre_persona AS nombre_integrante,accionistas.cuit_acc as cuit_integrante,
*/
iif(substring(accionistas.cuit_acc,1,1)='3',p2.nombre_persona,null) as nombre_integrante,
iif(substring(accionistas.cuit_acc,1,1)='3',accionistas.cuit_acc,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null AS contenido_archivo,getdate() AS fecha_publicacion,
tipo_reg = 'ACCIONISTA',@Proceso AS nro_proceso
from screening_empleados
inner join accionistas on screening_empleados.cuil = accionistas.cuit_acc
inner join padrones p1 on accionistas.cuit_acc = p1.identificacion
left join padrones p2 on accionistas.cuit_sociedad = p2.identificacion
where accionistas.cuit_acc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso and screening_empleados.tipo_reg = @Tipo)
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
UNION ALL
select DISTINCT screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo,
cargos.car_nombre AS cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
null as nombre_integrante,
null as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null AS contenido_archivo,getdate() AS fecha_publicacion,
tipo_reg = 'DIRECTOR',
@Proceso AS nro_proceso
from screening_empleados
inner join socios on ltrim(rtrim(screening_empleados.cuil)) = socios.c01_cuit_soc and socios.visible = 1 and isnull(c01_cuit,'') != ''
inner join cargos on cargos.car_codigo = socios.car_codigo
left join padrones p2 on socios.c01_cuit = p2.identificacion
where socios.c01_cuit_soc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso and screening_empleados.tipo_reg = @Tipo)
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
UNION ALL
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES EDICTOS COMO EMPRESAS */
select screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuit_prov,screening_empleados.cliente,getdate() as created,
NULL as titulo, NULL as cargo,
iif(substring(edictos.cuit_integrante,1,1)='3',padrones.nombre_persona,null) as soc_vinculada,
iif(substring(edictos.cuit_integrante,1,1)='3',edictos.cuit_integrante,null) as cuit_soc_vinculada,
iif(substring(edictos.cuit_integrante,1,1)='2',padrones.nombre_persona,null) as nombre_integrante,
iif(substring(edictos.cuit_integrante,1,1)='2',edictos.cuit_integrante,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
edictos.texto as contenido_archivo,edictos.fecha_boletin as fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join edictos on screening_empleados.cuil = edictos.cuit_sociedad
left join padrones on edictos.cuit_integrante = padrones.identificacion
left join padrones p2 on EDICTOS.cuit_sociedad = p2.identificacion
and cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
UNION ALL
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES EDICTOS PERSONAS */
select screening_empleados.nombre_empleado AS empleado,screening_empleados.cuil AS cuit_prov,screening_empleados.cliente,getdate() as created,
NULL as titulo, NULL as cargo,
iif(substring(edictos.cuit_sociedad,1,1)='3',P2.nombre_persona,null) as soc_vinculada,
iif(substring(edictos.cuit_sociedad,1,1)='3',edictos.cuit_sociedad,null) as cuit_soc_vinculada,
iif(substring(edictos.cuit_integrante,1,1)='2',null,'a') as nombre_integrante,
iif(substring(edictos.cuit_integrante,1,1)='2',null,'a') as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
edictos.texto as contenido_archivo,edictos.fecha_boletin as fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join edictos on screening_empleados.cuil = edictos.cuit_integrante
inner join padrones on edictos.cuit_integrante = padrones.identificacion
left join padrones p2 on EDICTOS.cuit_sociedad = p2.identificacion
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES CONSTITUCIONES COMO PERSONAS*/
select screening_empleados.nombre_empleado AS empleado ,screening_empleados.cuil AS cuil,
screening_empleados.cliente,
getdate() as created,
sociedades_constituciones.titulo, sociedades_constituciones.cargo,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.razon_social,null) as soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.documento_soc,null) as cuit_soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.nombre_integrante,null) as nombre_integrante,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.cuit_int,null) AS cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
sociedades_constituciones.contenido_archivo,sociedades_constituciones.fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join sociedades_constituciones on (screening_empleados.cuil = sociedades_constituciones.cuit_integrante)
left join padrones p2 on sociedades_constituciones.documento_soc = p2.identificacion
where screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
/*
and sociedades_constituciones.nombre_integrante <> '' and sociedades_constituciones.nombre_integrante is not null
*/
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES CONSTITUCIONES COMO PERSONAS*/
select screening_empleados.nombre_empleado AS empleado ,screening_empleados.cuil AS cuil,
screening_empleados.cliente,
getdate() as created,
sociedades_constituciones.titulo, sociedades_constituciones.cargo,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.razon_social,null) as soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='2' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.documento_soc,null) as cuit_soc_vinculada,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.nombre_integrante,null) as nombre_integrante,
iif(substring(sociedades_constituciones.cuit_int,1,1)='3' and (len(sociedades_constituciones.cuit_int) > 8),sociedades_constituciones.cuit_int,null) AS cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
sociedades_constituciones.contenido_archivo,sociedades_constituciones.fecha_publicacion
,'SOC_CONS_1' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join sociedades_constituciones on (screening_empleados.cuil = sociedades_constituciones.cuit_int)
left join padrones p2 on sociedades_constituciones.documento_soc = p2.identificacion
where screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
/*
and sociedades_constituciones.nombre_integrante <> '' and sociedades_constituciones.nombre_integrante is not null
*/
union all
select p2.nombre_persona as empleado,p2.identificacion AS cuil,
screening_empleados.cliente,
getdate() as created,
tp1.relacion as titulo, tsp1.subrelacion as cargo,
iif(substring(p3.identificacion,1,1)='3',p3.nombre_persona,null) as soc_vinculada,
iif(substring(p3.identificacion,1,1)='3',p3.identificacion,null) as cuit_soc_vinculada,
iif(substring(p3.identificacion,1,1)='2',p3.nombre_persona,null) as nombre_integrante,
iif(substring(p3.identificacion,1,1)='2',p3.identificacion,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null as contenido_archivo,relaciones.fecha_relacion,'AFIP' as tipo_reg /*SOC_CONS_1*/,@Proceso AS nro_proceso
from screening_empleados
inner join relaciones on screening_empleados.cuil = relaciones.cuita
inner join padrones p3 on relaciones.cuita = p3.identificacion
inner join padrones p2 on relaciones.cuitb = p2.identificacion
inner join tipos_relaciones tp1 on tp1.id_tipo_relacion = relaciones.id_tipo_relacion
inner join tipos_subrelaciones tsp1 on tsp1.id_subrelacion = relaciones.id_tipo_subrelacion
where cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
and relaciones.id_tipo_relacion in (1,2)
union all
/*buscamos sobre la tabla relaciones como personas */
select p2.nombre_persona as empleado,p2.identificacion AS cuil,
screening_empleados.cliente,
getdate() as created,
tp1.relacion as titulo, tsp1.subrelacion as cargo,
iif(substring(p3.identificacion,1,1)='3',p3.nombre_persona,null) as soc_vinculada,
iif(substring(p3.identificacion,1,1)='3',p3.identificacion,null) as cuit_soc_vinculada,
iif(substring(p3.identificacion,1,1)='2',p3.nombre_persona,null) as nombre_integrante,
iif(substring(p3.identificacion,1,1)='2',p3.identificacion,null) as cuit_integrante,
null as nombre_familiar,null as cuit_familiar,
null as contenido_archivo,relaciones.fecha_relacion,'AFIP' as tipo_reg /*SOC_CONS_1*/,@Proceso AS nro_proceso
from screening_empleados
inner join relaciones on screening_empleados.cuil = relaciones.cuitb
inner join padrones p3 on relaciones.cuita = p3.identificacion
inner join padrones p2 on relaciones.cuitb = p2.identificacion
inner join tipos_relaciones tp1 on tp1.id_tipo_relacion = relaciones.id_tipo_relacion
inner join tipos_subrelaciones tsp1 on tsp1.id_subrelacion = relaciones.id_tipo_subrelacion
where cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = @Tipo
and relaciones.id_tipo_relacion in (1,2)
order by empleado
end
if (@StepID=2) /* trabajo con los familiares de empleados*/
begin
insert into screening_empleados_out (razon_social,cuit,cliente,created,titulo,cargo,soc_vinculada,cuit_soc_vinculada,
nombre_integrante,cuit_integrante,nombre_familiar,cuit_familiar,contenido_archivo,fecha_publicacion,tipo_reg,nro_proceso)
/* relaciones */
select
ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente,
getdate() as created,
tp1.relacion as titulo, tsp1.subrelacion as cargo,
iif(substring(p3.identificacion,1,1)='3',p3.nombre_persona,null) as soc_vinculada,
iif(substring(p3.identificacion,1,1)='3',p3.identificacion,null) as cuit_soc_vinculada,
p2.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
p2.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
null as contenido_archivo,relaciones.fecha_relacion,'AFIP_F' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join relaciones on screening_empleados.cuil = relaciones.cuitb
inner join padrones p3 on relaciones.cuita = p3.identificacion
inner join padrones p2 on screening_empleados.cuil = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
inner join tipos_relaciones tp1 on tp1.id_tipo_relacion = relaciones.id_tipo_relacion
inner join tipos_subrelaciones tsp1 on tsp1.id_subrelacion = relaciones.id_tipo_subrelacion
where cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where nro_proceso = @Proceso and tipo_reg = 'EMP')
/*
and relaciones.id_tipo_relacion in (1,2)
*/
union all
/* accionistas */
select DISTINCT
ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo,'ACCIONISTA' AS cargo,
iif(substring(accionistas.cuit_acc,1,1)='2',p2.nombre_persona,null) as soc_vinculada,
iif(substring(accionistas.cuit_acc,1,1)='2',p2.identificacion,null) as cuit_soc_vinculada,
p1.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
p1.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
null as contenido_archivo,null as fecha_relacion,
tipo_reg = 'ACCIONIS_F',@Proceso AS nro_proceso
from screening_empleados
inner join accionistas on screening_empleados.cuil = accionistas.cuit_acc
inner join padrones p1 on accionistas.cuit_acc = p1.identificacion
inner join padrones p2 on accionistas.cuit_sociedad = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
where accionistas.cuit_acc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = 'FAM')
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where nro_proceso = @Proceso and tipo_reg = 'EMP')
union all
select DISTINCT
ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente as cliente,
getdate() as created,
null AS titulo, cargos.car_nombre AS cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
p1.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
p1.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
null as contenido_archivo,null as fecha_relacion,
tipo_reg = 'DIREC_F',
@Proceso AS nro_proceso
from screening_empleados
inner join socios on ltrim(rtrim(screening_empleados.cuil)) = socios.c01_cuit_soc and socios.visible = 1 and isnull(c01_cuit,'') != ''
inner join cargos on cargos.car_codigo = socios.car_codigo
inner join padrones p1 on socios.c01_cuit_soc = p1.identificacion and p1.habilitado = 1
inner join padrones p2 on socios.c01_cuit = p2.identificacion and p2.habilitado = 1
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
where socios.c01_cuit_soc in (select distinct ltrim(rtrim(cuil)) from screening_empleados where cliente = @IDCliente and screening_empleados.nro_proceso = @Proceso AND tipo_reg = 'FAM')
and screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where nro_proceso = @Proceso and tipo_reg = 'EMP')
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES CONSTITUCIONES COMO PERSONAS*/
select ptit.nombre_persona as empleado,ptit.identificacion as cuil,
/*
screening_empleados.nombre_empleado AS empleado ,screening_empleados.cuil AS cuil,
*/
screening_empleados.cliente,
getdate() as created,
sociedades_constituciones.titulo, sociedades_constituciones.cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
padrones.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
padrones.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
sociedades_constituciones.contenido_archivo,sociedades_constituciones.fecha_publicacion,
'SOCCONS1_F' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join sociedades_constituciones on (screening_empleados.cuil = sociedades_constituciones.cuit_int)
inner join padrones on screening_empleados.cuil = padrones.identificacion
left join padrones p2 on sociedades_constituciones.documento_soc = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
where screening_empleados.cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where cliente = @IDCliente and nro_proceso = @Proceso and tipo_reg = 'EMP')
union all
/* BUSCAMOS SOBRE LA TABLA SOCIEDADES EDICTOS PARA FAMILIARES */
select ptit.nombre_persona as empleado,ptit.identificacion as cuil,
screening_empleados.cliente,getdate() as created,
NULL as titulo, null as cargo,
p2.nombre_persona as soc_vinculada,
p2.identificacion as cuit_soc_vinculada,
padrones.nombre_persona as nombre_integrante,screening_empleados.cuil AS cuit_integrante,
padrones.nombre_persona as nombre_familiar,screening_empleados.cuil AS cuit_familiar,
edictos.texto as contenido_archivo,edictos.fecha_boletin as fecha_publicacion
,'EDICTO_F' as tipo_reg,@Proceso AS nro_proceso
from screening_empleados
inner join edictos on screening_empleados.cuil = edictos.cuit_integrante
left join padrones on edictos.cuit_integrante = padrones.identificacion
left join padrones p2 on EDICTOS.cuit_sociedad = p2.identificacion
inner join padrones ptit on screening_empleados.cuit_titular = ptit.identificacion
and cliente = @IDCliente
and screening_empleados.nro_proceso = @Proceso
and screening_empleados.tipo_reg = 'FAM'
AND screening_empleados.cuil not in (select distinct cuil from screening_empleados where cliente = @IDCliente and nro_proceso = @Proceso and tipo_reg = 'EMP')
end
END
GO
Depends On
12Used By
No items found