dbo.LN_capacidad_endeudamiento

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

5
Name Data Type Length Description
@contraparte int 4
@cuit varchar 20
@monto decimal 13
@leyenda varchar 200
@fecha date 3

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <16/10/2019>
-- Description: Cálculo de capacidad máxima de endeudamiento (según el pastor) 
-- =============================================
DECLARE @monto decimal(10,2) = null, @leyenda varchar(200) = null, @fecha date = null
EXEC [dbo].[LN_capacidad_endeudamiento] 33020, null, @monto output, @leyenda output, @fecha output 
--EXEC [dbo].[LN_capacidad_endeudamiento_BCRA] 33020, null, @Monto  output, @leyenda output, @Fecha output
--EXEC [dbo].[LN_capacidad_endeudamiento_Balance] 33020, null, @Monto output, @leyenda output, @Fecha output
select @monto as monto, @leyenda as leyenda, @fecha as fecha, @monto as monto
*/


CREATE OR ALTER PROCEDURE dbo.LN_capacidad_endeudamiento 
  @contraparte int,
  @cuit varchar(20) = null,
  @monto decimal(20,2) = null output,
  @leyenda varchar(200) = null output, 
  @fecha date = null output
AS
BEGIN
 SET NOCOUNT ON; 
 DECLARE @W_Monto_1 DECIMAL(20,2) = 0
 DECLARE @W_Monto_2 DECIMAL(20,2) = 0
 DECLARE @W_Fecha_1 DATE = null
 DECLARE @W_Fecha_2 DATE = null
 DECLARE @Leyenda_1  varchar(200) = NULL
 DECLARE @Leyenda_2  varchar(200) = NULL

 if (@contraparte is not null) 
 begin
  select @cuit = identificacion from padrones 
  where id_padron = (select id_padron from LN_contrapartes where contraparte = @contraparte)  
 end 

 if (@cuit is null)  -- No encontrado
 begin
  set @monto = null
  set @leyenda = null 
  set @fecha   = null 
 end 
 else 
 begin 
     /* Calculo segun BCRA */
  EXEC [dbo].[LN_capacidad_endeudamiento_BCRA] @contraparte, @cuit, @W_Monto_1 output, @leyenda_1 output, @W_Fecha_1 output

  /* Calculo segun Balance */ 
  EXEC [dbo].[LN_capacidad_endeudamiento_Balance] @contraparte, @cuit, @W_Monto_2 output, @leyenda_2 output, @W_Fecha_2 output
   
  IF (@W_Monto_2 = 0) 
  begin 
   set @monto = 0
   set @leyenda = @Leyenda_2
   set @fecha = @W_Fecha_2
  end 

  IF (@W_Monto_1 = 0.01 AND @W_Monto_2 = 0.01)
  begin
   set @monto = 0
   set @Leyenda = 'SIN INFORMACION CUANTITATIVA'
   set @fecha = IIF(@W_Fecha_2 > @W_Fecha_1, @W_Fecha_2, @w_fecha_1) 
  end 

  IF (@W_Monto_1 > 0.01 AND @W_Monto_2 = 0.01)
  begin 
   set @monto   = @W_Monto_1
   set @Leyenda = @Leyenda_1
   set @fecha   = @W_Fecha_1
  end 

  IF (@W_Monto_1 = 0.01 AND @W_Monto_2 > 0.01)
  begin 
   set @monto   = @W_Monto_2
   set @Leyenda = @Leyenda_2
   set @fecha   = @W_Fecha_2 
  end

  IF (@W_Monto_1 > 0.01 AND @W_Monto_2 > 0.01)
  begin
   set @monto   = @W_Monto_1 + @W_Monto_2
   set @Leyenda = @Leyenda_2
   set @fecha = IIF(@W_Fecha_2 > @W_Fecha_1, @W_Fecha_2, @w_fecha_1) 
  end 

 end 

END 
GO