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_Pat | decimal | 9 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <03/08/2021>
-- Description: Cálculo de Score Patrominio
-- =============================================
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_patrimonio_16082023
@contraparte int,
@score_Pat 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 = 'AprobacionPatrominio'
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
set @puntaje = 100
declare @patrimonio decimal(20,2) = null
set @patrimonio = (select top 1 patrimonio from Balances_Contables
where cuit = @cuit
and estado = 'PUBLICADO'
and visible = 1
and year(fecha_balance) >= year(getdate()) - 6
order by fecha_balance desc)
if (@patrimonio < 0)
begin
set @puntaje = -100
set @detalle = 'PATRIMONIO NEGATIVO'
end
if (@puntaje != -100 and @puntaje != 100) -- Por si se personaliza que de otro puntaje
begin
set @detallep = 'PATRIMONIO NEGATIVO'
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_Pat = @puntaje
END
GO
GO
/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <03/08/2021>
-- Description: Cálculo de Score Patrominio
-- =============================================
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_patrimonio_16082023
@contraparte int,
@score_Pat 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 = 'AprobacionPatrominio'
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
set @puntaje = 100
declare @patrimonio decimal(20,2) = null
set @patrimonio = (select top 1 patrimonio from Balances_Contables
where cuit = @cuit
and estado = 'PUBLICADO'
and visible = 1
and year(fecha_balance) >= year(getdate()) - 6
order by fecha_balance desc)
if (@patrimonio < 0)
begin
set @puntaje = -100
set @detalle = 'PATRIMONIO NEGATIVO'
end
if (@puntaje != -100 and @puntaje != 100) -- Por si se personaliza que de otro puntaje
begin
set @detallep = 'PATRIMONIO NEGATIVO'
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_Pat = @puntaje
END
GO
Depends On
10Used By
No items found