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_edad | 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_edad decimal(10,2)
EXEC [dbo].[LN_score_formal_edad] 1, @score_edad output
select @score_edad as score_edad
select * from ln_contrapartes where id_padron = (select id_padron from padrones where identificacion = '30500007539')
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_formal_edad_SIN_USO
@contraparte int,
@score_edad 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 = 'AprobacionFormales')
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_edad = null
return
end
*/
set @puntaje = 100
declare @fecha_defuncion date = null
declare @edad int = null
declare @defuncion bit = null
declare @p_menor int = null
declare @p_mayor int = null
declare @p_puntos_menor decimal(5,2) = null
declare @p_puntos_mayor decimal(5,2) = null
--> buscamos si está personalizado en la tabla ln_dias_alertas (en el campo dias la edad esta en años)
select @p_menor = dias,
@p_puntos_menor = puntos
from ln_dias_alertas where tabla = 'menor' and cliente = @cliente
if (@p_menor is null) set @p_menor = 25 -- default 25 años
if (@p_puntos_menor is null) set @p_puntos_menor = 50 -- default 50% por menor de 25
select @p_mayor = dias,
@p_puntos_mayor = puntos
from ln_dias_alertas where tabla = 'mayor' and cliente = @cliente
if (@p_mayor is null) set @p_mayor = 65 -- default 65 años
if (@p_puntos_mayor is null) set @p_puntos_mayor = 50 -- default 50% por por mayor de 65
--> Muerto o menor de 18 años siempre rechazo
select @fecha_defuncion = fecha_defuncion, @defuncion = ISNULL(defuncion,0),
@edad = (cast(datediff(dd,c02_fecha_nac,GETDATE()) / 365.25 as int))
from DATOS_PERSONAS
where c01_cuit = @cuit
select @edad
if (@fecha_defuncion is not null or @defuncion = 1)
begin
set @puntaje = -100
set @detalle = 'PERSONA FALLECIDA'
end
if (@puntaje != -100)
begin
if (@edad is not null and @edad < 18)
begin
set @puntaje = -100
set @detalle = 'PERSONA MENOR DE 18 AÑOS'
end
end
if (@puntaje != -100)
begin
if (@edad is not null and @edad < @p_menor)
begin
set @puntaje = @p_puntos_menor
if (@puntaje = -100)
set @detalle = 'PERSONA MENOR DE ' + CONVERT(varchar, @p_menor) + ' AÑOS'
end
end
if (@puntaje != -100)
begin
if (@edad is not null and @edad > @p_mayor)
begin
set @puntaje = @p_puntos_mayor
if (@puntaje = -100)
set @detalle = 'PERSONA MAYOR DE ' + CONVERT(varchar, @p_mayor) + ' AÑOS'
end
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_edad = @puntaje
END
GO
GO
/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <19/03/2019>
-- Description: Cálculo de Score de alertas
-- =============================================
DECLARE @score_edad decimal(10,2)
EXEC [dbo].[LN_score_formal_edad] 1, @score_edad output
select @score_edad as score_edad
select * from ln_contrapartes where id_padron = (select id_padron from padrones where identificacion = '30500007539')
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_formal_edad_SIN_USO
@contraparte int,
@score_edad 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 = 'AprobacionFormales')
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_edad = null
return
end
*/
set @puntaje = 100
declare @fecha_defuncion date = null
declare @edad int = null
declare @defuncion bit = null
declare @p_menor int = null
declare @p_mayor int = null
declare @p_puntos_menor decimal(5,2) = null
declare @p_puntos_mayor decimal(5,2) = null
--> buscamos si está personalizado en la tabla ln_dias_alertas (en el campo dias la edad esta en años)
select @p_menor = dias,
@p_puntos_menor = puntos
from ln_dias_alertas where tabla = 'menor' and cliente = @cliente
if (@p_menor is null) set @p_menor = 25 -- default 25 años
if (@p_puntos_menor is null) set @p_puntos_menor = 50 -- default 50% por menor de 25
select @p_mayor = dias,
@p_puntos_mayor = puntos
from ln_dias_alertas where tabla = 'mayor' and cliente = @cliente
if (@p_mayor is null) set @p_mayor = 65 -- default 65 años
if (@p_puntos_mayor is null) set @p_puntos_mayor = 50 -- default 50% por por mayor de 65
--> Muerto o menor de 18 años siempre rechazo
select @fecha_defuncion = fecha_defuncion, @defuncion = ISNULL(defuncion,0),
@edad = (cast(datediff(dd,c02_fecha_nac,GETDATE()) / 365.25 as int))
from DATOS_PERSONAS
where c01_cuit = @cuit
select @edad
if (@fecha_defuncion is not null or @defuncion = 1)
begin
set @puntaje = -100
set @detalle = 'PERSONA FALLECIDA'
end
if (@puntaje != -100)
begin
if (@edad is not null and @edad < 18)
begin
set @puntaje = -100
set @detalle = 'PERSONA MENOR DE 18 AÑOS'
end
end
if (@puntaje != -100)
begin
if (@edad is not null and @edad < @p_menor)
begin
set @puntaje = @p_puntos_menor
if (@puntaje = -100)
set @detalle = 'PERSONA MENOR DE ' + CONVERT(varchar, @p_menor) + ' AÑOS'
end
end
if (@puntaje != -100)
begin
if (@edad is not null and @edad > @p_mayor)
begin
set @puntaje = @p_puntos_mayor
if (@puntaje = -100)
set @detalle = 'PERSONA MAYOR DE ' + CONVERT(varchar, @p_mayor) + ' AÑOS'
end
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_edad = @puntaje
END
GO
Depends On
10Used By
No items found