dbo.ws_tiene_bcra

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

CREATE OR ALTER PROCEDURE dbo.ws_tiene_bcra
@p_Cuit varchar(20)

/*

Para que la deuda sea visible
1) tiene que fijarse que no exista otro registro con la misma entidad/mes con 
   id_fuente = '2' (son los que cargan los usuarios por staff, si despues viene del Bcra tiene, ese del bcra no lo tiene que tomar)
2) No puede ser de mas de 5 años
3) Si esta cancelada, no puede ser de mas de 2 años
4) Si no se cargo mas deuda para el mismo banco en los ultimos 3 meses, no puede ser de mas de 2 años

Para considerar que tiene Deuda, toma solo deudas en situacion mayor que 1

*/


AS
BEGIN
    SET NOCOUNT ON;
 DECLARE @cantidad int = 0 

/* 
declare @p_5anios date = getdate() - (5*365)
declare @p_2anios date = getdate() - (2*365)
declare @p_3meses date = getdate() - (90)
declare @cant_central_deudores int = 0
declare @tiene_bcra    char(1)


set @cantidad = (SELECT count(distinct(cast(codigo_ent as int)))

  from cendeu
 where cendeu.iden = @p_Cuit
   and cendeu.vigente = '1' 
   and convert(int,cendeu.situacion) > 1 
   and not exists (select * from cendeu b where b.iden = cendeu.iden and cast(b.codigo_ent as int) = cast(cendeu.codigo_ent as int) and b.fec_inf = cendeu.fec_inf and b.vigente = '1' and b.id_fuente = '2' and b.id_cendeu != cendeu.id_cendeu)
   and not 
   (
  (cast(fec_inf+'01' as date) < @p_5anios) 
  OR
  (cast(fec_inf+'01' as date) < @p_2anios 
and 
not exists (select * from cendeu c where c.iden = cendeu.iden and cast(c.codigo_ent as int) = cast(cendeu.codigo_ent as int) and c.vigente = '1' and (convert(date,c.created) > @p_3meses))
  )
  OR 
  (cast(fec_inf+'01' as date) < @p_2anios 
   and 
   exists (select * from cendeu_cancela c 
where c.iden = cendeu.iden 
  and cast(c.codigo_ent as int) = cast(cendeu.codigo_ent as int) 
  and cast(fec_inf+'01' as date) between convert(date,c.fec_inf_desde) and convert(date,c.fec_inf_hasta)
  and c.vigente = '1')
  )
   )
 )
 */

 /*
  declare @dtStart date, @dtEnd date, @dtEnd_cuit date,@periodo_maximo varchar(7),@fec_periodo_minimo varchar(11),@periodo_minimo varchar(7);
 
  select @dtEnd = (select max(fecha_informacion) from fuentes_procesadas where visible = '1')
 
  select @dtEnd_cuit = convert(date,isnull(max(cendeu.fec_inf),'200112')+'01') from cendeu where iden = @p_cuit
 
  if (@dtEnd_cuit > @dtEnd) 
  begin 
     set @dtEnd = @dtEnd_cuit
  end 
  set @dtStart = dateadd(month,-23, @dtEnd)
  set @periodo_maximo = replace(Convert(varchar(7),@dtEnd),'-','')
  set @fec_periodo_minimo = @dtStart
  set @periodo_minimo = replace(Convert(varchar(7),@dtStart),'-','')
  set @dtStart = dateadd(month,-23, @dtEnd)
  if (@periodo_maximo is not null)
  begin
    set @fec_periodo_minimo = dateadd(MM, -24,convert(date,@periodo_maximo+'01'))
    set @periodo_minimo = convert(varchar(4),DATEPART(yyyy,@fec_periodo_minimo))+right('0'+convert(varchar(2),DATEPART(mm,@fec_periodo_minimo)),2)
      end
  set @cantidad = (SELECT count(distinct(cast(codigo_ent as int)))
           from cendeu
      where cendeu.iden = @p_Cuit
      and cendeu.vigente = '1' 
      and convert(int,cendeu.situacion) > 1 
      and cendeu.fec_inf between @periodo_minimo and @periodo_maximo   
                     and not exists (select * from cendeu b 
          where b.iden = cendeu.iden and cast(b.codigo_ent as int) = cast(cendeu.codigo_ent as int)
           and b.fec_inf = cendeu.fec_inf 
        and b.vigente = 1 
     and b.id_fuente = 2 
     and b.id_cendeu != cendeu.id_cendeu)
  )
 
 
    return @cantidad
    */


   declare @entrada table (cod int, nombre_corto varchar(100), nombre varchar(100), mes_1 char(7), mes_2 char(7), sit int, situacion char(26), max_monto char(15), ult_monto char(15))
   -- Recorro las morosidades que se mostraran  
   insert into @entrada 
  exec ws_obtener_cuadro_bcra @p_Cuit
  
   set  @cantidad = (SELECT count(*) FROM @entrada where sit > 1) 
   return @cantidad
 
       
END

GO

Used By

No items found