dbo.LN_score_fiscales_16082023

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@contraparte int 4
@score_fiscal decimal 9

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <19/03/2019>
-- Description: Cálculo de Score de alertas
-- =============================================
DECLARE @score_fiscal decimal(10,2)
EXEC [dbo].[LN_score_fiscales] 31280, @score_fiscal output
select @score_fiscal as score_fiscal
select * from ln_contrapartes where id_padron = (select id_padron from padrones where identificacion = '30500007539')
*/

CREATE OR ALTER PROCEDURE dbo.LN_score_fiscales_16082023 
  @contraparte int,
  @score_fiscal decimal(10,2) = null output
AS
BEGIN
 SET NOCOUNT ON;
 declare @puntaje decimal(10,2) = null
 declare @detalle varchar(max) = null
 declare @detallep varchar(max) = null
 declare @cuit varchar(20) = (select identificacion from padrones where id_padron = (select id_padron from ln_contrapartes where contraparte = @contraparte))
 declare @cliente int = (select cliente from ln_contrapartes where contraparte = @contraparte)

 declare @gestion int = (select gestion 
       from LN_gestiones 
       where contraparte = @contraparte 
         AND LN_gestiones.desde <= GETDATE()
       AND LN_gestiones.hasta >= GETDATE())
 declare @indicador int = null
 declare @etiqueta varchar(100) = null

 select @indicador = indicador, @etiqueta = LN_productos.etiqueta
           from ln_indicadores 
        inner join LN_productos on ln_productos.producto = LN_indicadores.producto 
        where clave_indicador = 'AprobacionFiscales'
 declare @tiene_indicador int  = (select COUNT(*) from LN_cliente_indicadores where cliente = @cliente and indicador = @indicador)

 if (exists (select * From ln_score_detalle_killer
     where contraparte = @contraparte 
       and gestion = @gestion 
       and indicador = @indicador
       and visible = 1)
  and @tiene_indicador = 0)
 begin
  update ln_score_detalle_killer set visible = 0, modified = GETDATE()
   where contraparte = @contraparte 
     and gestion = @gestion 
     and indicador = @indicador
     and visible = 1
 end 

 if (exists (select * From ln_score_detalle_puntos
     where contraparte = @contraparte 
       and gestion = @gestion 
       and indicador = @indicador
       and visible = 1)
  and @tiene_indicador = 0)
 begin
  update ln_score_detalle_puntos set visible = 0, modified = GETDATE()
   where contraparte = @contraparte 
     and gestion = @gestion 
     and indicador = @indicador
     and visible = 1
 end 

 if (exists (select * From LN_contraparte_indicadores
     where contraparte = @contraparte 
       and gestion = @gestion 
       and indicador = @indicador
       and visible = 1)
  and @tiene_indicador = 0)
 begin 
  update LN_contraparte_indicadores set visible = 0, modified = GETDATE()
   where contraparte = @contraparte 
     and gestion = @gestion 
     and indicador = @indicador
     and visible = 1
 end 
 /*
  if  (@tiene_indicador = 0)
  begin
  set @score_fiscal = null
  return 
  end 
  */
 
 set @puntaje = 100 

 if exists (select * from apocrifas where cuit = @cuit and visible = 1) 
  begin
   set @puntaje = -100
   set @detalle = 'POSEE FACTURAS APOCRIFAS'
  end 

 if exists (select * from padron_sin_constancia
             where id_padron = (select id_padron from ln_contrapartes where contraparte = @contraparte)
               and ( texto_constancia like 'Codigo postal erroneo%'
      or 
      texto_constancia like 'Debe responder requerimientos pendientes%'
      or 
      texto_constancia like 'Domicilio Incompleto%'
      or 
      texto_constancia like 'Estado erroneo del domicilio%'
      or 
      texto_constancia like 'La CUIT del contribuyente fue limitada en los términos de la RG AFIP 3832/16%'
      or 
      texto_constancia like 'No consta en nuestros registros que Ud. ha cumplido con la adhesión al domicilio fiscal electrónico%'
      or 
      texto_constancia like 'No tiene dependencia informada%'
      or 
      texto_constancia like 'No tiene localidad%'
      or 
      texto_constancia like 'Si no tiene calle%'))
  begin 
    if (@puntaje != -100) 
    begin
    set @puntaje = 75
    set @detallep = 'PROBLEMAS CON LA CONSTANCIA DE AFIP'
    end 
  end

  
 if exists (select * from padron_sin_constancia
             where id_padron = (select id_padron from ln_contrapartes where contraparte = @contraparte)
               and (texto_constancia like 'Actividad economica principal inexistente%' 
      or
      texto_constancia like 'El contribuyente cuenta con impuestos con baja de oficio por Decreto%'
      or 
      texto_constancia like 'Falta AR%sus datos biometricos%'
      or 
      texto_constancia like 'Nombre erroneo%'
      or 
      texto_constancia like 'PASIVO DECRETO 1299/98%'
      or 
      texto_constancia like 'Sr. Contribuyente%AFIP Nro. 3537/13%')
     ) 
  begin 
    if (@puntaje != -100) 
    begin
   set @puntaje = 50
   set @detallep = 'PROBLEMAS CON LA CONSTANCIA DE AFIP'
    end
  end

 if exists (select * from padron_sin_constancia
             where id_padron = (select id_padron from ln_contrapartes where contraparte = @contraparte)
               and (texto_constancia like 'La CUIT fue cancelada %' 
      or
      texto_constancia like 'La cuit ingresada se encuentra inactiva%'
      or 
      texto_constancia like 'Tu Constancia se encuentra bloqueada%'
      or 
      texto_constancia like 'Documento erroneo%')
     ) 
  begin 
    set @puntaje = -100
    if (@detalle is null) 
    set @detalle = 'LA CUIT FUE CANCELADA'
    else 
    set @detalle = @detalle + '; LA CUIT FUE CANCELADA'
  end



 
