dbo.LN_control_calidad

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@p_contraparte int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
exec [LN_control_etica] 4298
select * from ln_contrapartes where id_padron in (select id_padron from padrones where identificacion = '800489519')
select * from socios where c01_cuit = '800489519'
*/

CREATE OR ALTER PROCEDURE dbo.LN_control_calidad
/* OJO si se cambia la salida, porque se usa en PANEL_CONTROL_EXCEL_ */

@p_contraparte int

AS
BEGIN
    SET NOCOUNT ON;
 /* 31/05/2022: Se agrego el control de que el numero de tax-id sea del mismo pais */

 
 /* 21/12/2023: se agrega el control los accionistas */
 select distinct accionistas.cuit_acc as cuit, padrones2.nombre_persona as nombre, 'ACCIONISTA' as cargo
   from ln_contrapartes 
   inner join padrones on padrones.id_padron = LN_contrapartes.id_padron 
   inner join accionistas on accionistas.cuit_sociedad = padrones.identificacion 
   inner join padrones padrones2 on padrones2.identificacion = accionistas.cuit_acc and padrones2.habilitado = 1 
   inner join identificadores on identificadores.identificador = padrones2.identificador
   inner join LN_control_black_list on  ((LN_control_black_list.identificacion = padrones2.identificacion  or 
            LN_control_black_list.identificacion = padrones2.cuerpo_clave) and 
               LN_control_black_list.country_code = identificadores.country_code)

  where ln_contrapartes.contraparte = @p_contraparte
    and ln_contrapartes.activo = 1
    and accionistas.visible = 1
    and LN_control_black_list.visible = 1
    and LN_control_black_list.cliente = ln_contrapartes.cliente
    and LN_control_black_list.country_code = identificadores.country_code

 union all 
 /* */ 
 select distinct socios.c01_cuit_soc as cuit, padrones2.nombre_persona as nombre, car_nombre as cargo
   from ln_contrapartes 
   inner join padrones on padrones.id_padron = LN_contrapartes.id_padron 
   inner join socios on socios.c01_cuit = padrones.identificacion 
   inner join padrones padrones2 on padrones2.identificacion = socios.c01_cuit_soc and padrones2.habilitado = 1 
    /* agregado - Pais del documento del socio */
   inner join identificadores on identificadores.identificador = padrones2.identificador
   /* */ 
   inner join LN_control_black_list on  ((LN_control_black_list.identificacion = padrones2.identificacion  or 
            LN_control_black_list.identificacion = padrones2.cuerpo_clave) and 
               LN_control_black_list.country_code = identificadores.country_code)

   left join cargos on cargos.car_codigo = socios.car_codigo 
  where ln_contrapartes.contraparte = @p_contraparte
    and ln_contrapartes.activo = 1
    and socios.visible = 1
    and isnull(socios.c04_ultimo,'') != 'N'
    and LN_control_black_list.visible = 1
    and LN_control_black_list.cliente = ln_contrapartes.cliente
    /* agregado */
    and LN_control_black_list.country_code = identificadores.country_code
    /* */ 

    union all 

   select distinct padrones.identificacion as cuit, padrones.nombre_persona as nombre, '' as cargo
   from ln_contrapartes 
   inner join padrones on padrones.id_padron = LN_contrapartes.id_padron 
    /* agregado - Pais del documento la contraparte */
   inner join identificadores on identificadores.identificador = padrones.identificador
   /* */
   
   inner join LN_control_black_list on  ((LN_control_black_list.identificacion = padrones.identificacion  or 
            LN_control_black_list.identificacion = padrones.cuerpo_clave) and 
               LN_control_black_list.country_code = identificadores.country_code)
  where ln_contrapartes.contraparte = @p_contraparte
    and ln_contrapartes.activo = 1
    and LN_control_black_list.visible = 1
    and LN_control_black_list.cliente = ln_contrapartes.cliente
    /* agregado */
    and LN_control_black_list.country_code = identificadores.country_code
    /* */ 
END 

GO