Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @fecha_desde_proceso | datetime | 8 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
Antes hay que pasar los registros de la tabla Sujetos_obligados_la_estrella (todos o con created >= a la fecha deseada)
por AFIP, para poder tener los Clae actualizados
insert into consultar_afip(proceso, cuit, fecha, procesado,prioridad)
select distinct 'ESTRELLA_BAJAS', identificacion, convert(date,getdate()), 0,2
from Sujetos_obligados_la_estrella s where /*s.created >= '2019-01-01'
and*/ not exists (select * from Sujetos_obligados_la_estrella_bajas b
where b.identificacion = s.identificacion
and b.created > s.created)
and not exists (select * from datos_personas p where p.c01_cuit = s.identificacion and p.fecha_defuncion is not null)
-- Para controlar como va el consultar_afip
select fecha, prioridad, procesado, count(*) as cantidad from consultar_afip
where proceso = 'ESTRELLA_BAJAS'
and fecha = (select max(fecha) from consultar_afip where proceso = 'ESTRELLA_BAJAS')
group by fecha, prioridad, procesado
select * from consultar_afip where proceso = 'ESTRELLA_BAJAS' and fecha = '2024-06-07' and ierror = 1
update consultar_afip set ierror = 0, procesado = 0 where proceso = 'ESTRELLA_BAJAS' and fecha = '2024-06-07' and ierror = 1
*/
CREATE OR ALTER PROCEDURE dbo.sp_la_estrella_bajas
@fecha_desde_proceso datetime = '1901-01-01'
-- Si se manda fecha, busca baja de los registros informados despues de esa fecha,
-- no se manda fecha, se buscan bajas de TODOS los registros informados en todos los procesos
AS
BEGIN
SET NOCOUNT ON;
declare @fecha date = getdate()
insert into Sujetos_obligados_la_estrella_bajas (cod_clae,nombre_persona,identificacion,tipo_persona,tipo_novedad,error, created)
select distinct s.cod_clae, p.nombre_persona, p.identificacion,
case (isnull(ltrim(rtrim(p.tipo_persona)),''))
when 'J' then 'J'
when 'F' then 'F'
else iif(p.identificacion like '3%','J','F')
end as tipo_persona,
'B' as tipo_novedad, '' as error, @fecha as fecha_proceso
from Sujetos_obligados_la_estrella s
inner join padrones p on p.identificacion = s.identificacion and p.habilitado = 1
and p.identificador in (select identificador from identificadores where country_code = 'AR')
where
s.created >= @fecha_desde_proceso
and not exists (select * from clae c where c.cuit = s.identificacion
and c.visible = 1
and c.formulario = 883
and c.cod_clae in (select cod_clae from /*clae_provincia_seguros*/ clae_la_estrella))
/* Esta parte era si se quieren saber los CUITs con error
and not exists (select * from padron_sin_constancia e where e.id_padron = p.id_padron)
union all
select distinct s.cod_clae, p.nombre_persona, p.identificacion,
case (isnull(ltrim(rtrim(p.tipo_persona)),''))
when 'J' then 'J'
when 'F' then 'F'
else iif(p.identificacion like '3%','J','F')
end as tipo_persona,
'E' as tipo_novedad,
case e.texto_constancia
when 'La cuit ingresada se encuentra inactiva. Acceda con su clave activa' then 'La cuit ingresada se encuentra inactiva.'
else 'La Constancia de Cuit se encuentra bloqueada'
end
as error, @fecha as fecha_proceso
from Sujetos_obligados_la_estrella s
inner join padrones p on p.identificacion = s.identificacion and p.habilitado = 1
and p.identificador in (select identificador from identificadores where country_code = 'AR')
inner join padron_sin_constancia e on e.id_padron = p.id_padron
where e.texto_constancia != 'La clave ingresada no es una CUIT'
*/
/* Excel a enviar en csv.*/
--declare @fecha date = '2021-05-27'
select a.cod_clae, a.nombre_persona, a.identificacion,
a.tipo_persona, a.tipo_novedad
from Sujetos_obligados_la_estrella_bajas a
where a.created = @fecha
/* que no lo hayamos informado como bajas antes */
and not exists (select * from Sujetos_obligados_la_estrella_bajas b
where b.identificacion = a.identificacion /*and b.cod_clae = a.cod_clae*/ and b.created < a.created)
order by a.identificacion
/* Muertos
select distinct cod_clae, nombre_persona, identificacion, tipo_persona, p.fecha_defuncion
from Sujetos_obligados_la_estrella s
inner join datos_personas p on p.c01_cuit = s.identificacion
where p.fecha_defuncion is not null and p.visible = 1
*/
END
GO
GO
/*
Antes hay que pasar los registros de la tabla Sujetos_obligados_la_estrella (todos o con created >= a la fecha deseada)
por AFIP, para poder tener los Clae actualizados
insert into consultar_afip(proceso, cuit, fecha, procesado,prioridad)
select distinct 'ESTRELLA_BAJAS', identificacion, convert(date,getdate()), 0,2
from Sujetos_obligados_la_estrella s where /*s.created >= '2019-01-01'
and*/ not exists (select * from Sujetos_obligados_la_estrella_bajas b
where b.identificacion = s.identificacion
and b.created > s.created)
and not exists (select * from datos_personas p where p.c01_cuit = s.identificacion and p.fecha_defuncion is not null)
-- Para controlar como va el consultar_afip
select fecha, prioridad, procesado, count(*) as cantidad from consultar_afip
where proceso = 'ESTRELLA_BAJAS'
and fecha = (select max(fecha) from consultar_afip where proceso = 'ESTRELLA_BAJAS')
group by fecha, prioridad, procesado
select * from consultar_afip where proceso = 'ESTRELLA_BAJAS' and fecha = '2024-06-07' and ierror = 1
update consultar_afip set ierror = 0, procesado = 0 where proceso = 'ESTRELLA_BAJAS' and fecha = '2024-06-07' and ierror = 1
*/
CREATE OR ALTER PROCEDURE dbo.sp_la_estrella_bajas
@fecha_desde_proceso datetime = '1901-01-01'
-- Si se manda fecha, busca baja de los registros informados despues de esa fecha,
-- no se manda fecha, se buscan bajas de TODOS los registros informados en todos los procesos
AS
BEGIN
SET NOCOUNT ON;
declare @fecha date = getdate()
insert into Sujetos_obligados_la_estrella_bajas (cod_clae,nombre_persona,identificacion,tipo_persona,tipo_novedad,error, created)
select distinct s.cod_clae, p.nombre_persona, p.identificacion,
case (isnull(ltrim(rtrim(p.tipo_persona)),''))
when 'J' then 'J'
when 'F' then 'F'
else iif(p.identificacion like '3%','J','F')
end as tipo_persona,
'B' as tipo_novedad, '' as error, @fecha as fecha_proceso
from Sujetos_obligados_la_estrella s
inner join padrones p on p.identificacion = s.identificacion and p.habilitado = 1
and p.identificador in (select identificador from identificadores where country_code = 'AR')
where
s.created >= @fecha_desde_proceso
and not exists (select * from clae c where c.cuit = s.identificacion
and c.visible = 1
and c.formulario = 883
and c.cod_clae in (select cod_clae from /*clae_provincia_seguros*/ clae_la_estrella))
/* Esta parte era si se quieren saber los CUITs con error
and not exists (select * from padron_sin_constancia e where e.id_padron = p.id_padron)
union all
select distinct s.cod_clae, p.nombre_persona, p.identificacion,
case (isnull(ltrim(rtrim(p.tipo_persona)),''))
when 'J' then 'J'
when 'F' then 'F'
else iif(p.identificacion like '3%','J','F')
end as tipo_persona,
'E' as tipo_novedad,
case e.texto_constancia
when 'La cuit ingresada se encuentra inactiva. Acceda con su clave activa' then 'La cuit ingresada se encuentra inactiva.'
else 'La Constancia de Cuit se encuentra bloqueada'
end
as error, @fecha as fecha_proceso
from Sujetos_obligados_la_estrella s
inner join padrones p on p.identificacion = s.identificacion and p.habilitado = 1
and p.identificador in (select identificador from identificadores where country_code = 'AR')
inner join padron_sin_constancia e on e.id_padron = p.id_padron
where e.texto_constancia != 'La clave ingresada no es una CUIT'
*/
/* Excel a enviar en csv.*/
--declare @fecha date = '2021-05-27'
select a.cod_clae, a.nombre_persona, a.identificacion,
a.tipo_persona, a.tipo_novedad
from Sujetos_obligados_la_estrella_bajas a
where a.created = @fecha
/* que no lo hayamos informado como bajas antes */
and not exists (select * from Sujetos_obligados_la_estrella_bajas b
where b.identificacion = a.identificacion /*and b.cod_clae = a.cod_clae*/ and b.created < a.created)
order by a.identificacion
/* Muertos
select distinct cod_clae, nombre_persona, identificacion, tipo_persona, p.fecha_defuncion
from Sujetos_obligados_la_estrella s
inner join datos_personas p on p.c01_cuit = s.identificacion
where p.fecha_defuncion is not null and p.visible = 1
*/
END
GO
Depends On
6Used By
No items found