-- Detalle Killers 
 if  (@tiene_indicador != 0)
 BEGIN
  if exists (select * From ln_score_detalle_killer
     where contraparte = @contraparte 
       and gestion = @gestion 
       and indicador = @indicador
       and detalle_killer != isnull(@detalle,'')
       and visible = 1)
   UPDATE LN_score_detalle_killer
      set visible = 0, modified = getdate()
    where contraparte = @contraparte 
      and gestion = @gestion 
      and indicador = @indicador

  if (@detalle is not null) 
  begin
   if not exists (select * From ln_score_detalle_killer
      where contraparte = @contraparte 
        and gestion = @gestion 
        and indicador = @indicador
        and detalle_killer = isnull(@detalle,'')
        and visible = 1)
      insert into ln_score_detalle_killer
      (contraparte, gestion, indicador, detalle_killer, visible, created)
      values (@contraparte, @gestion, @indicador, @detalle, 1, getdate()) 
  end 
  
  if (@detallep is not null) 
   set @detallep = isnull(@etiqueta, '') + ': ' + @detallep
  
  if exists (select * From ln_score_detalle_puntos
     where contraparte = @contraparte 
       and gestion = @gestion 
       and indicador = @indicador
       and detalle != isnull(@detallep,'')
       and visible = 1)
   UPDATE LN_score_detalle_puntos
      set visible = 0, modified = getdate()
    where contraparte = @contraparte 
      and gestion = @gestion 
      and indicador = @indicador

  if (@detallep is not null) 
  begin
   if not exists (select * From ln_score_detalle_puntos
      where contraparte = @contraparte 
        and gestion = @gestion 
        and indicador = @indicador
        and detalle = isnull(@detallep,'')
        and visible = 1)
      insert into ln_score_detalle_puntos
      (contraparte, gestion, indicador, detalle, visible, created)
      values (@contraparte, @gestion, @indicador, @detallep, 1, getdate()) 
  end 
 end 
 set @score_fiscal =  @puntaje

END

GO

Used By

No items found