Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
5| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_cuit | varchar | 20 | |
| @p_id_padron | varchar | 50 | |
| @p_razon_social | varchar | 100 | |
| @p_identificador | varchar | 10 | |
| @p_tipo_persona | varchar | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.carga_datos_padron_pj_afip
@p_cuit varchar(20),
@p_id_padron varchar(50),
@p_razon_social varchar(100),
@p_identificador varchar(10),
@p_tipo_persona varchar(1)
AS
BEGIN
IF((select COUNT(*) from padrones where (id_padron = @p_id_padron) and (habilitado = 1)
and (((nombre_persona is not null and @p_razon_social is not null) and (nombre_persona != @p_razon_social)) or (nombre_persona is null and @p_razon_social is not null))) > 0)
begin
begin try
declare @nombre_anterior varchar(100) = (select nombre_persona from padrones where (id_padron = @p_id_padron))
declare @identificador varchar(10) = (select identificador from padrones where (id_padron = @p_id_padron))
declare @tipo_persona varchar(1) = (select tipo_persona from padrones where (id_padron = @p_id_padron))
if ((select COUNT(*) from nombres_anteriores where (cuit = @p_cuit)) > 0)
begin
declare @nombre1 varchar(100) = (select top 1 nombre1 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre2 varchar(100) = (select top 1 nombre2 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre3 varchar(100) = (select top 1 nombre3 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre4 varchar(100) = (select top 1 nombre4 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre5 varchar(100) = (select top 1 nombre5 from nombres_anteriores where (cuit = @p_cuit))
if (@nombre1 is null)
begin
update nombres_anteriores set nombre1 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre2 is null)
begin
update nombres_anteriores set nombre2 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre3 is null)
begin
update nombres_anteriores set nombre3 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre4 is null)
begin
update nombres_anteriores set nombre4 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre5 is null)
begin
update nombres_anteriores set nombre5 = @nombre_anterior where (cuit = @p_cuit)
end
end
else
begin
insert into nombres_anteriores (cuit, nombre1) values (@p_cuit, @nombre_anterior)
end
/*
set @nombre_anterior = iif (@p_razon_social is not null, @p_razon_social, @nombre_anterior)
set @identificador = iif (@p_identificador is not null, @p_identificador, @identificador)
set @tipo_persona = iif (@p_tipo_persona is not null, @p_tipo_persona, @tipo_persona)
update padrones set
nombre_persona = @nombre_anterior,
--identificador = @identificador,
tipo_persona = @tipo_persona,
ismodified = GETDATE()
where (id_padron = @p_id_padron) and (habilitado = 1)
select 'ok' as ok
*/
set @nombre_anterior = iif (isnull(@p_razon_social,'') !='', @p_razon_social, @nombre_anterior)
set @identificador = iif (isnull(@p_identificador,'') != '', @p_identificador, @identificador)
set @tipo_persona = iif (isnull(@p_tipo_persona,'') != '', @p_tipo_persona, @tipo_persona)
update padrones set
--nombre_persona = @nombre_anterior,
nombre_persona = iif((isnull(modificado_por,'') != 'R' or isnull(nombre_persona,'') = '') and isnull(@nombre_anterior,'') != '',
@nombre_anterior,nombre_persona),
--identificador = @identificador,
tipo_persona = @tipo_persona,
ismodified = GETDATE(),
/*
habilitado = iif(isnull(@p_razon_social,'') != '', 1, 0) --> si el nombre viene vacio de AFIP, avisamos pero lo dejamos habilitado (31/7/2018)
*/
habilitado = iif (isnull(@p_razon_social,'') !='',1,1)
where (id_padron = @p_id_padron) and (habilitado = 1)
select 'ok' as ok
end try
begin catch
select ERROR_MESSAGE() as error
end catch
end
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.carga_datos_padron_pj_afip
@p_cuit varchar(20),
@p_id_padron varchar(50),
@p_razon_social varchar(100),
@p_identificador varchar(10),
@p_tipo_persona varchar(1)
AS
BEGIN
IF((select COUNT(*) from padrones where (id_padron = @p_id_padron) and (habilitado = 1)
and (((nombre_persona is not null and @p_razon_social is not null) and (nombre_persona != @p_razon_social)) or (nombre_persona is null and @p_razon_social is not null))) > 0)
begin
begin try
declare @nombre_anterior varchar(100) = (select nombre_persona from padrones where (id_padron = @p_id_padron))
declare @identificador varchar(10) = (select identificador from padrones where (id_padron = @p_id_padron))
declare @tipo_persona varchar(1) = (select tipo_persona from padrones where (id_padron = @p_id_padron))
if ((select COUNT(*) from nombres_anteriores where (cuit = @p_cuit)) > 0)
begin
declare @nombre1 varchar(100) = (select top 1 nombre1 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre2 varchar(100) = (select top 1 nombre2 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre3 varchar(100) = (select top 1 nombre3 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre4 varchar(100) = (select top 1 nombre4 from nombres_anteriores where (cuit = @p_cuit))
declare @nombre5 varchar(100) = (select top 1 nombre5 from nombres_anteriores where (cuit = @p_cuit))
if (@nombre1 is null)
begin
update nombres_anteriores set nombre1 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre2 is null)
begin
update nombres_anteriores set nombre2 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre3 is null)
begin
update nombres_anteriores set nombre3 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre4 is null)
begin
update nombres_anteriores set nombre4 = @nombre_anterior where (cuit = @p_cuit)
end
else if (@nombre5 is null)
begin
update nombres_anteriores set nombre5 = @nombre_anterior where (cuit = @p_cuit)
end
end
else
begin
insert into nombres_anteriores (cuit, nombre1) values (@p_cuit, @nombre_anterior)
end
/*
set @nombre_anterior = iif (@p_razon_social is not null, @p_razon_social, @nombre_anterior)
set @identificador = iif (@p_identificador is not null, @p_identificador, @identificador)
set @tipo_persona = iif (@p_tipo_persona is not null, @p_tipo_persona, @tipo_persona)
update padrones set
nombre_persona = @nombre_anterior,
--identificador = @identificador,
tipo_persona = @tipo_persona,
ismodified = GETDATE()
where (id_padron = @p_id_padron) and (habilitado = 1)
select 'ok' as ok
*/
set @nombre_anterior = iif (isnull(@p_razon_social,'') !='', @p_razon_social, @nombre_anterior)
set @identificador = iif (isnull(@p_identificador,'') != '', @p_identificador, @identificador)
set @tipo_persona = iif (isnull(@p_tipo_persona,'') != '', @p_tipo_persona, @tipo_persona)
update padrones set
--nombre_persona = @nombre_anterior,
nombre_persona = iif((isnull(modificado_por,'') != 'R' or isnull(nombre_persona,'') = '') and isnull(@nombre_anterior,'') != '',
@nombre_anterior,nombre_persona),
--identificador = @identificador,
tipo_persona = @tipo_persona,
ismodified = GETDATE(),
/*
habilitado = iif(isnull(@p_razon_social,'') != '', 1, 0) --> si el nombre viene vacio de AFIP, avisamos pero lo dejamos habilitado (31/7/2018)
*/
habilitado = iif (isnull(@p_razon_social,'') !='',1,1)
where (id_padron = @p_id_padron) and (habilitado = 1)
select 'ok' as ok
end try
begin catch
select ERROR_MESSAGE() as error
end catch
end
END
GO
Depends On
2Used By
No items found