dbo.LN_check_

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

14
Name Data Type Length Description
@accion varchar 30
@p_id int 4
@p_contraparte int 4
@p_nombre varchar 250
@p_seccion varchar 1
@p_tax_id varchar 50
@p_nacionalidad varchar 30
@p_porcentaje decimal 5
@p_tipo_relacion varchar 100
@p_cargo varchar 100
@p_check varchar 1
@p_detalle varchar -1
@p_url varchar 500
@p_gestion int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
LN_check_ 'select', 3284, null,null,null
*/


CREATE OR ALTER PROCEDURE dbo.LN_check_ 
 -- Add the parameters for the stored procedure here

 @accion        varchar(30) = null,
 @p_id        int = null,
 @p_contraparte      int = null,
 @p_nombre       varchar(250) = null,
 @p_seccion       varchar(1) = null,
 @p_tax_id       varchar(50) = null,
 @p_nacionalidad      varchar(30) = null,
 @p_porcentaje      decimal(5,2) = null,
 @p_tipo_relacion     varchar(100) = null,
 @p_cargo       varchar(100) = null,
 @p_check          varchar(1) = null,
 @p_detalle       varchar(max) = null, 
 @p_url varchar(500) = null, 
 @p_gestion int = null 


 
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here
 DECLARE @id int = null, @ord int = null, @contraparte int = null, @gestion int = null, @sec varchar(1) = NULL
 if (@p_gestion is null and @p_contraparte is not null)
  select @p_gestion =  (select max(gestion) from ln_gestiones where ln_gestiones.contraparte = @p_contraparte and vigente = 1)
 

 IF (@accion = 'SEARCH' or @accion = 'SEARCHALL') BEGIN

  if (@p_seccion is null)

   select distinct LN_check.*, null as fecha_defuncion, null as defuncion, 
   --DATOS_PERSONAS.fecha_defuncion,
   --DATOS_PERSONAS.defuncion,
     CASE
      WHEN LN_check.seccion = 'S' THEN 'Socios / Accionistas'
      WHEN LN_check.seccion = 'R' THEN 'Vinculaciones / Empresas relacionadas'
      WHEN LN_check.seccion = 'D' THEN 'Directivos'
      WHEN LN_check.seccion = 'P' THEN 'Propio'
      ELSE NULL
     END AS nombre_seccion,
     CASE 
      WHEN LN_check.lncheck = 'R' THEN 'Rojo'
      WHEN LN_check.lncheck = 'A' THEN 'Amarillo'
      WHEN LN_check.lncheck = 'V' THEN 'Verde'   

      ELSE NULL
     END AS pep,
     CASE 
      WHEN LN_check.lncheck = 'R' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#A72B2A" /></svg>'
      WHEN LN_check.lncheck = 'A' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_check.lncheck = 'V' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#63b68c" /></svg>'
      ELSE NULL
     END AS estado,
    clientes.nombre_cliente, padrones.nombre_persona, padrones.identificador,
    padrones.numero, padrones.identificacion, identificadores.abreviatura, 
    identificadores.country_code, country.country_name, 
    LN_contrapartes.id_padron, LN_contrapartes.cliente, 
    iif(LN_check.modified is not null, LN_check.modified, LN_check.created) as fecha

   from LN_check
   inner join LN_contrapartes on LN_check.contraparte = LN_contrapartes.contraparte
   inner join clientes on LN_contrapartes.cliente = clientes.cliente
   inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
   inner join identificadores on padrones.identificador = identificadores.identificador
   inner join country on identificadores.country_code = country.country_code
   --left join DATOS_PERSONAS on DATOS_PERSONAS.c01_cuit = LN_check.tax_id and DATOS_PERSONAS.visible = 1
   where LN_check.contraparte = @p_contraparte and gestion = @p_gestion 
   and LN_check.visible = 1 
   and  
   ((@accion = 'SEARCH' and LN_check.visible = 1) or @accion='SEARCHALL')
   order by LN_check.seccion, LN_check.orden, 
      LN_check.porcentaje desc, LN_check.nombre

  else


   select distinct  LN_check.*, null as fecha_fefuncion, null as defuncion, 
     --DATOS_PERSONAS.fecha_defuncion,
     --DATOS_PERSONAS.defuncion,
     CASE
      WHEN LN_check.seccion = 'S' THEN 'Socios / Accionistas'
      WHEN LN_check.seccion = 'R' THEN 'Vinculaciones / Empresas relacionadas'
      WHEN LN_check.seccion = 'D' THEN 'Directivos'
      WHEN LN_check.seccion = 'P' THEN 'Propio'
     END AS nombre_seccion,
     CASE 
      WHEN LN_check.lncheck = 'R' THEN 'Rojo'
      WHEN LN_check.lncheck = 'A' THEN 'Amarillo'
      WHEN LN_check.lncheck = 'V' THEN 'Verde'
     END AS pep,
     CASE 
      WHEN LN_check.lncheck = 'R' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#A72B2A" /></svg>'
      WHEN LN_check.lncheck = 'A' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_check.lncheck = 'V' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#63b68c" /></svg>'
      ELSE NULL
     END AS estado,
    clientes.nombre_cliente, padrones.nombre_persona, padrones.identificador,
    padrones.numero, padrones.identificacion, identificadores.abreviatura, 
    identificadores.country_code, country.country_name, 
    LN_contrapartes.id_padron, LN_contrapartes.cliente,
    iif(LN_check.modified is not null, convert(varchar,LN_check.modified,103), convert(varchar,LN_check.created,103)) as fecha


   from LN_check
   inner join LN_contrapartes on LN_check.contraparte = LN_contrapartes.contraparte
   inner join clientes on LN_contrapartes.cliente = clientes.cliente
   inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
   inner join identificadores on padrones.identificador = identificadores.identificador
   inner join country on identificadores.country_code = country.country_code
   --left join DATOS_PERSONAS on DATOS_PERSONAS.c01_cuit = LN_check.tax_id and DATOS_PERSONAS.visible = 1

   where LN_check.contraparte = @p_contraparte and LN_check.gestion = @p_gestion 
   and LN_check.visible = 1 
   and LN_check.seccion = @p_seccion
   and ((@accion = 'SEARCH' and LN_check.visible = 1) or @accion='SEARCHALL')

   order by LN_check.seccion, LN_check.orden, 
      LN_check.porcentaje desc, LN_check.nombre


 END

 IF (@accion = 'SELECT') BEGIN

  if (@p_seccion = 'P' and isnull(@p_id,0) = 0) 
   begin
     set @p_id = (select Top 1 id_check from LN_check where contraparte = @p_contraparte and gestion = @p_gestion and seccion = 'P' and visible = 1) 
     if (isnull(@p_id,0) = 0) 
     begin
    insert into LN_check (contraparte, gestion, nombre, seccion, tax_id, visible,lncheck) 
     select LN_contrapartes.contraparte, @p_gestion, UPPER(padrones.nombre_persona), 'P', padrones.identificacion, 1,''
     from LN_contrapartes 
     inner join padrones on padrones.id_padron = LN_contrapartes.id_padron
     where LN_contrapartes.contraparte = @p_contraparte 
    SET @p_id = SCOPE_IDENTITY()
     end
   end  

   select LN_check.*,  null as fecha_defuncion, null as defuncion,
     --DATOS_PERSONAS.fecha_defuncion,
     --DATOS_PERSONAS.defuncion,
     CASE
      WHEN LN_check.seccion = 'S' THEN 'Socios / Accionistas'
      WHEN LN_check.seccion = 'R' THEN 'Vinculaciones / Empresas relacionadas'
      WHEN LN_check.seccion = 'D' THEN 'Directivos'
      WHEN LN_check.seccion = 'P' THEN 'Propio'
     END AS nombre_seccion,
     CASE 
      WHEN LN_check.lncheck = 'R' THEN 'Rojo'
      WHEN LN_check.lncheck = 'A' THEN 'Amarillo'
      WHEN LN_check.lncheck = 'V' THEN 'Verde'
     END AS pep,
     CASE 
      WHEN LN_check.lncheck = 'R' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#A72B2A" /></svg>'
      WHEN LN_check.lncheck = 'A' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_check.lncheck = 'V' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#63b68c" /></svg>'
      ELSE NULL
     END AS estado,
    clientes.nombre_cliente, padrones.nombre_persona, padrones.identificador,
    padrones.numero, padrones.identificacion, identificadores.abreviatura, 
    identificadores.country_code, country.country_name, 
    LN_contrapartes.id_padron, LN_contrapartes.cliente,
    iif(LN_check.modified is not null, convert(varchar,LN_check.modified,103), convert(varchar,LN_check.created,103)) as fecha


   from LN_check
   inner join LN_contrapartes on LN_check.contraparte = LN_contrapartes.contraparte
   inner join clientes on LN_contrapartes.cliente = clientes.cliente
   inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
   inner join identificadores on padrones.identificador = identificadores.identificador
   inner join country on identificadores.country_code = country.country_code
   --left join DATOS_PERSONAS on DATOS_PERSONAS.c01_cuit = LN_check.tax_id and DATOS_PERSONAS.visible = 1

   where LN_check.id_check = @p_id

 END
 

 IF (@accion = 'up') BEGIN

  SELECT @ord = orden, @contraparte = contraparte, @gestion = gestion FROM LN_check WHERE id_check = @p_id

  if (@ord > 1 and @contraparte is not null) begin
   
   select @id = id_check 
   from LN_check  
   where contraparte = @contraparte and gestion = @gestion 
   and seccion = 'R'
   and orden = @ord - 1

   if (@id is not null) begin

    update LN_check SET
     orden = @ord - 1
    where id_check = @p_id

    update LN_check SET
     orden = @ord
    where id_check = @id

   end

  end

 END


 IF (@accion = 'down') BEGIN

  SELECT @ord = orden, @contraparte = contraparte, @gestion = gestion FROM LN_check WHERE id_check = @p_id

  if (@ord is not null and @contraparte is not null) begin
   
   select @id = id_check 
   from LN_check 
   where contraparte = @contraparte and gestion = @gestion 
   and seccion = 'R'
   and orden = @ord + 1

   if (@id is not null) begin

    update LN_check SET
     orden = @ord + 1
    where id_check = @p_id

    update LN_check SET
     orden = @ord
    where id_check = @id

   end

  end

 END


 IF (@accion = 'INSERT') BEGIN

  IF (@p_seccion != 'R')

   INSERT INTO LN_check
   (contraparte, gestion, nombre, seccion, tax_id, nacionalidad, orden, porcentaje, tipo_relacion, cargo, lncheck, detalle)
   VALUES
   (@p_contraparte, @p_gestion, UPPER(@p_nombre), @p_seccion, @p_tax_id, UPPER(@p_nacionalidad), NULL, @p_porcentaje, @p_tipo_relacion, @p_cargo, @p_check, @p_detalle)

  ELSE BEGIN

   SELECT @ord = ISNULL(MAX(orden),0)+1 FROM LN_check
   WHERE contraparte = @p_contraparte and gestion = @p_gestion AND seccion = 'R'

   INSERT INTO LN_check
   (contraparte, gestion, nombre, seccion, tax_id, nacionalidad, orden, porcentaje, tipo_relacion, cargo, lncheck, detalle)
   VALUES
   (@p_contraparte, @p_gestion, UPPER(@p_nombre), @p_seccion, @p_tax_id, UPPER(@p_nacionalidad), @ord, @p_porcentaje, @p_tipo_relacion, @p_cargo, @p_check, @p_detalle)

  END

 END

 IF (@accion = 'UPDATE') BEGIN

  UPDATE LN_check SET
     lncheck = @p_check,
     detalle = @p_detalle, 
     ruta = @p_url, 
     modified = GETDATE()

  WHERE id_check = @p_id

 END


 IF (@accion = 'DELETE') BEGIN

  select @sec = seccion, 
    @contraparte = contraparte,
    @gestion = gestion, 
    @ord = orden
  from LN_check 
  where id_check = @p_id


  if (@sec is not null AND @contraparte is not null) begin

   if (@sec != 'R')

    DELETE FROM LN_check WHERE id_check = @p_id

   else begin

    if (@ord is not null) begin

        DELETE FROM LN_check WHERE id_check = @p_id 

     UPDATE LN_check SET
      orden = orden - 1
     WHERE seccion = 'R' 
     AND contraparte = @contraparte and gestion = @gestion 
     AND orden > @ord
     
    
    end  

   end


  end

 END

 IF (@accion = 'CAMBIARESTADO') BEGIN

    update LN_check set visible = iif(visible=0,1,0) 
    WHERE id_check = @p_id

 END


 IF (@accion = 'STATUS') BEGIN

  IF (select count(*) from LN_check
   where contraparte = @p_contraparte and gestion = @p_gestion 
   and lncheck = 'R' and visible = 1) > 0

   SELECT 'R' AS lncheck

  ELSE

    IF (select count(*) from LN_check
    where contraparte = @p_contraparte and gestion = @p_gestion 
    and lncheck = 'A' and visible = 1) > 0

    SELECT 'A' AS lncheck
    ELSE

   IF (select count(*) from LN_check
    where contraparte = @p_contraparte and gestion = @p_gestion 
    and lncheck = 'V'  and visible = 1) > 0

    SELECT 'V' AS lncheck

   ELSE

    SELECT NULL AS lncheck


 END
 
END

GO

Used By

No items found