Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @cliente | int | 4 | |
| @fecha | date | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_cuit_enrichment_simples_sociedades
@cliente int = 5674,
@fecha date = '2018-11-29'
AS
BEGIN
SET NOCOUNT ON;
delete from procesos_cuit_enrichment_datos_simples_socios
where cliente = @cliente
and fecha_proceso = @fecha
/* Tabla socios */
insert into procesos_cuit_enrichment_datos_simples_socios(cliente, fecha_proceso, cuit, nombre, cuit_relacionado, nombre_relacionado, cargo)
select distinct
@cliente as cliente, @fecha as fecha_proceso,
c01_cuit as cuit, b.nombre_persona as sociedad,
c01_cuit_soc as cuit_integrante, a.nombre_persona as nombre_integrante, c.car_nombre as cargo
from socios
inner join cargos c on c.car_codigo = socios.car_codigo
inner join padrones a on a.identificacion = c01_cuit_soc and a.habilitado = 1
inner join padrones b on b.identificacion = c01_cuit and b.habilitado = 1
where socios.c01_cuit_soc
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha)
and c04_ultimo = 'S'
and isnull(c01_cuit,'') != ''
/* Tabla Sociedades_Constituciones */
insert into procesos_cuit_enrichment_datos_simples_socios(cliente, fecha_proceso, cuit, nombre, cuit_relacionado, nombre_relacionado, cargo)
select distinct
@cliente as cliente, @fecha as fecha_proceso,
documento_soc as cuit, b.nombre_persona as sociedad,
iif(isnull(cuit_int,'')!='',cuit_int, cuit_integrante) as cuit_integrante,
a.nombre_persona as nombre_integrante,
iif(isnull(sociedades_constituciones.cargo,'')='',cargos_grupo_jurad.cargo,sociedades_constituciones.cargo) as cargo
from sociedades_constituciones
left join cargos_grupo_jurad on codigo = cargo_int
inner join padrones a on a.identificacion = iif(isnull(cuit_int,'')!='',cuit_int, cuit_integrante) and a.habilitado = 1
inner join padrones b on b.identificacion = documento_soc and b.habilitado = 1
where (sociedades_constituciones.cuit_int
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha)
or sociedades_constituciones.cuit_integrante
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha))
and (ISNULL(documento_soc ,'') != '')
and not exists (select * from procesos_cuit_enrichment_datos_simples_socios a
where a.cliente = @cliente
and a.fecha_proceso = @fecha
and a.cuit = documento_soc
and a.cuit_relacionado = iif(isnull(cuit_int,'')!='',cuit_int, cuit_integrante))
/* Tabla Edictos */
insert into procesos_cuit_enrichment_datos_simples_socios(cliente, fecha_proceso, cuit, nombre, cuit_relacionado, nombre_relacionado, cargo)
select distinct
@cliente as cliente, @fecha as fecha_proceso,
cuit_sociedad as cuit, b.nombre_persona as sociedad,
cuit_integrante, a.nombre_persona as nombre_integrante, 'INTEGRANTE' as cargo
from edictos
inner join padrones a on a.identificacion = cuit_integrante and a.habilitado = 1
inner join padrones b on b.identificacion = cuit_sociedad and b.habilitado = 1
where edictos.cuit_integrante
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha)
and isnull(cuit_sociedad,'') != ''
and not exists (select * from procesos_cuit_enrichment_datos_simples_socios a
where a.cliente = @cliente
and a.fecha_proceso = @fecha
and a.cuit = cuit_sociedad
and a.cuit_relacionado = edictos.cuit_integrante)
select * from procesos_cuit_enrichment_datos_simples_socios a
where a.cliente = @cliente
and a.fecha_proceso = @fecha
order by cuit, cuit_relacionado
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_cuit_enrichment_simples_sociedades
@cliente int = 5674,
@fecha date = '2018-11-29'
AS
BEGIN
SET NOCOUNT ON;
delete from procesos_cuit_enrichment_datos_simples_socios
where cliente = @cliente
and fecha_proceso = @fecha
/* Tabla socios */
insert into procesos_cuit_enrichment_datos_simples_socios(cliente, fecha_proceso, cuit, nombre, cuit_relacionado, nombre_relacionado, cargo)
select distinct
@cliente as cliente, @fecha as fecha_proceso,
c01_cuit as cuit, b.nombre_persona as sociedad,
c01_cuit_soc as cuit_integrante, a.nombre_persona as nombre_integrante, c.car_nombre as cargo
from socios
inner join cargos c on c.car_codigo = socios.car_codigo
inner join padrones a on a.identificacion = c01_cuit_soc and a.habilitado = 1
inner join padrones b on b.identificacion = c01_cuit and b.habilitado = 1
where socios.c01_cuit_soc
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha)
and c04_ultimo = 'S'
and isnull(c01_cuit,'') != ''
/* Tabla Sociedades_Constituciones */
insert into procesos_cuit_enrichment_datos_simples_socios(cliente, fecha_proceso, cuit, nombre, cuit_relacionado, nombre_relacionado, cargo)
select distinct
@cliente as cliente, @fecha as fecha_proceso,
documento_soc as cuit, b.nombre_persona as sociedad,
iif(isnull(cuit_int,'')!='',cuit_int, cuit_integrante) as cuit_integrante,
a.nombre_persona as nombre_integrante,
iif(isnull(sociedades_constituciones.cargo,'')='',cargos_grupo_jurad.cargo,sociedades_constituciones.cargo) as cargo
from sociedades_constituciones
left join cargos_grupo_jurad on codigo = cargo_int
inner join padrones a on a.identificacion = iif(isnull(cuit_int,'')!='',cuit_int, cuit_integrante) and a.habilitado = 1
inner join padrones b on b.identificacion = documento_soc and b.habilitado = 1
where (sociedades_constituciones.cuit_int
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha)
or sociedades_constituciones.cuit_integrante
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha))
and (ISNULL(documento_soc ,'') != '')
and not exists (select * from procesos_cuit_enrichment_datos_simples_socios a
where a.cliente = @cliente
and a.fecha_proceso = @fecha
and a.cuit = documento_soc
and a.cuit_relacionado = iif(isnull(cuit_int,'')!='',cuit_int, cuit_integrante))
/* Tabla Edictos */
insert into procesos_cuit_enrichment_datos_simples_socios(cliente, fecha_proceso, cuit, nombre, cuit_relacionado, nombre_relacionado, cargo)
select distinct
@cliente as cliente, @fecha as fecha_proceso,
cuit_sociedad as cuit, b.nombre_persona as sociedad,
cuit_integrante, a.nombre_persona as nombre_integrante, 'INTEGRANTE' as cargo
from edictos
inner join padrones a on a.identificacion = cuit_integrante and a.habilitado = 1
inner join padrones b on b.identificacion = cuit_sociedad and b.habilitado = 1
where edictos.cuit_integrante
in (select cuit from procesos_cuit where cliente = @cliente and fecha = @fecha)
and isnull(cuit_sociedad,'') != ''
and not exists (select * from procesos_cuit_enrichment_datos_simples_socios a
where a.cliente = @cliente
and a.fecha_proceso = @fecha
and a.cuit = cuit_sociedad
and a.cuit_relacionado = edictos.cuit_integrante)
select * from procesos_cuit_enrichment_datos_simples_socios a
where a.cliente = @cliente
and a.fecha_proceso = @fecha
order by cuit, cuit_relacionado
END
GO
Depends On
8Used By
No items found