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_antiguedad] 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_antiguedad_SIN_USO
@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 @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 = (select indicador
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_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
declare @fecha_inicio_actividad date = null
declare @p_dias int = null
declare @p_puntos decimal(5,2) = null
--> buscamos si está personalizado en la tabla ln_dias_alertas
select @p_dias = dias,
@p_puntos = puntos
from ln_dias_alertas where tabla = 'antiguedad' and cliente = @cliente
if (@p_dias is null) set @p_dias = 720 -- default 720 dias, 2 años
if (@p_puntos is null) set @p_puntos = -100 -- default rechazo por antiguedad menor a dos años
-- fecha de inicio actividad toma la menor fecha de los impuestos
select @fecha_inicio_actividad = convert(varchar(50),min(fecha_inscripcion))
from padron_impuestos
where id_padron = (select id_padron from padrones where identificacion = @cuit and habilitado = 1)
and fecha_inscripcion != '1901-01-01'
declare @antiguedad_dias int = null
set @antiguedad_dias = DATEDIFF ( dd , @fecha_inicio_actividad , getdate())
--select @antiguedad_dias/360
if (@antiguedad_dias is not null and @antiguedad_dias < @p_dias)
begin
set @puntaje = @p_puntos
end
if (@puntaje = -100)
begin
set @detalle = 'ANTIGÜEDAD MENOR A ' + convert (varchar,(@p_dias / 360)) + ' AÑOS'
end
-- Detalle Killers
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
set @score_fiscal = @puntaje
END
GO
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_antiguedad] 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_antiguedad_SIN_USO
@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 @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 = (select indicador
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_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
declare @fecha_inicio_actividad date = null
declare @p_dias int = null
declare @p_puntos decimal(5,2) = null
--> buscamos si está personalizado en la tabla ln_dias_alertas
select @p_dias = dias,
@p_puntos = puntos
from ln_dias_alertas where tabla = 'antiguedad' and cliente = @cliente
if (@p_dias is null) set @p_dias = 720 -- default 720 dias, 2 años
if (@p_puntos is null) set @p_puntos = -100 -- default rechazo por antiguedad menor a dos años
-- fecha de inicio actividad toma la menor fecha de los impuestos
select @fecha_inicio_actividad = convert(varchar(50),min(fecha_inscripcion))
from padron_impuestos
where id_padron = (select id_padron from padrones where identificacion = @cuit and habilitado = 1)
and fecha_inscripcion != '1901-01-01'
declare @antiguedad_dias int = null
set @antiguedad_dias = DATEDIFF ( dd , @fecha_inicio_actividad , getdate())
--select @antiguedad_dias/360
if (@antiguedad_dias is not null and @antiguedad_dias < @p_dias)
begin
set @puntaje = @p_puntos
end
if (@puntaje = -100)
begin
set @detalle = 'ANTIGÜEDAD MENOR A ' + convert (varchar,(@p_dias / 360)) + ' AÑOS'
end
-- Detalle Killers
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
set @score_fiscal = @puntaje
END
GO
Depends On
10Used By
No items found