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_BL | 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
-- =============================================
select * from LN_control_black_list where visible = 1
DECLARE @score_BL decimal(10,2)
EXEC [dbo].[LN_score_blackList] 107, @score_BL output
select @score_BL as score_BL
select * from ln_contrapartes where id_padron = (select id_padron from padrones where identificacion = '30500007539')
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_blackList
@contraparte int,
@score_BL decimal(10,2) = null output
AS
BEGIN
SET NOCOUNT ON;
declare @puntaje decimal(10,2) = 100
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 = 'AprobacionBlackList'
declare @tiene_indicador int = (select COUNT(*) from LN_cliente_indicadores where cliente = @cliente and indicador = @indicador)
if (@tiene_indicador = 0)
begin
select @indicador = indicador, @etiqueta = LN_productos.etiqueta
from ln_indicadores
inner join LN_productos on ln_productos.producto = LN_indicadores.producto
where clave_indicador = 'score_blacklist'
set @tiene_indicador = (select COUNT(*) from LN_cliente_indicadores where cliente = @cliente and indicador = @indicador)
end
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_BL = null
return
end
*/
set @puntaje = 100
if exists(select * from LN_control_black_list
where cliente = @cliente
and identificacion = @cuit
and visible = 1
and ISNULL(vigencia_desde, '1901-01-01') < GETDATE()
and ISNULL(vigencia_hasta, '2099-12-31') > GETDATE())
begin
set @puntaje = -100
set @detalle = 'BLACK LIST'
end
if (@puntaje != -100 and @puntaje != 100) -- Por si se personaliza que de otro puntaje
begin
set @detallep = 'BLACK LIST'
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
-- Detalle Puntos
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
set @score_BL = @puntaje
END
GO
GO
/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <19/03/2019>
-- Description: Cálculo de Score de alertas
-- =============================================
select * from LN_control_black_list where visible = 1
DECLARE @score_BL decimal(10,2)
EXEC [dbo].[LN_score_blackList] 107, @score_BL output
select @score_BL as score_BL
select * from ln_contrapartes where id_padron = (select id_padron from padrones where identificacion = '30500007539')
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_blackList
@contraparte int,
@score_BL decimal(10,2) = null output
AS
BEGIN
SET NOCOUNT ON;
declare @puntaje decimal(10,2) = 100
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 = 'AprobacionBlackList'
declare @tiene_indicador int = (select COUNT(*) from LN_cliente_indicadores where cliente = @cliente and indicador = @indicador)
if (@tiene_indicador = 0)
begin
select @indicador = indicador, @etiqueta = LN_productos.etiqueta
from ln_indicadores
inner join LN_productos on ln_productos.producto = LN_indicadores.producto
where clave_indicador = 'score_blacklist'
set @tiene_indicador = (select COUNT(*) from LN_cliente_indicadores where cliente = @cliente and indicador = @indicador)
end
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_BL = null
return
end
*/
set @puntaje = 100
if exists(select * from LN_control_black_list
where cliente = @cliente
and identificacion = @cuit
and visible = 1
and ISNULL(vigencia_desde, '1901-01-01') < GETDATE()
and ISNULL(vigencia_hasta, '2099-12-31') > GETDATE())
begin
set @puntaje = -100
set @detalle = 'BLACK LIST'
end
if (@puntaje != -100 and @puntaje != 100) -- Por si se personaliza que de otro puntaje
begin
set @detallep = 'BLACK LIST'
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
-- Detalle Puntos
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
set @score_BL = @puntaje
END
GO
Depends On
10Used By
11- dbo.LN_dashboard_cliente
- dbo.LN_dashboard_cliente_0822
- dbo.LN_dashboard_cliente_13052020
- dbo.LN_dashboard_cliente_2020
- dbo.LN_dashboard_cliente_20200403
- dbo.LN_dashboard_cliente_2024
- dbo.LN_dashboard_cliente_21-08-2022-AGB
- dbo.LN_dashboard_cliente_AB
- dbo.LN_dashboard_cliente_AGB
- dbo.LN_dashboard_cliente_MIS
- dbo.LN_dashboard_cliente_ppp