Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_Cuit | varchar | 20 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
exec [api_info_afip_cuit_new] '20000591441'
select * from datos_personas where c01_cuit = '27000591446'
select * from padrones where cuerpo_clave = '00059144'
*/
CREATE OR ALTER PROCEDURE dbo.api_info_afip_cuit_new
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
declare @fecha_nacimiento varchar(10) = null
declare @fecha_defuncion varchar(10) = null
declare @defuncion varchar(2) = null
declare @estado_iva varchar(2) = null
/* MIS 23/07/2021: Si no tenemos la fecha de nacimiento la buscamos en la tabla auxiliar de empleados y la grabamos */
declare @fecha_nac date = null
select @fecha_nac = c02_fecha_nac from DATOS_PERSONAS where c01_cuit = @p_Cuit and visible = 1
if (@fecha_nac is null)
begin
select @fecha_nac = FECHADENACIMIENTO from empleados_202102B where CUIL = @p_Cuit
if (@fecha_nac is not null)
update DATOS_PERSONAS set c02_fecha_nac = @fecha_nac
where c01_cuit = @p_Cuit and visible = 1
end
declare @dni varchar(8) = null, @sexo char(1) = null
select @dni = RIGHT('00000000'+cuerpo_clave,8) , @sexo = upper(sexo)
from padrones where identificacion = @p_Cuit and habilitado = 1
if (@sexo != 'F' and @sexo != 'M') or @sexo is null
begin
if (@p_Cuit like '27%') set @sexo = 'F'
if (@p_Cuit like '20%') set @sexo = 'M'
end
declare @buscar_fecha bit = 0
/* AGB 22/7/2021
select @fecha_nacimiento = iif(c02_fecha_nac is not null,c02_fecha_nac,iif(empleados_202102B.FECHADENACIMIENTO is not null,convert(varchar(10),empleados_202102B.FECHADENACIMIENTO),iif(c02_anio_nac is not null and c02_anio_nac != '',cast (c02_anio_nac + '-' + convert(varchar(2),MONTH(getdate())) + '-' + convert(varchar(2),DAY(getdate())) as date),null))),
@fecha_defuncion = convert(varchar,fecha_defuncion),
@defuncion = iif(isnull(defuncion,0)=1,'SI','NO'),
from DATOS_PERSONAS left join empleados_202102B
on DATOS_PERSONAS.c01_cuit = empleados_202102B.CUIL
where c01_cuit = @p_Cuit
and visible = 1
MIS 23/07/2021: Ya se completo antes el campo c02_fecha_nac si lo tenia en la tabla auxiliar de empleados
*/
select @fecha_nacimiento = iif(c02_fecha_nac is not null,c02_fecha_nac,iif(c02_anio_nac is not null and c02_anio_nac != '',cast (c02_anio_nac + '-' + convert(varchar(2),MONTH(getdate())) + '-' + convert(varchar(2),DAY(getdate())) as date),null)),
@fecha_defuncion = convert(varchar,fecha_defuncion),
@defuncion = iif(isnull(defuncion,0)=1,'SI','NO'),
@buscar_fecha = IIF (c02_fecha_nac is null,1,0)
from DATOS_PERSONAS
where c01_cuit = @p_Cuit
and visible = 1
/*
Responsable Inscripto:
Si fue a afip en los últimos 60 días:
- Busca IVA en la tabla de impuestos afip
Si no fue a afip en los últimos 60 días:
- Busca en la tabla inscripciones
*/
if (SELECT max(fecha) as fecha from servicios_externos_cuits_consultados where identificacion = @p_cuit and servicio = 'AFIP') >= DATEADD(day,-60,getdate())
begin
select top 1 @estado_iva = iif(isnull(estado,'')='ACTIVO','SI','NO')
from padron_impuestos
where id_padron in (select top 1 id_padron from padrones where identificacion = @p_Cuit and habilitado = 1
and identificador in(select identificador from identificadores where country_code = 'AR'))
and codigo_impuesto = 30
and created >= DATEADD(day,-60,getdate())
order by created desc
end
else
begin
select top 1 @estado_iva = iif(isnull(imp_iva,'')='AC','SI','NO')
from inscripciones
where cuit = @p_Cuit
order by created desc
end
if (@estado_iva is null) set @estado_iva = 'NO'
if (@fecha_defuncion is not null) set @defuncion = 'SI'
declare @monotributo varchar(20) = null
set @monotributo = (select top 1 impuestos.nombre_impuesto
from padron_impuestos a
inner join impuestos on impuestos.codigo_impuesto = a.codigo_impuesto
where id_padron = (select top 1 id_padron from padrones
WHERE padrones.identificacion = @p_Cuit
and habilitado = 1)
and ISNULL(estado,'') = 'ACTIVO'
and a.codigo_impuesto = 20
order by a.created desc )
if (@monotributo is null) set @monotributo = 'NO'
else set @monotributo = 'SI'
select @estado_iva as responsable_inscripto,
@monotributo as monotributo,
isnull(@fecha_nacimiento,'') as fecha_nacimiento,
isnull(@fecha_defuncion,'') as fecha_defuncion,
isnull(@defuncion,'NO') as persona_fallecida,
@buscar_fecha as buscar_fecha_nac,
@dni as dni,
@sexo as sexo
END
GO
GO
/*
exec [api_info_afip_cuit_new] '20000591441'
select * from datos_personas where c01_cuit = '27000591446'
select * from padrones where cuerpo_clave = '00059144'
*/
CREATE OR ALTER PROCEDURE dbo.api_info_afip_cuit_new
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
declare @fecha_nacimiento varchar(10) = null
declare @fecha_defuncion varchar(10) = null
declare @defuncion varchar(2) = null
declare @estado_iva varchar(2) = null
/* MIS 23/07/2021: Si no tenemos la fecha de nacimiento la buscamos en la tabla auxiliar de empleados y la grabamos */
declare @fecha_nac date = null
select @fecha_nac = c02_fecha_nac from DATOS_PERSONAS where c01_cuit = @p_Cuit and visible = 1
if (@fecha_nac is null)
begin
select @fecha_nac = FECHADENACIMIENTO from empleados_202102B where CUIL = @p_Cuit
if (@fecha_nac is not null)
update DATOS_PERSONAS set c02_fecha_nac = @fecha_nac
where c01_cuit = @p_Cuit and visible = 1
end
declare @dni varchar(8) = null, @sexo char(1) = null
select @dni = RIGHT('00000000'+cuerpo_clave,8) , @sexo = upper(sexo)
from padrones where identificacion = @p_Cuit and habilitado = 1
if (@sexo != 'F' and @sexo != 'M') or @sexo is null
begin
if (@p_Cuit like '27%') set @sexo = 'F'
if (@p_Cuit like '20%') set @sexo = 'M'
end
declare @buscar_fecha bit = 0
/* AGB 22/7/2021
select @fecha_nacimiento = iif(c02_fecha_nac is not null,c02_fecha_nac,iif(empleados_202102B.FECHADENACIMIENTO is not null,convert(varchar(10),empleados_202102B.FECHADENACIMIENTO),iif(c02_anio_nac is not null and c02_anio_nac != '',cast (c02_anio_nac + '-' + convert(varchar(2),MONTH(getdate())) + '-' + convert(varchar(2),DAY(getdate())) as date),null))),
@fecha_defuncion = convert(varchar,fecha_defuncion),
@defuncion = iif(isnull(defuncion,0)=1,'SI','NO'),
from DATOS_PERSONAS left join empleados_202102B
on DATOS_PERSONAS.c01_cuit = empleados_202102B.CUIL
where c01_cuit = @p_Cuit
and visible = 1
MIS 23/07/2021: Ya se completo antes el campo c02_fecha_nac si lo tenia en la tabla auxiliar de empleados
*/
select @fecha_nacimiento = iif(c02_fecha_nac is not null,c02_fecha_nac,iif(c02_anio_nac is not null and c02_anio_nac != '',cast (c02_anio_nac + '-' + convert(varchar(2),MONTH(getdate())) + '-' + convert(varchar(2),DAY(getdate())) as date),null)),
@fecha_defuncion = convert(varchar,fecha_defuncion),
@defuncion = iif(isnull(defuncion,0)=1,'SI','NO'),
@buscar_fecha = IIF (c02_fecha_nac is null,1,0)
from DATOS_PERSONAS
where c01_cuit = @p_Cuit
and visible = 1
/*
Responsable Inscripto:
Si fue a afip en los últimos 60 días:
- Busca IVA en la tabla de impuestos afip
Si no fue a afip en los últimos 60 días:
- Busca en la tabla inscripciones
*/
if (SELECT max(fecha) as fecha from servicios_externos_cuits_consultados where identificacion = @p_cuit and servicio = 'AFIP') >= DATEADD(day,-60,getdate())
begin
select top 1 @estado_iva = iif(isnull(estado,'')='ACTIVO','SI','NO')
from padron_impuestos
where id_padron in (select top 1 id_padron from padrones where identificacion = @p_Cuit and habilitado = 1
and identificador in(select identificador from identificadores where country_code = 'AR'))
and codigo_impuesto = 30
and created >= DATEADD(day,-60,getdate())
order by created desc
end
else
begin
select top 1 @estado_iva = iif(isnull(imp_iva,'')='AC','SI','NO')
from inscripciones
where cuit = @p_Cuit
order by created desc
end
if (@estado_iva is null) set @estado_iva = 'NO'
if (@fecha_defuncion is not null) set @defuncion = 'SI'
declare @monotributo varchar(20) = null
set @monotributo = (select top 1 impuestos.nombre_impuesto
from padron_impuestos a
inner join impuestos on impuestos.codigo_impuesto = a.codigo_impuesto
where id_padron = (select top 1 id_padron from padrones
WHERE padrones.identificacion = @p_Cuit
and habilitado = 1)
and ISNULL(estado,'') = 'ACTIVO'
and a.codigo_impuesto = 20
order by a.created desc )
if (@monotributo is null) set @monotributo = 'NO'
else set @monotributo = 'SI'
select @estado_iva as responsable_inscripto,
@monotributo as monotributo,
isnull(@fecha_nacimiento,'') as fecha_nacimiento,
isnull(@fecha_defuncion,'') as fecha_defuncion,
isnull(@defuncion,'NO') as persona_fallecida,
@buscar_fecha as buscar_fecha_nac,
@dni as dni,
@sexo as sexo
END
GO
Depends On
8Used By
No items found