Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @ClientID | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
select top 10 CONVERT(VARCHAR(10),led_docs.ingresado, 103) AS FECHA_INGRESADO
from led_docs
where ingresado is not null
exec [Imperium_Digicard_Response_Diff] 9335603
exec [Imperium_Digicard_FULL] 9335603
exec [Imperium_Digicard_Response_bkp] 9335603
select * from led_digicard_emp_temp where empleado = 66849
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Digicard_Response_Diff
@ClientID int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sLocaciones as varchar(max)
declare @Contratista int
/*declare @ClientID int = 7048064*/
declare @Empleado int
declare @Periodo int = dbo.PeriodoAdelantado()
/*
select * from led_digicard_temp where locaciones = ''
*/
DELETE FROM led_digicard_temp
WHERE cliente = @ClientID
DELETE FROM led_digicard_emp_temp
WHERE cliente = @ClientID
DECLARE Contratistas Cursor
FOR
SELECT contratista from led_contratistas
WHERE cliente = @ClientID
Open Contratistas
Fetch NEXT FROM Contratistas INTO @Contratista
While @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
set @sLocaciones = ''
/*
select @sLocaciones = COALESCE(@sLocaciones + ',', '') + led_locaciones.id_cliente_locacion
from led_contratista_locaciones inner join led_locaciones on led_contratista_locaciones.locacion = led_locaciones.locacion
where contratista = @Contratista and led_contratista_locaciones.activo = 1
*/
select @sLocaciones = COALESCE(@sLocaciones + ',', '') + led_locaciones.id_cliente_locacion
from led_contratista_locaciones
inner join led_locaciones on led_contratista_locaciones.locacion = led_locaciones.locacion
inner join led_contratistas on led_contratista_locaciones.contratista = led_contratistas.contratista_1
where led_contratistas.contratista = @Contratista and led_contratista_locaciones.activo = 1
/*
SUBSTRING(@sLocaciones,4,200)
*/
insert into led_digicard_temp (cliente, contratista, locaciones)
select @ClientID as cliente, @Contratista as contratista,SUBSTRING(ltrim(@sLocaciones),2,200)
END TRY
BEGIN CATCH
END CATCH
Fetch NEXT FROM Contratistas INTO @Contratista
END
CLOSE Contratistas
DEALLOCATE Contratistas
/*
SELECT contratista,empleado from led_empleados_periodo
WHERE cliente = 9335603
DECLARE @sLocaciones as varchar(max)
declare @Contratista int = 1661
declare @Periodo int = 201706
*/
DECLARE Empleados Cursor
FOR
SELECT contratista,empleado from led_empleados
WHERE cliente = @ClientID
Open Empleados
Fetch NEXT FROM Empleados INTO @Contratista,@Empleado
While @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
set @sLocaciones = ''
select @sLocaciones = COALESCE(@sLocaciones + ',', '') + led_locaciones.id_cliente_locacion
/*
select led_empleado_locaciones.*, led_locaciones.id_cliente_locacion
*/
from led_empleado_locaciones
inner join led_locaciones on led_empleado_locaciones.locacion = led_locaciones.locacion
inner join led_empleados on led_empleado_locaciones.empleado = led_empleados.empleado
inner join led_contratistas on led_empleados.contratista_1 = led_contratistas.contratista_1
where led_contratistas.contratista = @Contratista and led_empleado_locaciones.activo = 1
and led_empleados.empleado =@Empleado
and led_empleado_locaciones.vigencia_desde <= getdate() and (led_empleado_locaciones.vigencia_hasta >= getdate() or led_empleado_locaciones.vigencia_hasta is null)
insert into led_digicard_emp_temp (cliente, contratista,empleado, locaciones)
select @ClientID as cliente, @Contratista as contratista,@Empleado,SUBSTRING(ltrim(@sLocaciones),2,200)
END TRY
BEGIN CATCH
END CATCH
Fetch NEXT FROM Empleados INTO @Contratista,@Empleado
END
CLOSE Empleados
DEALLOCATE Empleados
update led_digicard_temp set locaciones = null where locaciones = ''
update led_digicard_emp_temp set locaciones = null where locaciones = ''
/* EXCEPCIONES */
SELECT P1.nombre_persona as empleado, P1.identificacion as cuit_empleado,
padrones_1.nombre_persona AS empleador_directo,
padrones_1.identificacion AS cuit_empleador_directo,
' ' AS contratista_principal,' ' AS cuit_contratista_principal,
CONVERT(VARCHAR(10),led_control_ingreso.vigencia_excepcion, 103) + ' ' + CONVERT(VARCHAR(8),led_control_ingreso.vigencia_excepcion, 108) AS vigencia_excepcion,
'V' AS estado_ingreso,
iif(led_digicard_temp.locaciones is null,'99',led_digicard_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),led_control_ingreso.vigencia_excepcion, 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
INNER JOIN
padrones P1 ON led_empleados.id_padron = P1.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
LEFT OUTER JOIN led_digicard_temp ON
(led_control_ingreso.cliente = led_digicard_temp.cliente
AND led_control_ingreso.contratista = led_digicard_temp.contratista)
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
UNION ALL
/* EMPLEADOS SIN WHITE LIST NI BLACK LIST*/
SELECT P.nombre_persona AS empleado, P.numero AS cuit_empleado,PD.nombre_persona AS empleador_directo, PD.numero AS cuit_empleador_directo,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.nombre_persona ELSE ' ' END AS contratista_principal,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.numero ELSE ' ' END AS cuit_contratista_principal,
/* CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
iif(LE.estado_empleado = 'N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
iif(led_digicard_emp_temp.locaciones is null,'99',led_digicard_emp_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_empleados LE
inner join led_empleado_multi LEM on LE.empleado = LEM.empleado
inner join led_empleados_periodo LEP on LE.empleado = LEP.empleado
inner join led_tipos_empleado TE on LE.tipo_empleado = TE.tipo_empleado
inner join padrones P on LE.id_padron = P.id_padron
inner join led_contratistas LC1 on LE.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join led_contratistas LC on LE.contratista = LC.contratista
inner join padrones PD on LC.id_padron = PD.id_padron
inner join
(select led_docs.empleado from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_docs.estado_doc IN ('N', 'I', 'V', 'R')
and led_cliente_empleado.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs ON LE.empleado = docs.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS pendientes from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_pendientes ON LE.empleado = docs_pendientes.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS ingresados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_ingresados ON LE.empleado = docs_ingresados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados ON LE.empleado = docs_verificados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS rechazados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_rechazados ON LE.empleado = docs_rechazados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados_vencidos from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and (led_docs.fecha_vigencia < getdate())
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados_vencidos ON LE.empleado = docs_verificados_vencidos.empleado
LEFT OUTER JOIN led_digicard_emp_temp ON
(LE.empleado = led_digicard_emp_temp.empleado)
LEFT OUTER JOIN
(select led_empleados.empleado, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_empleados inner join led_docs on led_empleados.empleado = led_docs.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_docs.cliente = led_cliente_empleado.cliente
and led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
inner join led_contratistas on
(led_empleados.contratista = led_contratistas.contratista
and led_docs.cliente = led_contratistas.cliente)
where led_docs.led_seccion = 'E'
and led_tipos_doc.modalidad = 'A'
and led_cliente_empleado.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_empleados.empleado) VENCIMIENTO ON LE.empleado = VENCIMIENTO.empleado
where LE.cliente = @ClientID
/*
and LE.estado_empleado = 'A'
*/
and LEP.periodo = @Periodo
AND P1.identificacion NOT IN (
SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P.identificacion NOT IN ( select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('X','W') )
and (LE.empleado in (select distinct empleado from led_docs where (verificado > getdate()-0.045 or rechazado > getdate()-0.045 or last_modified > getdate()-0.045)
and cliente in (@ClientID) and periodo = @Periodo and estado_doc in ('N','I','R','V')
union all
select distinct led_empleado_locaciones.empleado from led_empleado_locaciones inner join led_empleado_multi on led_empleado_multi.empleado = led_empleado_locaciones.empleado
where led_empleado_multi.cliente in (@ClientID) and (led_empleado_locaciones.asignada > getdate()-0.045 or led_empleado_locaciones.modified > getdate()-0.045)))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
/*
and (LC.contratista in (select distinct contratista from led_docs where last_modified > getdate()-0.045 and cliente in (@ClientID))
OR LE.EMPLEADO IN (select distinct empleado from led_empleado_locaciones where (asignada > getdate()-0.045 or modified > getdate()-0.045)))
*/
UNION ALL
/* EMPLEADOS SOLO WHITE LIST*/
SELECT P.nombre_persona AS empleado, P.numero AS cuit_empleado,PD.nombre_persona AS empleador_directo, PD.numero AS cuit_empleador_directo,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.nombre_persona ELSE ' ' END AS contratista_principal,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.numero ELSE ' ' END AS cuit_contratista_principal,
/* CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
/*
iif(LE.estado_empleado = 'N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
*/
'V' AS estado_ingreso,
/*
iif(led_digicard_emp_temp.locaciones is null,'99',led_digicard_emp_temp.locaciones) AS locacion,
*/
'0' as locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_empleados LE
inner join led_empleado_multi LEM on LE.empleado = LEM.empleado
inner join led_empleados_periodo LEP on LE.empleado = LEP.empleado
inner join led_tipos_empleado TE on LE.tipo_empleado = TE.tipo_empleado
inner join padrones P on LE.id_padron = P.id_padron
inner join led_contratistas LC1 on LE.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join led_contratistas LC on LE.contratista = LC.contratista
inner join padrones PD on LC.id_padron = PD.id_padron
/*
inner join
(select led_docs.empleado from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_docs.estado_doc IN ('N', 'I', 'V', 'R')
and led_cliente_empleado.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs ON LE.empleado = docs.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS pendientes from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_pendientes ON LE.empleado = docs_pendientes.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS ingresados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_ingresados ON LE.empleado = docs_ingresados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados ON LE.empleado = docs_verificados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS rechazados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_rechazados ON LE.empleado = docs_rechazados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados_vencidos from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and (led_docs.fecha_vigencia < getdate())
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados_vencidos ON LE.empleado = docs_verificados_vencidos.empleado
LEFT OUTER JOIN led_digicard_emp_temp ON
(LE.empleado = led_digicard_emp_temp.empleado)
*/
LEFT OUTER JOIN
(select led_empleados.empleado, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_empleados inner join led_docs on led_empleados.empleado = led_docs.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_docs.cliente = led_cliente_empleado.cliente
and led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
inner join led_contratistas on
(led_empleados.contratista = led_contratistas.contratista
and led_docs.cliente = led_contratistas.cliente)
where led_docs.led_seccion = 'E'
and led_tipos_doc.modalidad = 'A'
and led_cliente_empleado.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_empleados.empleado) VENCIMIENTO ON LE.empleado = VENCIMIENTO.empleado
where LE.cliente = @ClientID
/*
and LE.estado_empleado = 'A'
*/
and LEP.periodo = @Periodo
AND P1.identificacion NOT IN (
SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P.identificacion IN ( select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W') )
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
UNION ALL
/* SUBCONTRATISTAS UNIPERSONALES SIN WHITE LIST NI BLACK LIST*/
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_subcontratista_periodo LSCP on LC.contratista = LSCP.subcontratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion NOT IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('X','W'))
and (LC.contratista in (select distinct CONTRATISTA from led_docs where (verificado > getdate()-0.045 or rechazado > getdate()-0.045 or last_modified > getdate()-0.045)
and cliente in (@ClientID) and periodo = @Periodo and estado_doc in ('N','I','R','V')
union all
select distinct led_contratista_locaciones.contratista from led_contratista_locaciones inner join led_contratista_multi on led_contratista_multi.contratista = led_contratista_locaciones.contratista
where led_contratista_multi.cliente in (@ClientID) and (led_contratista_locaciones.asignada > getdate()-0.045 or led_contratista_locaciones.modified > getdate()-0.045)))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
/*
and LC.contratista in (select distinct contratista from led_docs where last_modified > getdate()-0.045 and cliente in (@ClientID))
*/
UNION ALL
/* SUBCONTRATISTAS UNIPERSONALES SOLO WHITE LIST */
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
/*
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
*/
'V' AS estado_ingreso,
/*
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
*/
'0' as locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_subcontratista_periodo LSCP on LC.contratista = LSCP.subcontratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
/*
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
*/
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
/*
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
*/
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W'))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
UNION ALL
/* CONTRATISTAS UNIPERSONALES SIN WHITE LIST NI BLACK LIST*/
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_contratista_periodo LSCP on LC.contratista = LSCP.contratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion NOT IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W','X'))
and (LC.contratista in (select distinct CONTRATISTA from led_docs where (verificado > getdate()-0.045 or rechazado > getdate()-0.045 or last_modified > getdate()-0.045)
and cliente in (@ClientID) and periodo = @Periodo and estado_doc in ('N','I','R','V')
union all
select distinct led_contratista_locaciones.contratista from led_contratista_locaciones inner join led_contratista_multi on led_contratista_multi.contratista = led_contratista_locaciones.contratista
where led_contratista_multi.cliente in (@ClientID) and (led_contratista_locaciones.asignada > getdate()-0.045 or led_contratista_locaciones.modified > getdate()-0.045)))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
/*
and LC.contratista in (select distinct contratista from led_docs where last_modified > getdate()-0.045 and cliente in (@ClientID))
*/
UNION ALL
/* CONTRATISTAS UNIPERSONALES SOLO WHITE LIST */
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
/*
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
*/
'V' AS estado_ingreso,
/*
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
*/
'0' as locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_contratista_periodo LSCP on LC.contratista = LSCP.contratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
/*
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
*/
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
/*
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
*/
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W'))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
UNION ALL
/*
select 'DATOS DE PRUEBA LISTA NEGRA' as empleado,'27897771255' AS cuit_empleado,
'DATOS DE PRUEBA LISTA NEGRA' AS empleador_directo, '27897771255' AS cuit_empleador_directo,
'DATOS DE PRUEBA LISTA NEGRA' AS contratista_principal, '27897771255' AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
'X' AS estado_ingreso,
'0' AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
*/
/* LISTA NEGRA */
select padrones.nombre_persona as empleado,padrones.identificacion as cuit_empleado,
padrones.nombre_persona as empleador_directo,padrones.identificacion as cuit_empleador_directo,
padrones.nombre_persona as contratista_principal,padrones.identificacion as cuit_contratista_principal,
null as vigencia_excepcion,
led_blacklist.tipo_lista AS estado_ingreso,
'0' AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('X')
UNION ALL
/* LISTA BLANCA */
select padrones.nombre_persona as empleado,padrones.identificacion as cuit_empleado,
padrones.nombre_persona as empleador_directo,padrones.identificacion as cuit_empleador_directo,
padrones.nombre_persona as contratista_principal,padrones.identificacion as cuit_contratista_principal,
null as vigencia_excepcion,
'V' AS estado_ingreso,
'0' AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W')
ORDER BY EMPLEADO
/*
SELECT empleado, cuit_empleado, empleador_directo, isnull(cuit_empleador_directo,0) as cuit_empleador_directo, isnull(contratista_principal,0) as contratista_principal,
isnull(cuit_contratista_principal,0) as cuit_contratista_principal,
CONVERT(VARCHAR(10),getdate()+1, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+1, 108) as vigencia_excepcion
, estado_ingreso, locacion,
CONVERT(VARCHAR(10),isnull(fecha_maxima_ingreso,getdate()), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
FROM Digicard
*/
/*
SELECT led_tipos_contratista.nombre_tipo_contratista,
padrones.nombre_persona as empleado, padrones.identificacion as cuit_empleado,
padrones_1.nombre_persona AS empleador_directo, padrones_1.identificacion AS cuit_empleador_directo,
null AS contratista_principal,null AS cuit_contratista_principal,
/*
led_control_ingreso.vigencia_excepcion
*/
getdate() + 1 as vigencia_excepcion
, 'V' AS estado_ingreso,'0' as locacion,
getdate() + 43 as fecha_maxima_ingreso
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = 9335603
and led_control_ingreso.
order by padrones.nombre_persona asc
exec [Imperium_Digicard_Response] 9335603
select * from led_blacklist
SELECT empleado, cuit_empleado, empleador_directo, isnull(cuit_empleador_directo,0) as cuit_empleador_directo, isnull(contratista_principal,0) as contratista_principal,
isnull(cuit_contratista_principal,0) as cuit_contratista_principal,
CONVERT(VARCHAR(10),getdate()+1, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+1, 108) as vigencia_excepcion
, estado_ingreso, locacion,
CONVERT(VARCHAR(10),isnull(fecha_maxima_ingreso,getdate()), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
9335603 as cliente,
CONVERT(VARCHAR(10),getdate()+0010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0010, 108) as habilitado_proxima_consulta
FROM Digicard
/*
iif(LC.estado_contratista='A','A','B') AS ACTIVO,
TC.nombre_tipo_contratista AS NOMBRE_TIPO_CONTRATISTA,
*/
/*
SELECT empleado, cuit_empleado, empleador_directo, isnull(cuit_empleador_directo,0) as cuit_empleador_directo, isnull(contratista_principal,0) as contratista_principal,
isnull(cuit_contratista_principal,0) as cuit_contratista_principal,
CONVERT(VARCHAR(10),getdate()+1, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+1, 108) as vigencia_excepcion
, estado_ingreso, locacion,
CONVERT(VARCHAR(10),isnull(fecha_maxima_ingreso,getdate()), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
FROM Digicard
*/
*/
end
GO
GO
/*
select top 10 CONVERT(VARCHAR(10),led_docs.ingresado, 103) AS FECHA_INGRESADO
from led_docs
where ingresado is not null
exec [Imperium_Digicard_Response_Diff] 9335603
exec [Imperium_Digicard_FULL] 9335603
exec [Imperium_Digicard_Response_bkp] 9335603
select * from led_digicard_emp_temp where empleado = 66849
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Digicard_Response_Diff
@ClientID int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sLocaciones as varchar(max)
declare @Contratista int
/*declare @ClientID int = 7048064*/
declare @Empleado int
declare @Periodo int = dbo.PeriodoAdelantado()
/*
select * from led_digicard_temp where locaciones = ''
*/
DELETE FROM led_digicard_temp
WHERE cliente = @ClientID
DELETE FROM led_digicard_emp_temp
WHERE cliente = @ClientID
DECLARE Contratistas Cursor
FOR
SELECT contratista from led_contratistas
WHERE cliente = @ClientID
Open Contratistas
Fetch NEXT FROM Contratistas INTO @Contratista
While @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
set @sLocaciones = ''
/*
select @sLocaciones = COALESCE(@sLocaciones + ',', '') + led_locaciones.id_cliente_locacion
from led_contratista_locaciones inner join led_locaciones on led_contratista_locaciones.locacion = led_locaciones.locacion
where contratista = @Contratista and led_contratista_locaciones.activo = 1
*/
select @sLocaciones = COALESCE(@sLocaciones + ',', '') + led_locaciones.id_cliente_locacion
from led_contratista_locaciones
inner join led_locaciones on led_contratista_locaciones.locacion = led_locaciones.locacion
inner join led_contratistas on led_contratista_locaciones.contratista = led_contratistas.contratista_1
where led_contratistas.contratista = @Contratista and led_contratista_locaciones.activo = 1
/*
SUBSTRING(@sLocaciones,4,200)
*/
insert into led_digicard_temp (cliente, contratista, locaciones)
select @ClientID as cliente, @Contratista as contratista,SUBSTRING(ltrim(@sLocaciones),2,200)
END TRY
BEGIN CATCH
END CATCH
Fetch NEXT FROM Contratistas INTO @Contratista
END
CLOSE Contratistas
DEALLOCATE Contratistas
/*
SELECT contratista,empleado from led_empleados_periodo
WHERE cliente = 9335603
DECLARE @sLocaciones as varchar(max)
declare @Contratista int = 1661
declare @Periodo int = 201706
*/
DECLARE Empleados Cursor
FOR
SELECT contratista,empleado from led_empleados
WHERE cliente = @ClientID
Open Empleados
Fetch NEXT FROM Empleados INTO @Contratista,@Empleado
While @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
set @sLocaciones = ''
select @sLocaciones = COALESCE(@sLocaciones + ',', '') + led_locaciones.id_cliente_locacion
/*
select led_empleado_locaciones.*, led_locaciones.id_cliente_locacion
*/
from led_empleado_locaciones
inner join led_locaciones on led_empleado_locaciones.locacion = led_locaciones.locacion
inner join led_empleados on led_empleado_locaciones.empleado = led_empleados.empleado
inner join led_contratistas on led_empleados.contratista_1 = led_contratistas.contratista_1
where led_contratistas.contratista = @Contratista and led_empleado_locaciones.activo = 1
and led_empleados.empleado =@Empleado
and led_empleado_locaciones.vigencia_desde <= getdate() and (led_empleado_locaciones.vigencia_hasta >= getdate() or led_empleado_locaciones.vigencia_hasta is null)
insert into led_digicard_emp_temp (cliente, contratista,empleado, locaciones)
select @ClientID as cliente, @Contratista as contratista,@Empleado,SUBSTRING(ltrim(@sLocaciones),2,200)
END TRY
BEGIN CATCH
END CATCH
Fetch NEXT FROM Empleados INTO @Contratista,@Empleado
END
CLOSE Empleados
DEALLOCATE Empleados
update led_digicard_temp set locaciones = null where locaciones = ''
update led_digicard_emp_temp set locaciones = null where locaciones = ''
/* EXCEPCIONES */
SELECT P1.nombre_persona as empleado, P1.identificacion as cuit_empleado,
padrones_1.nombre_persona AS empleador_directo,
padrones_1.identificacion AS cuit_empleador_directo,
' ' AS contratista_principal,' ' AS cuit_contratista_principal,
CONVERT(VARCHAR(10),led_control_ingreso.vigencia_excepcion, 103) + ' ' + CONVERT(VARCHAR(8),led_control_ingreso.vigencia_excepcion, 108) AS vigencia_excepcion,
'V' AS estado_ingreso,
iif(led_digicard_temp.locaciones is null,'99',led_digicard_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),led_control_ingreso.vigencia_excepcion, 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
INNER JOIN
padrones P1 ON led_empleados.id_padron = P1.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
LEFT OUTER JOIN led_digicard_temp ON
(led_control_ingreso.cliente = led_digicard_temp.cliente
AND led_control_ingreso.contratista = led_digicard_temp.contratista)
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
UNION ALL
/* EMPLEADOS SIN WHITE LIST NI BLACK LIST*/
SELECT P.nombre_persona AS empleado, P.numero AS cuit_empleado,PD.nombre_persona AS empleador_directo, PD.numero AS cuit_empleador_directo,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.nombre_persona ELSE ' ' END AS contratista_principal,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.numero ELSE ' ' END AS cuit_contratista_principal,
/* CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
iif(LE.estado_empleado = 'N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
iif(led_digicard_emp_temp.locaciones is null,'99',led_digicard_emp_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_empleados LE
inner join led_empleado_multi LEM on LE.empleado = LEM.empleado
inner join led_empleados_periodo LEP on LE.empleado = LEP.empleado
inner join led_tipos_empleado TE on LE.tipo_empleado = TE.tipo_empleado
inner join padrones P on LE.id_padron = P.id_padron
inner join led_contratistas LC1 on LE.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join led_contratistas LC on LE.contratista = LC.contratista
inner join padrones PD on LC.id_padron = PD.id_padron
inner join
(select led_docs.empleado from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_docs.estado_doc IN ('N', 'I', 'V', 'R')
and led_cliente_empleado.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs ON LE.empleado = docs.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS pendientes from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_pendientes ON LE.empleado = docs_pendientes.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS ingresados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_ingresados ON LE.empleado = docs_ingresados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados ON LE.empleado = docs_verificados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS rechazados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_rechazados ON LE.empleado = docs_rechazados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados_vencidos from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and (led_docs.fecha_vigencia < getdate())
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados_vencidos ON LE.empleado = docs_verificados_vencidos.empleado
LEFT OUTER JOIN led_digicard_emp_temp ON
(LE.empleado = led_digicard_emp_temp.empleado)
LEFT OUTER JOIN
(select led_empleados.empleado, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_empleados inner join led_docs on led_empleados.empleado = led_docs.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_docs.cliente = led_cliente_empleado.cliente
and led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
inner join led_contratistas on
(led_empleados.contratista = led_contratistas.contratista
and led_docs.cliente = led_contratistas.cliente)
where led_docs.led_seccion = 'E'
and led_tipos_doc.modalidad = 'A'
and led_cliente_empleado.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_empleados.empleado) VENCIMIENTO ON LE.empleado = VENCIMIENTO.empleado
where LE.cliente = @ClientID
/*
and LE.estado_empleado = 'A'
*/
and LEP.periodo = @Periodo
AND P1.identificacion NOT IN (
SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P.identificacion NOT IN ( select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('X','W') )
and (LE.empleado in (select distinct empleado from led_docs where (verificado > getdate()-0.045 or rechazado > getdate()-0.045 or last_modified > getdate()-0.045)
and cliente in (@ClientID) and periodo = @Periodo and estado_doc in ('N','I','R','V')
union all
select distinct led_empleado_locaciones.empleado from led_empleado_locaciones inner join led_empleado_multi on led_empleado_multi.empleado = led_empleado_locaciones.empleado
where led_empleado_multi.cliente in (@ClientID) and (led_empleado_locaciones.asignada > getdate()-0.045 or led_empleado_locaciones.modified > getdate()-0.045)))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
/*
and (LC.contratista in (select distinct contratista from led_docs where last_modified > getdate()-0.045 and cliente in (@ClientID))
OR LE.EMPLEADO IN (select distinct empleado from led_empleado_locaciones where (asignada > getdate()-0.045 or modified > getdate()-0.045)))
*/
UNION ALL
/* EMPLEADOS SOLO WHITE LIST*/
SELECT P.nombre_persona AS empleado, P.numero AS cuit_empleado,PD.nombre_persona AS empleador_directo, PD.numero AS cuit_empleador_directo,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.nombre_persona ELSE ' ' END AS contratista_principal,
CASE WHEN LC.contratista <> LC.contratista_1 THEN P1.numero ELSE ' ' END AS cuit_contratista_principal,
/* CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
/*
iif(LE.estado_empleado = 'N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
*/
'V' AS estado_ingreso,
/*
iif(led_digicard_emp_temp.locaciones is null,'99',led_digicard_emp_temp.locaciones) AS locacion,
*/
'0' as locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_empleados LE
inner join led_empleado_multi LEM on LE.empleado = LEM.empleado
inner join led_empleados_periodo LEP on LE.empleado = LEP.empleado
inner join led_tipos_empleado TE on LE.tipo_empleado = TE.tipo_empleado
inner join padrones P on LE.id_padron = P.id_padron
inner join led_contratistas LC1 on LE.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join led_contratistas LC on LE.contratista = LC.contratista
inner join padrones PD on LC.id_padron = PD.id_padron
/*
inner join
(select led_docs.empleado from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_docs.estado_doc IN ('N', 'I', 'V', 'R')
and led_cliente_empleado.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs ON LE.empleado = docs.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS pendientes from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_pendientes ON LE.empleado = docs_pendientes.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS ingresados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_ingresados ON LE.empleado = docs_ingresados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados ON LE.empleado = docs_verificados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS rechazados from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_rechazados ON LE.empleado = docs_rechazados.empleado
LEFT OUTER JOIN
(select led_docs.empleado, COUNT(*) AS verificados_vencidos from led_docs
inner join led_empleados on led_docs.empleado = led_empleados.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.cliente = led_cliente_empleado.cliente
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'E'
and led_cliente_empleado.ci_killer = 1
and led_docs.estado_doc = 'V'
and (led_docs.fecha_vigencia < getdate())
and led_docs.periodo = @Periodo
group by led_docs.empleado) docs_verificados_vencidos ON LE.empleado = docs_verificados_vencidos.empleado
LEFT OUTER JOIN led_digicard_emp_temp ON
(LE.empleado = led_digicard_emp_temp.empleado)
*/
LEFT OUTER JOIN
(select led_empleados.empleado, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_empleados inner join led_docs on led_empleados.empleado = led_docs.empleado
inner join led_empleado_multi LEM on led_empleados.empleado = LEM.empleado
inner join led_cliente_empleado on
(led_docs.cliente = led_cliente_empleado.cliente
and led_empleados.tipo_empleado = led_cliente_empleado.tipo_empleado
and led_docs.tipo_doc = led_cliente_empleado.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
inner join led_contratistas on
(led_empleados.contratista = led_contratistas.contratista
and led_docs.cliente = led_contratistas.cliente)
where led_docs.led_seccion = 'E'
and led_tipos_doc.modalidad = 'A'
and led_cliente_empleado.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_empleados.empleado) VENCIMIENTO ON LE.empleado = VENCIMIENTO.empleado
where LE.cliente = @ClientID
/*
and LE.estado_empleado = 'A'
*/
and LEP.periodo = @Periodo
AND P1.identificacion NOT IN (
SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P.identificacion IN ( select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W') )
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
UNION ALL
/* SUBCONTRATISTAS UNIPERSONALES SIN WHITE LIST NI BLACK LIST*/
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_subcontratista_periodo LSCP on LC.contratista = LSCP.subcontratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion NOT IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('X','W'))
and (LC.contratista in (select distinct CONTRATISTA from led_docs where (verificado > getdate()-0.045 or rechazado > getdate()-0.045 or last_modified > getdate()-0.045)
and cliente in (@ClientID) and periodo = @Periodo and estado_doc in ('N','I','R','V')
union all
select distinct led_contratista_locaciones.contratista from led_contratista_locaciones inner join led_contratista_multi on led_contratista_multi.contratista = led_contratista_locaciones.contratista
where led_contratista_multi.cliente in (@ClientID) and (led_contratista_locaciones.asignada > getdate()-0.045 or led_contratista_locaciones.modified > getdate()-0.045)))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
/*
and LC.contratista in (select distinct contratista from led_docs where last_modified > getdate()-0.045 and cliente in (@ClientID))
*/
UNION ALL
/* SUBCONTRATISTAS UNIPERSONALES SOLO WHITE LIST */
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
/*
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
*/
'V' AS estado_ingreso,
/*
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
*/
'0' as locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_subcontratista_periodo LSCP on LC.contratista = LSCP.subcontratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
/*
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
*/
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
/*
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
*/
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W'))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
UNION ALL
/* CONTRATISTAS UNIPERSONALES SIN WHITE LIST NI BLACK LIST*/
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_contratista_periodo LSCP on LC.contratista = LSCP.contratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion NOT IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W','X'))
and (LC.contratista in (select distinct CONTRATISTA from led_docs where (verificado > getdate()-0.045 or rechazado > getdate()-0.045 or last_modified > getdate()-0.045)
and cliente in (@ClientID) and periodo = @Periodo and estado_doc in ('N','I','R','V')
union all
select distinct led_contratista_locaciones.contratista from led_contratista_locaciones inner join led_contratista_multi on led_contratista_multi.contratista = led_contratista_locaciones.contratista
where led_contratista_multi.cliente in (@ClientID) and (led_contratista_locaciones.asignada > getdate()-0.045 or led_contratista_locaciones.modified > getdate()-0.045)))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
/*
and LC.contratista in (select distinct contratista from led_docs where last_modified > getdate()-0.045 and cliente in (@ClientID))
*/
UNION ALL
/* CONTRATISTAS UNIPERSONALES SOLO WHITE LIST */
SELECT DISTINCT P.nombre_persona AS empleado, P.numero AS cuit_empleado,
P.nombre_persona AS empleador_directo, P.numero AS cuit_empleador_directo,
P1.nombre_persona AS contratista_principal, P1.numero AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
/*
iif(LC.estado_contratista='N','B',CASE WHEN
ISNULL(docs_pendientes.pendientes, 0) = 0 AND
ISNULL(docs_ingresados.ingresados, 0) = 0 AND
ISNULL(docs_verificados.verificados, 0) > 0 AND
ISNULL(docs_rechazados.rechazados, 0) = 0 AND
ISNULL(docs_verificados_vencidos.verificados_vencidos, 0) = 0 THEN 'V'
ELSE 'R' END) AS estado_ingreso,
*/
'V' AS estado_ingreso,
/*
iif(led_digicard_temp.locaciones is null ,'99',led_digicard_temp.locaciones) AS locacion,
*/
'0' as locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_contratistas LC inner join led_contratista_periodo LSCP on LC.contratista = LSCP.contratista
inner join led_contratista_multi LCM on LC.contratista = LCM.contratista
inner join led_tipos_contratista TC on LC.tipo_contratista = TC.tipo_contratista
inner join padrones P on LC.id_padron = P.id_padron
inner join led_contratistas LC1 on LC.contratista_1 = LC1.contratista
inner join padrones P1 on LC1.id_padron = P1.id_padron
/*
inner join
(select led_docs.contratista from led_docs
inner join led_contratista_multi on led_docs.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratista_multi.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs ON LC.contratista = docs.contratista
*/
left outer join
(select led_contratistas.contratista, count(*) AS total_empleados
from led_contratistas
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_empleados
on led_contratistas.contratista = led_empleados.contratista
inner join led_empleados_periodo
on led_empleados.empleado = led_empleados_periodo.empleado
where led_empleados.estado_empleado = 'A'
and led_contratistas.estado_contratista = 'A'
and led_empleados.cliente = @ClientID
and led_empleados_periodo.periodo = @Periodo
group by led_contratistas.contratista) empleados
on LC.contratista = empleados.contratista
/*
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS pendientes from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'N'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_pendientes ON LC.contratista = docs_pendientes.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS ingresados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'I'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_ingresados ON LC.contratista = docs_ingresados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia >= getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados ON LC.contratista = docs_verificados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS rechazados from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'R'
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_rechazados ON LC.contratista = docs_rechazados.contratista
LEFT OUTER JOIN
(select led_docs.contratista, COUNT(*) AS verificados_vencidos from led_docs
inner join led_contratistas on led_docs.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.cliente = led_cliente_contratista.cliente
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
where led_docs.cliente = @ClientID
and led_docs.led_seccion = 'C'
and led_cliente_contratista.ci_killer = 1
and led_docs.estado_doc = 'V'
and led_docs.fecha_vigencia < getdate()
and led_docs.periodo = @Periodo
group by led_docs.contratista) docs_verificados_vencidos ON LC.contratista = docs_verificados_vencidos.contratista
LEFT OUTER JOIN led_digicard_temp ON
(LC.cliente = led_digicard_temp.cliente
AND LC.contratista = led_digicard_temp.contratista)
*/
LEFT OUTER JOIN
(select led_contratistas.contratista, MIN(led_docs.fecha_vigencia) as fecha_vencimiento
from led_contratistas inner join led_docs on led_contratistas.contratista = led_docs.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
inner join led_cliente_contratista on
(led_docs.cliente = led_cliente_contratista.cliente
and led_contratistas.tipo_contratista = led_cliente_contratista.tipo_contratista
and led_docs.tipo_doc = led_cliente_contratista.tipo_doc)
inner join led_tipos_doc on led_docs.tipo_doc = led_tipos_doc.tipo_doc
where led_docs.led_seccion = 'C'
and led_tipos_doc.modalidad = 'A'
and led_cliente_contratista.ci_killer = 1
and led_docs.cliente = @ClientID
and led_docs.periodo = @Periodo
group by led_contratistas.contratista) VENCIMIENTO ON LC.contratista = VENCIMIENTO.contratista
where
LC.cliente = @ClientID
/*and
LC.estado_contratista = 'A'*/
and
LSCP.periodo = @Periodo and
empleados.total_empleados IS NULL
AND P1.identificacion NOT IN (SELECT DISTINCT padrones.identificacion as cuit_empleado
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista
inner join led_contratista_multi on led_contratistas.contratista = led_contratista_multi.contratista
INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = @ClientID
and led_control_ingreso.estado_autorizacion='A'
and led_control_ingreso.tipo_acceso='I'
and led_control_ingreso.excepcion not in (2)
and led_control_ingreso.vigencia_excepcion > getdate()
)
AND P1.identificacion IN (
select distinct padrones.identificacion
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W'))
AND LC.estado_contratista = 'A'
AND LC1.estado_contratista = 'A'
AND (P.tipo_persona IN ('F'))
UNION ALL
/*
select 'DATOS DE PRUEBA LISTA NEGRA' as empleado,'27897771255' AS cuit_empleado,
'DATOS DE PRUEBA LISTA NEGRA' AS empleador_directo, '27897771255' AS cuit_empleador_directo,
'DATOS DE PRUEBA LISTA NEGRA' AS contratista_principal, '27897771255' AS cuit_contratista_principal,
/*CONVERT(VARCHAR(10),getdate()+(365*3), 103) + ' ' + CONVERT(VARCHAR(8),getdate()+(365*3), 108) as vigencia_excepcion,*/
null as vigencia_excepcion,
'X' AS estado_ingreso,
'0' AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
*/
/* LISTA NEGRA */
select padrones.nombre_persona as empleado,padrones.identificacion as cuit_empleado,
padrones.nombre_persona as empleador_directo,padrones.identificacion as cuit_empleador_directo,
padrones.nombre_persona as contratista_principal,padrones.identificacion as cuit_contratista_principal,
null as vigencia_excepcion,
led_blacklist.tipo_lista AS estado_ingreso,
'0' AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('X')
UNION ALL
/* LISTA BLANCA */
select padrones.nombre_persona as empleado,padrones.identificacion as cuit_empleado,
padrones.nombre_persona as empleador_directo,padrones.identificacion as cuit_empleador_directo,
padrones.nombre_persona as contratista_principal,padrones.identificacion as cuit_contratista_principal,
null as vigencia_excepcion,
'V' AS estado_ingreso,
'0' AS locacion,
CONVERT(VARCHAR(10),isnull(getdate()+(365*3),getdate()+(365*3)), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
from led_blacklist inner join padrones on led_blacklist.id_padron = padrones.id_padron
where led_blacklist.cliente = @ClientID and led_blacklist.activo = 1 and led_blacklist.tipo_lista IN ('W')
ORDER BY EMPLEADO
/*
SELECT empleado, cuit_empleado, empleador_directo, isnull(cuit_empleador_directo,0) as cuit_empleador_directo, isnull(contratista_principal,0) as contratista_principal,
isnull(cuit_contratista_principal,0) as cuit_contratista_principal,
CONVERT(VARCHAR(10),getdate()+1, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+1, 108) as vigencia_excepcion
, estado_ingreso, locacion,
CONVERT(VARCHAR(10),isnull(fecha_maxima_ingreso,getdate()), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
FROM Digicard
*/
/*
SELECT led_tipos_contratista.nombre_tipo_contratista,
padrones.nombre_persona as empleado, padrones.identificacion as cuit_empleado,
padrones_1.nombre_persona AS empleador_directo, padrones_1.identificacion AS cuit_empleador_directo,
null AS contratista_principal,null AS cuit_contratista_principal,
/*
led_control_ingreso.vigencia_excepcion
*/
getdate() + 1 as vigencia_excepcion
, 'V' AS estado_ingreso,'0' as locacion,
getdate() + 43 as fecha_maxima_ingreso
FROM led_contratistas INNER JOIN
led_empleados ON led_empleados.contratista = led_contratistas.contratista INNER JOIN
padrones ON led_empleados.id_padron = padrones.id_padron INNER JOIN
padrones AS padrones_1 ON led_contratistas.id_padron = padrones_1.id_padron
inner join led_tipos_contratista on led_contratistas.tipo_contratista = led_tipos_contratista.tipo_contratista
inner join led_tipos_empleado on led_empleados.tipo_empleado = led_tipos_empleado.tipo_empleado
left JOIN led_control_ingreso ON led_empleados.empleado = led_control_ingreso.empleado
LEFT join led_locaciones on led_locaciones.locacion = led_control_ingreso.locacion
where led_contratistas.cliente = 9335603
and led_control_ingreso.
order by padrones.nombre_persona asc
exec [Imperium_Digicard_Response] 9335603
select * from led_blacklist
SELECT empleado, cuit_empleado, empleador_directo, isnull(cuit_empleador_directo,0) as cuit_empleador_directo, isnull(contratista_principal,0) as contratista_principal,
isnull(cuit_contratista_principal,0) as cuit_contratista_principal,
CONVERT(VARCHAR(10),getdate()+1, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+1, 108) as vigencia_excepcion
, estado_ingreso, locacion,
CONVERT(VARCHAR(10),isnull(fecha_maxima_ingreso,getdate()), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
9335603 as cliente,
CONVERT(VARCHAR(10),getdate()+0010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0010, 108) as habilitado_proxima_consulta
FROM Digicard
/*
iif(LC.estado_contratista='A','A','B') AS ACTIVO,
TC.nombre_tipo_contratista AS NOMBRE_TIPO_CONTRATISTA,
*/
/*
SELECT empleado, cuit_empleado, empleador_directo, isnull(cuit_empleador_directo,0) as cuit_empleador_directo, isnull(contratista_principal,0) as contratista_principal,
isnull(cuit_contratista_principal,0) as cuit_contratista_principal,
CONVERT(VARCHAR(10),getdate()+1, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+1, 108) as vigencia_excepcion
, estado_ingreso, locacion,
CONVERT(VARCHAR(10),isnull(fecha_maxima_ingreso,getdate()), 103) + ' ' + CONVERT(VARCHAR(8),'23:59:59', 108) as fecha_maxima_ingreso,
@ClientID as cliente,
CONVERT(VARCHAR(10),getdate()+0.010, 103) + ' ' + CONVERT(VARCHAR(8),getdate()+0.010, 108) as habilitado_proxima_consulta
FROM Digicard
*/
*/
end
GO
Depends On
24- dbo.PeriodoAdelantado
- dbo.docs
- dbo.empleados
- dbo.led_blacklist
- dbo.led_cliente_contratista
- dbo.led_cliente_empleado
- dbo.led_contratista_locaciones
- dbo.led_contratista_multi
- dbo.led_contratista_periodo
- dbo.led_contratistas
- dbo.led_control_ingreso
- dbo.led_digicard_emp_temp
- dbo.led_digicard_temp
- dbo.led_docs
- dbo.led_empleado_locaciones
- dbo.led_empleado_multi
- dbo.led_empleados
- dbo.led_empleados_periodo
- dbo.led_locaciones
- dbo.led_subcontratista_periodo
- dbo.led_tipos_contratista
- dbo.led_tipos_doc
- dbo.led_tipos_empleado
- dbo.padrones
Used By
No items found