Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
13| Name | Data Type | Length | Description |
|---|---|---|---|
| @identificador | varchar | 10 | |
| @numero | varchar | 50 | |
| @nombre_persona | varchar | 200 | |
| @tipo_persona | varchar | 1 | |
| @sexo | varchar | 1 | |
| @habilitado | bit | 1 | |
| @altaweb | bit | 1 | |
| @consAFIP | bit | 1 | |
| @fecha_nac | date | 3 | |
| @nacionalidad | varchar | 50 | |
| @pais | varchar | 2 | |
| @apellido | varchar | 100 | |
| @nombre | varchar | 100 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
/*
exec backend_insertar_padron 'CUIL','20955578353','ALEID RAMI--borrar','F','M',1,1,1
exec backend_insertar_padron 'CUIT','30955578353','ALEID RAMI EMPRESA--borrar','J',NULL,1,1,1
select * from padrones where identificacion = '30955578353'
select * from consultar_afip where cuit = '30955578353'
SELECT * FROM CONSULTAR_AFIP WHERE PROCESO = 'PADRONESSYNC'
--update padrones set identificador='CUIT' WHERE id_padron=198913604
*/
/*
exec backend_insertar_padron 'CICL' ,'18607033K', NULL,'F','M',1,NULL,0,NULL,NULL,'CL','SITJA MORALES','WILLIAM PATRICIO'
INSERT INTO padrones
(identificador, numero, nombre_persona, tipo_persona, sexo, pre_clave, cuerpo_clave,
suf_clave, habilitado, identificacion, afip_activo, iscreated,apellidos,nombres)
VALUES
('CICL', '18607033K', 'SITJA MORALES WILLIAM PATRICIO', 'F','M', NULL, '18607033K',
NULL, 1, '18607033K', 0, GETDATE(),'SITJA MORALES','WILLIAM PATRICIO')
array(13) { [0]=> string(4) "CICL" [1]=> string(9) "18607033K" [2]=> NULL [3]=> string(1) "F" [4]=> string(1) "M" [5]=> int(1) [6]=> NULL [7]=> int(0) [8]=> NULL [9]=> NULL [10]=> string(2) "CL" [11]=> string(13) "SITJA MORALES" [12]=> string(16) "WILLIAM PATRICIO" }
*/
CREATE OR ALTER PROCEDURE dbo.backend_insertar_padron
-- Add the parameters for the stored procedure here
@identificador varchar(10),
@numero varchar(50),
@nombre_persona varchar(200),
@tipo_persona varchar(1),
@sexo varchar(1),
@habilitado bit,
@altaweb bit=null, /* si es 1 devuelve los datos */
@consAFIP bit=null, /* si es 1 lo manda a afip, para extranjeros enviar 0 */
@fecha_nac date = null,
@nacionalidad varchar(50) = null,
@pais varchar(2) = null,
@apellido varchar(100) = null,
@nombre varchar(100) = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
if (@altaweb is null)
begin
set @altaweb = 0
end
-- Insert statements for procedure here
IF(@identificador <> '' AND @numero <> '') BEGIN
DECLARE @pre_clave varchar(4) = NULL
DECLARE @cuerpo_clave varchar(40) = NULL
DECLARE @suf_clave varchar(4) = NULL
SET @numero = REPLACE(@numero, '/', '')
SET @numero = REPLACE(@numero, '-', '')
SET @numero = REPLACE(@numero, '.', '')
SET @numero = REPLACE(@numero, ',', '')
IF( (UPPER(@identificador) = 'CUIT' OR UPPER(@identificador) = 'CUIL') AND LEN(@numero) = 11) BEGIN
SET @pre_clave = SUBSTRING(@numero,1,2)
SET @cuerpo_clave = SUBSTRING(@numero,3,8)
SET @suf_clave = SUBSTRING(@numero,11,1)
END
ELSE
BEGIN
SET @cuerpo_clave = @numero
END
declare @existe tinyint = 0
declare @idPadronWeb int = 0
IF( (UPPER(@identificador) = 'CUIT' OR UPPER(@identificador) = 'CUIL') AND LEN(@numero) = 11) BEGIN
-- cuit / cuil no chequeo por identificador
SELECT @existe = COUNT(*) from padrones where identificacion = @numero
SELECT @idPadronWeb =id_padron from padrones where identificacion = @numero
END ELSE BEGIN
SELECT @existe = COUNT(*) from padrones where identificacion = @numero and identificador = @identificador
SELECT @idPadronWeb =id_padron from padrones where identificacion = @numero and identificador = @identificador
END
if(@existe=0)
begin
if (@nombre_persona is null)
begin
set @nombre_persona = ISNULL(@apellido,'') + ' ' + ISNULL(@nombre,'')
end
set @nombre_persona = LTRIM(RTRIM(@nombre_persona))
INSERT INTO padrones
(identificador, numero, nombre_persona, tipo_persona, sexo, pre_clave, cuerpo_clave,
suf_clave, habilitado, identificacion, afip_activo, iscreated,apellidos,nombres)
VALUES
(@identificador, @numero, UPPER(@nombre_persona), UPPER(@tipo_persona), UPPER(@sexo), @pre_clave, @cuerpo_clave,
@suf_clave, @habilitado, @numero, 1, GETDATE(),@apellido,@nombre)
select @idPadronWeb = @@IDENTITY
if (@altaweb = 0)
begin
select 'ok' as mensaje
END
if (@consAFIP = 1)
BEGIN
INSERT INTO consultar_afip (proceso,cuit,fecha,procesado,ierror,prioridad,id_taken)
VALUES ('PADRONESSYNC', @numero, getdate(),0,0, 2,0)
END
END
else
begin
if (@altaweb = 0)
begin
select 'duplicado' as mensaje
end
end
--if (@idPadronWeb > 0 and @pais!='AR')
if (@idPadronWeb > 0 and (@fecha_nac is not null or @nacionalidad is not null))
BEGIN
insert into datos_personas (c01_cuit,id_padron,c02_fecha_nac,nacionalidad)
values (@numero,@idPadronWeb,@fecha_nac,@nacionalidad)
end
if (@altaweb = 1 AND @idPadronWeb > 0)
BEGIN
select padrones.*,identificadores.country_code,identificadores.abreviatura from padrones inner join identificadores on padrones.identificador=identificadores.identificador where id_padron = @idPadronWeb
/*
select padrones.*,identificadores.country_code,identificadores.abreviatura from padrones inner join identificadores on padrones.identificador=identificadores.identificador where id_padron = 206093670
*/
end
END
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
/*
exec backend_insertar_padron 'CUIL','20955578353','ALEID RAMI--borrar','F','M',1,1,1
exec backend_insertar_padron 'CUIT','30955578353','ALEID RAMI EMPRESA--borrar','J',NULL,1,1,1
select * from padrones where identificacion = '30955578353'
select * from consultar_afip where cuit = '30955578353'
SELECT * FROM CONSULTAR_AFIP WHERE PROCESO = 'PADRONESSYNC'
--update padrones set identificador='CUIT' WHERE id_padron=198913604
*/
/*
exec backend_insertar_padron 'CICL' ,'18607033K', NULL,'F','M',1,NULL,0,NULL,NULL,'CL','SITJA MORALES','WILLIAM PATRICIO'
INSERT INTO padrones
(identificador, numero, nombre_persona, tipo_persona, sexo, pre_clave, cuerpo_clave,
suf_clave, habilitado, identificacion, afip_activo, iscreated,apellidos,nombres)
VALUES
('CICL', '18607033K', 'SITJA MORALES WILLIAM PATRICIO', 'F','M', NULL, '18607033K',
NULL, 1, '18607033K', 0, GETDATE(),'SITJA MORALES','WILLIAM PATRICIO')
array(13) { [0]=> string(4) "CICL" [1]=> string(9) "18607033K" [2]=> NULL [3]=> string(1) "F" [4]=> string(1) "M" [5]=> int(1) [6]=> NULL [7]=> int(0) [8]=> NULL [9]=> NULL [10]=> string(2) "CL" [11]=> string(13) "SITJA MORALES" [12]=> string(16) "WILLIAM PATRICIO" }
*/
CREATE OR ALTER PROCEDURE dbo.backend_insertar_padron
-- Add the parameters for the stored procedure here
@identificador varchar(10),
@numero varchar(50),
@nombre_persona varchar(200),
@tipo_persona varchar(1),
@sexo varchar(1),
@habilitado bit,
@altaweb bit=null, /* si es 1 devuelve los datos */
@consAFIP bit=null, /* si es 1 lo manda a afip, para extranjeros enviar 0 */
@fecha_nac date = null,
@nacionalidad varchar(50) = null,
@pais varchar(2) = null,
@apellido varchar(100) = null,
@nombre varchar(100) = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
if (@altaweb is null)
begin
set @altaweb = 0
end
-- Insert statements for procedure here
IF(@identificador <> '' AND @numero <> '') BEGIN
DECLARE @pre_clave varchar(4) = NULL
DECLARE @cuerpo_clave varchar(40) = NULL
DECLARE @suf_clave varchar(4) = NULL
SET @numero = REPLACE(@numero, '/', '')
SET @numero = REPLACE(@numero, '-', '')
SET @numero = REPLACE(@numero, '.', '')
SET @numero = REPLACE(@numero, ',', '')
IF( (UPPER(@identificador) = 'CUIT' OR UPPER(@identificador) = 'CUIL') AND LEN(@numero) = 11) BEGIN
SET @pre_clave = SUBSTRING(@numero,1,2)
SET @cuerpo_clave = SUBSTRING(@numero,3,8)
SET @suf_clave = SUBSTRING(@numero,11,1)
END
ELSE
BEGIN
SET @cuerpo_clave = @numero
END
declare @existe tinyint = 0
declare @idPadronWeb int = 0
IF( (UPPER(@identificador) = 'CUIT' OR UPPER(@identificador) = 'CUIL') AND LEN(@numero) = 11) BEGIN
-- cuit / cuil no chequeo por identificador
SELECT @existe = COUNT(*) from padrones where identificacion = @numero
SELECT @idPadronWeb =id_padron from padrones where identificacion = @numero
END ELSE BEGIN
SELECT @existe = COUNT(*) from padrones where identificacion = @numero and identificador = @identificador
SELECT @idPadronWeb =id_padron from padrones where identificacion = @numero and identificador = @identificador
END
if(@existe=0)
begin
if (@nombre_persona is null)
begin
set @nombre_persona = ISNULL(@apellido,'') + ' ' + ISNULL(@nombre,'')
end
set @nombre_persona = LTRIM(RTRIM(@nombre_persona))
INSERT INTO padrones
(identificador, numero, nombre_persona, tipo_persona, sexo, pre_clave, cuerpo_clave,
suf_clave, habilitado, identificacion, afip_activo, iscreated,apellidos,nombres)
VALUES
(@identificador, @numero, UPPER(@nombre_persona), UPPER(@tipo_persona), UPPER(@sexo), @pre_clave, @cuerpo_clave,
@suf_clave, @habilitado, @numero, 1, GETDATE(),@apellido,@nombre)
select @idPadronWeb = @@IDENTITY
if (@altaweb = 0)
begin
select 'ok' as mensaje
END
if (@consAFIP = 1)
BEGIN
INSERT INTO consultar_afip (proceso,cuit,fecha,procesado,ierror,prioridad,id_taken)
VALUES ('PADRONESSYNC', @numero, getdate(),0,0, 2,0)
END
END
else
begin
if (@altaweb = 0)
begin
select 'duplicado' as mensaje
end
end
--if (@idPadronWeb > 0 and @pais!='AR')
if (@idPadronWeb > 0 and (@fecha_nac is not null or @nacionalidad is not null))
BEGIN
insert into datos_personas (c01_cuit,id_padron,c02_fecha_nac,nacionalidad)
values (@numero,@idPadronWeb,@fecha_nac,@nacionalidad)
end
if (@altaweb = 1 AND @idPadronWeb > 0)
BEGIN
select padrones.*,identificadores.country_code,identificadores.abreviatura from padrones inner join identificadores on padrones.identificador=identificadores.identificador where id_padron = @idPadronWeb
/*
select padrones.*,identificadores.country_code,identificadores.abreviatura from padrones inner join identificadores on padrones.identificador=identificadores.identificador where id_padron = 206093670
*/
end
END
END
GO