Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
6| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_id_tabla | int | 4 | |
| @p_documento_soc | varchar | 20 | |
| @p_fecha_publicacion | varchar | 10 | |
| @p_cargo | varchar | 50 | |
| @p_documento_integrante | varchar | 50 | |
| @p_ultdir | varchar | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.igj_insertar
@p_id_tabla int, --Ejemplo de nombre
@p_documento_soc varchar(20),
@p_fecha_publicacion varchar(10),
@p_cargo varchar(50),
@p_documento_integrante varchar(50),
@p_ultdir varchar(1)
AS
BEGIN
--BEGIN TRY
SET NOCOUNT ON;
DECLARE @periodo_ano VARCHAR(4)=NULL
DECLARE @periodo_mes VARCHAR(2)=NULL
/*
select * from igj_autoridades2021
select * from igj_entidades_2021
ALTER TABLE igj_autoridades2021 ADD periodo varchar(10)
*/
/* USAR ESTA CONSULTA MODIFICADA Y CON ESOS REGISTROS MANDARLO A ESTE sp esto va al php*/
select TOP 1000 padrones.identificacion as cuit_socio,igj_entidades_2021.cuit as cuit_sociedad,
descripcion_tipo_administrador as cargo,
'S' as ultimo,
periodo,
idTabla,procesado
--,igj_autoridades2021.*
from igj_autoridades2021
inner join padrones on (igj_autoridades2021.numero_documento=padrones.cuerpo_clave and padrones.habilitado=1)
inner join igj_entidades_2021 on igj_entidades_2021.numero_correlativo=igj_autoridades2021.numero_correlativo
where /*tipo_documento!=5 and */
isnull(igj_autoridades2021.PROCESADO,0) =0 AND
replace(igj_autoridades2021.numero_correlativo,'"','') in (
select distinct numero_correlativo from igj_entidades_2021 where /*dada_de_baja is null and */ cuit is not null)
declare @existe int = 0
select @existe = count(*) from socios where c01_cuit= @p_documento_soc and c01_cuit_soc=@p_documento_integrante and car_codigo= @p_cargo and c04_ultimo= @p_ultdir and fuente = 'IGJ'
if (@existe = 0) --lo tengo que insertar
BEGIN
/*verificar que el registro no exista ya en las mismas condiciones para no duplicar
if (@cuit empresa + cuit persona + cargo + ult dir + fuente IFG == existe
no hacemos nada
else*/
/* ACÁ SE INSERTA EN LA TABLA SOCIOS */
/* SI LOS DATOS NO SON NULOS LO INSERTAMOS EN LA TABLA DE SOCIOS Y SINO EN LA TABLA DE SOCIOS AUXILIAR*/
if (@p_ultdir = 'S')
begin
/* ANTES DE INSERTAR DEBEMOS PASAR TODOS LOS REGISTROS MAS VIEJOS A ULTIMO DIRECTORIO N */
set @periodo_ano=substring(@p_fecha_publicacion,1,4)
set @periodo_mes=substring(@p_fecha_publicacion,6,2)
update socios set c04_ultimo='N',modified=getdate(),modified_by=15342812,c04_periodo_desde=c04_periodo_ano + '-' + c04_periodo_mes
where c01_cuit=@p_documento_soc and c01_cuit_soc=@p_documento_integrante
and ((ISNULL(c04_periodo_desde,'1900-01-01')<substring(@p_fecha_publicacion,1,7))
OR (ISNULL(c04_periodo_ano,'1900')<@periodo_ano and ISNULL(c04_periodo_mes,'01')<=@periodo_mes))
/* FIN DE ACTUALIZAR LOS DIRECTORIOS ANTERIORES */
insert into socios (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,c04_periodo_ano,c04_periodo_mes)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,substring(@p_fecha_publicacion,1,7),1,getdate(),15342812,'IGJ',@periodo_ano,@periodo_mes)
end
else
begin
insert into socios (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,c04_periodo_ano,c04_periodo_mes)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,substring(@p_fecha_publicacion,1,7),1,getdate(),15342812,'IGJ',@periodo_ano,@periodo_mes)
end
UPDATE igj_autoridades2021 SET PROCESADO = 1 WHERE idTabla = @p_id_tabla
END
ELSE
BEGIN
UPDATE igj_autoridades2021 SET PROCESADO = 1 WHERE idTabla = @p_id_tabla
END
END
/*si la razón social es mayor a 2 caracteres asumimos que es cierta y la insertamos. Sino se inserta en la tabla aux para revisarla luego*/
/*
if (len(ltrim(rtrim(@p_razon_social))) < 2)
begin
set @p_razon_social = null
end
if (len(ltrim(rtrim(@p_documento_soc))) < 11)
begin
set @p_documento_soc = null
end
if (len(ltrim(rtrim(@p_documento_integrante))) < 11)
begin
set @p_documento_integrante = null
end
if (len(ltrim(rtrim(@p_fecha_publicacion))) < 10)
begin
set @p_fecha_publicacion = null
end
if (@p_razon_social is not null and @p_cargo !='ZZZ')
begin
INSERT INTO sociedades_constituciones
(id_boletin, documento_soc, razon_social, domicilio_sociedad, localidad_sociedad, provincia_sociedad,
fecha_publicacion, titulo, tipo_publicacion, capita_social, fecha_constitucion, cargo, nombre_integrante,
documento_integrante, domicilio_integrante, localidad_integrante, provincia_integrante, fuente,
codigo_archivo, contenido_archivo, nombre_file, created_by,visible,created,cuit_int,cuit_integrante)
VALUES
(@p_id_boletin, @p_documento_soc, @p_razon_social, @p_domicilio_sociedad, @p_localidad_sociedad, @p_provincia_sociedad,
@p_fecha_publicacion, @p_titulo, @p_tipo_publicacion, @p_capita_social, @p_fecha_constitucion, @p_cargo, @p_nombre_integrante,
@p_documento_integrante, @p_domicilio_integrante, @p_localidad_integrante, @p_provincia_integrante, @p_fuente,
@p_codigo_archivo, @p_contenido_archivo, @p_nombre_file, NULL,1,getdate(),@p_documento_integrante,@p_documento_integrante)
end
if (@p_razon_social is null or @p_cargo ='ZZZ')
BEGIN
INSERT INTO sociedades_constituciones_AI
(id_boletin, documento_soc, razon_social, domicilio_sociedad, localidad_sociedad, provincia_sociedad,
fecha_publicacion, titulo, tipo_publicacion, capita_social, fecha_constitucion, cargo, nombre_integrante,
documento_integrante, domicilio_integrante, localidad_integrante, provincia_integrante, fuente,
codigo_archivo, contenido_archivo, nombre_file, created_by,visible,created,cuit_int,cuit_integrante)
VALUES
(@p_id_boletin, @p_documento_soc, @p_razon_social, @p_domicilio_sociedad, @p_localidad_sociedad, @p_provincia_sociedad,
@p_fecha_publicacion, @p_titulo, @p_tipo_publicacion, @p_capita_social, @p_fecha_constitucion, @p_cargo, @p_nombre_integrante,
@p_documento_integrante, @p_domicilio_integrante, @p_localidad_integrante, @p_provincia_integrante, @p_fuente,
@p_codigo_archivo, @p_contenido_archivo, @p_nombre_file, NULL,1,getdate(),@p_documento_integrante,@p_documento_integrante)
END
if (@p_ultdir = 'S')
begin
declare @existe int = 0
select @existe = count(*) from socios where c01_cuit=@p_documento_soc and c01_cuit_soc=@p_documento_integrante
and ((ISNULL(c04_periodo_desde,'1900-01-01')>substring(@p_fecha_publicacion,1,7))
OR (ISNULL(c04_periodo_ano,'1900')>= @periodo_ano and ISNULL(c04_periodo_mes,'01')>=@periodo_mes))
if (@existe>0)
begin
set @p_ultdir='N'
end
end
if (@p_documento_soc is not null and @p_documento_integrante is not null and @p_fecha_publicacion is not null and @p_cargo !='ZZZ')
begin
begin try
set @periodo_ano=substring(@p_fecha_publicacion,1,4)
set @periodo_mes=substring(@p_fecha_publicacion,6,2)
update socios set c04_ultimo='N',modified=getdate(),modified_by=15342812,c04_periodo_desde=c04_periodo_ano + '-' + c04_periodo_mes
where c01_cuit=@p_documento_soc and c01_cuit_soc=@p_documento_integrante
--and (ISNULL(c04_periodo_desde,'1900-01-01')<substring(@p_fecha_publicacion,1,7) or (ISNULL(c04_periodo_ano,'1900-01-01')<@periodo_ano and ISNULL(c04_periodo_mes,'1900-01-01')<@periodo_mes))
-- and isnull(visible,1)=1
and ((ISNULL(c04_periodo_desde,'1900-01-01')<substring(@p_fecha_publicacion,1,7))
OR (ISNULL(c04_periodo_ano,'1900')<@periodo_ano and ISNULL(c04_periodo_mes,'01')<=@periodo_mes))
end try
begin catch
end catch
insert into socios (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,c04_periodo_ano,c04_periodo_mes)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,substring(@p_fecha_publicacion,1,7),1,getdate(),@p_user_id,@p_fuente,@periodo_ano,@periodo_mes)
end
else
begin
insert into socios_ai (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,cargo_detalle,contenido_archivo)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,@p_fecha_publicacion,1,getdate(),@p_user_id,@p_fuente,@p_cargo_detalle,@p_contenido_archivo)
end
*/
/*
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER()
END CATCH
*/
GO
GO
CREATE OR ALTER PROCEDURE dbo.igj_insertar
@p_id_tabla int, --Ejemplo de nombre
@p_documento_soc varchar(20),
@p_fecha_publicacion varchar(10),
@p_cargo varchar(50),
@p_documento_integrante varchar(50),
@p_ultdir varchar(1)
AS
BEGIN
--BEGIN TRY
SET NOCOUNT ON;
DECLARE @periodo_ano VARCHAR(4)=NULL
DECLARE @periodo_mes VARCHAR(2)=NULL
/*
select * from igj_autoridades2021
select * from igj_entidades_2021
ALTER TABLE igj_autoridades2021 ADD periodo varchar(10)
*/
/* USAR ESTA CONSULTA MODIFICADA Y CON ESOS REGISTROS MANDARLO A ESTE sp esto va al php*/
select TOP 1000 padrones.identificacion as cuit_socio,igj_entidades_2021.cuit as cuit_sociedad,
descripcion_tipo_administrador as cargo,
'S' as ultimo,
periodo,
idTabla,procesado
--,igj_autoridades2021.*
from igj_autoridades2021
inner join padrones on (igj_autoridades2021.numero_documento=padrones.cuerpo_clave and padrones.habilitado=1)
inner join igj_entidades_2021 on igj_entidades_2021.numero_correlativo=igj_autoridades2021.numero_correlativo
where /*tipo_documento!=5 and */
isnull(igj_autoridades2021.PROCESADO,0) =0 AND
replace(igj_autoridades2021.numero_correlativo,'"','') in (
select distinct numero_correlativo from igj_entidades_2021 where /*dada_de_baja is null and */ cuit is not null)
declare @existe int = 0
select @existe = count(*) from socios where c01_cuit= @p_documento_soc and c01_cuit_soc=@p_documento_integrante and car_codigo= @p_cargo and c04_ultimo= @p_ultdir and fuente = 'IGJ'
if (@existe = 0) --lo tengo que insertar
BEGIN
/*verificar que el registro no exista ya en las mismas condiciones para no duplicar
if (@cuit empresa + cuit persona + cargo + ult dir + fuente IFG == existe
no hacemos nada
else*/
/* ACÁ SE INSERTA EN LA TABLA SOCIOS */
/* SI LOS DATOS NO SON NULOS LO INSERTAMOS EN LA TABLA DE SOCIOS Y SINO EN LA TABLA DE SOCIOS AUXILIAR*/
if (@p_ultdir = 'S')
begin
/* ANTES DE INSERTAR DEBEMOS PASAR TODOS LOS REGISTROS MAS VIEJOS A ULTIMO DIRECTORIO N */
set @periodo_ano=substring(@p_fecha_publicacion,1,4)
set @periodo_mes=substring(@p_fecha_publicacion,6,2)
update socios set c04_ultimo='N',modified=getdate(),modified_by=15342812,c04_periodo_desde=c04_periodo_ano + '-' + c04_periodo_mes
where c01_cuit=@p_documento_soc and c01_cuit_soc=@p_documento_integrante
and ((ISNULL(c04_periodo_desde,'1900-01-01')<substring(@p_fecha_publicacion,1,7))
OR (ISNULL(c04_periodo_ano,'1900')<@periodo_ano and ISNULL(c04_periodo_mes,'01')<=@periodo_mes))
/* FIN DE ACTUALIZAR LOS DIRECTORIOS ANTERIORES */
insert into socios (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,c04_periodo_ano,c04_periodo_mes)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,substring(@p_fecha_publicacion,1,7),1,getdate(),15342812,'IGJ',@periodo_ano,@periodo_mes)
end
else
begin
insert into socios (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,c04_periodo_ano,c04_periodo_mes)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,substring(@p_fecha_publicacion,1,7),1,getdate(),15342812,'IGJ',@periodo_ano,@periodo_mes)
end
UPDATE igj_autoridades2021 SET PROCESADO = 1 WHERE idTabla = @p_id_tabla
END
ELSE
BEGIN
UPDATE igj_autoridades2021 SET PROCESADO = 1 WHERE idTabla = @p_id_tabla
END
END
/*si la razón social es mayor a 2 caracteres asumimos que es cierta y la insertamos. Sino se inserta en la tabla aux para revisarla luego*/
/*
if (len(ltrim(rtrim(@p_razon_social))) < 2)
begin
set @p_razon_social = null
end
if (len(ltrim(rtrim(@p_documento_soc))) < 11)
begin
set @p_documento_soc = null
end
if (len(ltrim(rtrim(@p_documento_integrante))) < 11)
begin
set @p_documento_integrante = null
end
if (len(ltrim(rtrim(@p_fecha_publicacion))) < 10)
begin
set @p_fecha_publicacion = null
end
if (@p_razon_social is not null and @p_cargo !='ZZZ')
begin
INSERT INTO sociedades_constituciones
(id_boletin, documento_soc, razon_social, domicilio_sociedad, localidad_sociedad, provincia_sociedad,
fecha_publicacion, titulo, tipo_publicacion, capita_social, fecha_constitucion, cargo, nombre_integrante,
documento_integrante, domicilio_integrante, localidad_integrante, provincia_integrante, fuente,
codigo_archivo, contenido_archivo, nombre_file, created_by,visible,created,cuit_int,cuit_integrante)
VALUES
(@p_id_boletin, @p_documento_soc, @p_razon_social, @p_domicilio_sociedad, @p_localidad_sociedad, @p_provincia_sociedad,
@p_fecha_publicacion, @p_titulo, @p_tipo_publicacion, @p_capita_social, @p_fecha_constitucion, @p_cargo, @p_nombre_integrante,
@p_documento_integrante, @p_domicilio_integrante, @p_localidad_integrante, @p_provincia_integrante, @p_fuente,
@p_codigo_archivo, @p_contenido_archivo, @p_nombre_file, NULL,1,getdate(),@p_documento_integrante,@p_documento_integrante)
end
if (@p_razon_social is null or @p_cargo ='ZZZ')
BEGIN
INSERT INTO sociedades_constituciones_AI
(id_boletin, documento_soc, razon_social, domicilio_sociedad, localidad_sociedad, provincia_sociedad,
fecha_publicacion, titulo, tipo_publicacion, capita_social, fecha_constitucion, cargo, nombre_integrante,
documento_integrante, domicilio_integrante, localidad_integrante, provincia_integrante, fuente,
codigo_archivo, contenido_archivo, nombre_file, created_by,visible,created,cuit_int,cuit_integrante)
VALUES
(@p_id_boletin, @p_documento_soc, @p_razon_social, @p_domicilio_sociedad, @p_localidad_sociedad, @p_provincia_sociedad,
@p_fecha_publicacion, @p_titulo, @p_tipo_publicacion, @p_capita_social, @p_fecha_constitucion, @p_cargo, @p_nombre_integrante,
@p_documento_integrante, @p_domicilio_integrante, @p_localidad_integrante, @p_provincia_integrante, @p_fuente,
@p_codigo_archivo, @p_contenido_archivo, @p_nombre_file, NULL,1,getdate(),@p_documento_integrante,@p_documento_integrante)
END
if (@p_ultdir = 'S')
begin
declare @existe int = 0
select @existe = count(*) from socios where c01_cuit=@p_documento_soc and c01_cuit_soc=@p_documento_integrante
and ((ISNULL(c04_periodo_desde,'1900-01-01')>substring(@p_fecha_publicacion,1,7))
OR (ISNULL(c04_periodo_ano,'1900')>= @periodo_ano and ISNULL(c04_periodo_mes,'01')>=@periodo_mes))
if (@existe>0)
begin
set @p_ultdir='N'
end
end
if (@p_documento_soc is not null and @p_documento_integrante is not null and @p_fecha_publicacion is not null and @p_cargo !='ZZZ')
begin
begin try
set @periodo_ano=substring(@p_fecha_publicacion,1,4)
set @periodo_mes=substring(@p_fecha_publicacion,6,2)
update socios set c04_ultimo='N',modified=getdate(),modified_by=15342812,c04_periodo_desde=c04_periodo_ano + '-' + c04_periodo_mes
where c01_cuit=@p_documento_soc and c01_cuit_soc=@p_documento_integrante
--and (ISNULL(c04_periodo_desde,'1900-01-01')<substring(@p_fecha_publicacion,1,7) or (ISNULL(c04_periodo_ano,'1900-01-01')<@periodo_ano and ISNULL(c04_periodo_mes,'1900-01-01')<@periodo_mes))
-- and isnull(visible,1)=1
and ((ISNULL(c04_periodo_desde,'1900-01-01')<substring(@p_fecha_publicacion,1,7))
OR (ISNULL(c04_periodo_ano,'1900')<@periodo_ano and ISNULL(c04_periodo_mes,'01')<=@periodo_mes))
end try
begin catch
end catch
insert into socios (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,c04_periodo_ano,c04_periodo_mes)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,substring(@p_fecha_publicacion,1,7),1,getdate(),@p_user_id,@p_fuente,@periodo_ano,@periodo_mes)
end
else
begin
insert into socios_ai (c01_cuit, c01_cuit_soc, car_codigo,c04_ultimo, c04_periodo_desde,visible, created, created_by,fuente,cargo_detalle,contenido_archivo)
values (@p_documento_soc,@p_documento_integrante,@p_cargo,@p_ultdir,@p_fecha_publicacion,1,getdate(),@p_user_id,@p_fuente,@p_cargo_detalle,@p_contenido_archivo)
end
*/
/*
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER()
END CATCH
*/
GO
Used By
No items found