dbo.LN_demo_fidecheck_

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

13
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_fidecheck varchar 1
@p_detalle varchar -1
@p_gestion int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
-- select * from LN_demo_fidecheck where nacionalidad is not null and contraparte > 32000

-- [LN_demo_fidecheck_] 'SEARCH', null, 156348, null,null

-- [LN_demo_fidecheck_] 'SELECT', 1998
-- LN_demo_fidecheck_  'select', 0, 66886,'', 'P'

CREATE OR ALTER PROCEDURE dbo.LN_demo_fidecheck_ 
 -- 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_fidecheck      varchar(1) = null,
 @p_detalle       varchar(max) = 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)
    begin
  select @p_gestion =  (select max(gestion) from ln_gestiones where ln_gestiones.contraparte = @p_contraparte and vigente = 1)
 end

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

  if (@p_seccion is null)

   select distinct LN_demo_fidecheck.*, 
   DATOS_PERSONAS.fecha_defuncion,
   DATOS_PERSONAS.defuncion,
     CASE
      WHEN LN_demo_fidecheck.seccion = 'S' THEN 'Socios / Accionistas'
      WHEN LN_demo_fidecheck.seccion = 'R' THEN 'Vinculaciones / Empresas relacionadas'
      WHEN LN_demo_fidecheck.seccion = 'D' THEN 'Directivos'
      WHEN LN_demo_fidecheck.seccion = 'P' THEN 'Propio'
      ELSE NULL
     END AS nombre_seccion,
     CASE 
      WHEN LN_demo_fidecheck.fidecheck = 'N' THEN 'Negative'
      WHEN LN_demo_fidecheck.fidecheck = 'R' THEN 'Relative'
      WHEN LN_demo_fidecheck.fidecheck = 'P' THEN 'Positive'
      WHEN LN_demo_fidecheck.fidecheck = 'E' THEN 'PEP'
      WHEN LN_demo_fidecheck.fidecheck = 'S' THEN 'Sujeto Obligado'
      

      ELSE NULL
     END AS pep,
     CASE 
      WHEN LN_demo_fidecheck.fidecheck = 'P' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#A72B2A" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'E' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FF5C1C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'S' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'R' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'N' 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_demo_fidecheck.modified is not null, LN_demo_fidecheck.modified, LN_demo_fidecheck.created) as fecha

   from LN_demo_fidecheck
   inner join LN_contrapartes on LN_demo_fidecheck.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_demo_fidecheck.tax_id and DATOS_PERSONAS.visible = 1
   where LN_demo_fidecheck.contraparte = @p_contraparte and gestion = @p_gestion 
   and LN_demo_fidecheck.visible = 1 
   and  
   ((@accion = 'SEARCH' and LN_demo_fidecheck.visible = 1) or @accion='SEARCHALL')
   order by LN_demo_fidecheck.seccion, LN_demo_fidecheck.orden, 
      LN_demo_fidecheck.porcentaje desc, LN_demo_fidecheck.nombre

  else


   select distinct  LN_demo_fidecheck.*, 
     DATOS_PERSONAS.fecha_defuncion,
     DATOS_PERSONAS.defuncion,
     CASE
      WHEN LN_demo_fidecheck.seccion = 'S' THEN 'Socios / Accionistas'
      WHEN LN_demo_fidecheck.seccion = 'R' THEN 'Vinculaciones / Empresas relacionadas'
      WHEN LN_demo_fidecheck.seccion = 'D' THEN 'Directivos'
      WHEN LN_demo_fidecheck.seccion = 'P' THEN 'Propio'
     END AS nombre_seccion,
     CASE 
      WHEN LN_demo_fidecheck.fidecheck = 'N' THEN 'Negative'
      WHEN LN_demo_fidecheck.fidecheck = 'R' THEN 'Relative'
      WHEN LN_demo_fidecheck.fidecheck = 'S' THEN 'Sujeto Obligado'
      WHEN LN_demo_fidecheck.fidecheck = 'E' THEN 'PEP'
      WHEN LN_demo_fidecheck.fidecheck = 'P' THEN 'Positive'

     END AS pep,
     CASE 
      WHEN LN_demo_fidecheck.fidecheck = 'P' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#A72B2A" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'E' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FF5C1C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'S' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'R' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'N' 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_demo_fidecheck.modified is not null, convert(varchar,LN_demo_fidecheck.modified,103), convert(varchar,LN_demo_fidecheck.created,103)) as fecha


   from LN_demo_fidecheck
   inner join LN_contrapartes on LN_demo_fidecheck.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_demo_fidecheck.tax_id and DATOS_PERSONAS.visible = 1

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

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


 END

 IF (@accion = 'SELECT') BEGIN

  if (@p_seccion = 'P' and isnull(@p_id,0) = 0) 
   begin
     set @p_id = (select Top 1 id_fidecheck from LN_demo_fidecheck where contraparte = @p_contraparte and gestion = @p_gestion and seccion = 'P' and visible = 1) 
     if (isnull(@p_id,0) = 0) 
     begin
    insert into LN_demo_fidecheck (contraparte, gestion, nombre, seccion, tax_id, visible,fidecheck) 
     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_demo_fidecheck.*, 
     DATOS_PERSONAS.fecha_defuncion,
     DATOS_PERSONAS.defuncion,
     CASE
      WHEN LN_demo_fidecheck.seccion = 'S' THEN 'Socios / Accionistas'
      WHEN LN_demo_fidecheck.seccion = 'R' THEN 'Vinculaciones / Empresas relacionadas'
      WHEN LN_demo_fidecheck.seccion = 'D' THEN 'Directivos'
      WHEN LN_demo_fidecheck.seccion = 'P' THEN 'Propio'
     END AS nombre_seccion,
     CASE 
      WHEN LN_demo_fidecheck.fidecheck = 'N' THEN 'Negative'
      WHEN LN_demo_fidecheck.fidecheck = 'R' THEN 'Relative'
      WHEN LN_demo_fidecheck.fidecheck = 'S' THEN 'Sujeto Obligado'
      WHEN LN_demo_fidecheck.fidecheck = 'E' THEN 'PEP'
      WHEN LN_demo_fidecheck.fidecheck = 'P' THEN 'Positive'

     END AS pep,
     CASE 
      WHEN LN_demo_fidecheck.fidecheck = 'P' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#A72B2A" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'E' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FF5C1C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'S' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'R' THEN '<svg height="20" width="20"><circle cx="10" cy="10" r="9" stroke="black" stroke-width="0" fill="#FFB81C" /></svg>'
      WHEN LN_demo_fidecheck.fidecheck = 'N' 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_demo_fidecheck.modified is not null, convert(varchar,LN_demo_fidecheck.modified,103), convert(varchar,LN_demo_fidecheck.created,103)) as fecha


   from LN_demo_fidecheck
   inner join LN_contrapartes on LN_demo_fidecheck.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_demo_fidecheck.tax_id and DATOS_PERSONAS.visible = 1

   where LN_demo_fidecheck.id_fidecheck = @p_id

 END

 IF (@accion = 'up') BEGIN

  SELECT @ord = orden, @contraparte = contraparte, @gestion = gestion FROM LN_demo_fidecheck WHERE id_fidecheck = @p_id

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

   if (@id is not null) begin

    update LN_demo_fidecheck SET
     orden = @ord - 1
    where id_fidecheck = @p_id

    update LN_demo_fidecheck SET
     orden = @ord
    where id_fidecheck = @id

   end

  end

 END


 IF (@accion = 'down') BEGIN

  SELECT @ord = orden, @contraparte = contraparte, @gestion = gestion FROM LN_demo_fidecheck WHERE id_fidecheck = @p_id

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

   if (@id is not null) begin

    update LN_demo_fidecheck SET
     orden = @ord + 1
    where id_fidecheck = @p_id

    update LN_demo_fidecheck SET
     orden = @ord
    where id_fidecheck = @id

   end

  end

 END


 IF (@accion = 'INSERT') BEGIN

  IF (@p_seccion != 'R')
            BEGIN
                INSERT INTO LN_demo_fidecheck
                (contraparte, gestion, nombre, seccion, tax_id, nacionalidad, orden, porcentaje, tipo_relacion, cargo, fidecheck, 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_fidecheck, @p_detalle)
            end
  ELSE BEGIN

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

   INSERT INTO LN_demo_fidecheck
   (contraparte, gestion, nombre, seccion, tax_id, nacionalidad, orden, porcentaje, tipo_relacion, cargo, fidecheck, 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_fidecheck, @p_detalle)

  END

 END

 IF (@accion = 'UPDATE') BEGIN

  UPDATE LN_demo_fidecheck SET

     contraparte = @p_contraparte,
     gestion = @p_gestion, 
     nombre = UPPER(@p_nombre),
     seccion = @p_seccion,
     tax_id = @p_tax_id,
     nacionalidad = UPPER(@p_nacionalidad),
     porcentaje = @p_porcentaje,
     tipo_relacion = @p_tipo_relacion,
     cargo = @p_cargo,
     fidecheck = @p_fidecheck,
     detalle = @p_detalle, 
     modified = GETDATE()

  WHERE id_fidecheck = @p_id

 END


 IF (@accion = 'DELETE') BEGIN

  select @sec = seccion, 
    @contraparte = contraparte,
    @gestion = gestion, 
    @ord = orden
  from LN_demo_fidecheck 
  where id_fidecheck = @p_id


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

   if (@sec != 'R')

    DELETE FROM LN_demo_fidecheck WHERE id_fidecheck = @p_id

   else begin

    if (@ord is not null) begin

        DELETE FROM LN_demo_fidecheck WHERE id_fidecheck = @p_id 

     UPDATE LN_demo_fidecheck 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_demo_fidecheck set visible = iif(visible=0,1,0) 
    WHERE id_fidecheck = @p_id

 END


 IF (@accion = 'STATUS') BEGIN

  IF (select count(*) from LN_demo_fidecheck
   where contraparte = @p_contraparte and gestion = @p_gestion 
   and fidecheck = 'P' and visible = 1) > 0

   SELECT 'P' AS fidecheck

  ELSE

    IF (select count(*) from LN_demo_fidecheck
    where contraparte = @p_contraparte and gestion = @p_gestion 
    and fidecheck = 'E' and visible = 1) > 0

    SELECT 'E' AS fidecheck
    ELSE

      IF (select count(*) from LN_demo_fidecheck
    where contraparte = @p_contraparte and gestion = @p_gestion 
    and fidecheck = 'S' and visible = 1) > 0

    SELECT 'S' AS fidecheck
   ELSE

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

    SELECT 'R' AS fidecheck

   ELSE

    IF (select count(*) from LN_demo_fidecheck
     where contraparte = @p_contraparte and gestion = @p_gestion 
     and fidecheck = 'N'  and visible = 1) > 0

     SELECT 'N' AS fidecheck

    ELSE

     SELECT NULL AS fidecheck


 END
 
END

GO

Used By

No items found