Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
7| Name | Data Type | Length | Description |
|---|---|---|---|
| @FirstName | varchar | 100 | |
| @SurName | varchar | 100 | |
| @IDNumber | varchar | 20 | |
| @Gender | varchar | 1 | |
| @StreetAddress | varchar | 250 | |
| @ZipCode | varchar | 20 | |
| @DateOfBirth | date | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
EXEC [Trulioo_Validacion] 'SORIA', 'ines maria', 'm','CONDARCO 34 PISO 1','1406','1969-05-23','27208925658'
*/
CREATE OR ALTER PROCEDURE dbo.Trulioo_Validacion
@FirstName VARCHAR(100),
@SurName VARCHAR(100),
@IDNumber VARCHAR(20),
@Gender VARCHAR(1) = null,
@StreetAddress VARCHAR(250) = null,
@ZipCode VARCHAR(20) = null,
@DateOfBirth DATE = null
AS
BEGIN
SET NOCOUNT ON;
declare @error_cuit varchar(10) = 'false'
declare @error_name varchar(10) = 'false'
declare @error_address varchar(10) = 'false'
declare @error_zipcode varchar(10) = 'false'
declare @error_nac varchar(10) = 'false'
declare @error_gender varchar(10) = 'false'
declare @resp bit
declare @busqueda_cuit int, @busqueda_igual int, @busqueda_contains int
declare @domicilios table (id int, domicilio varchar(200), pai_nombre varchar(20), prv_nombre varchar(100), loc_nombre varchar(100), codpos varchar(10), tipo_domicilio varchar(10), created datetime)
declare @p_cuit varchar(20) = LTRIM(rtrim(@IDNumber))
/* Cuit */
set @busqueda_cuit = (select count(*)
from padrones
where identificacion = @p_Cuit and habilitado = 1 and tipo_persona != 'J'
and identificador in (select identificador from identificadores where country_code = 'AR'))
if( @busqueda_cuit > 0)
begin
set @error_cuit = 'true'
/* Sexo */
declare @sexo char(1) = (select distinct top 1 sexo
from padrones
where identificacion = @p_Cuit and habilitado = 1 and tipo_persona != 'J'
and identificador in (select identificador from identificadores where country_code = 'AR')
and isnull(sexo, '') != '')
if (isnull(@sexo,'') = '')
begin
set @error_gender = 'true'
end
else
begin
if (@sexo = @gender)
begin
set @error_gender = 'true'
end
end
/* Nombre */
declare @nombre varchar(200) = LTRIM(rtrim(@SurName)) + ' ' + LTRIM(rtrim(@FirstName))
declare @nombre_contains varchar(500)
while (@nombre like '% %')
begin
set @nombre = (select replace(@nombre, ' ', ' '))
end
set @nombre_contains = (select replace(@nombre, ' ' , ' NEAR '))
set @busqueda_igual = (select count(distinct nombre_persona)
from padrones
where identificacion = @p_Cuit and habilitado = 1 and tipo_persona != 'J'
and nombre_persona = @nombre
and identificador in (select identificador from identificadores where country_code = 'AR'))
if( @busqueda_igual > 0)
begin
set @error_name = 'true'
end
else
begin
set @busqueda_contains = (select count(distinct nombre_persona)
from padrones
where identificacion = @p_Cuit
and habilitado = 1
and tipo_persona != 'J'
and contains(nombre_persona, @nombre_contains)
and identificador in(select identificador from identificadores where country_code = 'AR'))
if(@busqueda_contains > 0)
begin
set @error_name = 'true'
end
end
/* Domicilio */
declare @domicilio varchar(200)
declare @codpos varchar(20)
insert into @domicilios exec sp_obtener_domicilios @p_cuit
DECLARE dom CURSOR FOR
select distinct upper(domicilio),
codpos
from @domicilios
OPEN dom
FETCH NEXT FROM dom INTO @domicilio,
@codpos
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
exec @resp = [sp_comparo_domicilios] @domicilio,
@StreetAddress
if (@resp = 1)
begin
set @error_address = 'true'
if (lower(ltrim(rtrim(@codpos))) = lower(ltrim(rtrim(@ZipCode))) )
begin
set @error_zipcode = 'true'
end
BREAK
end
FETCH NEXT FROM dom INTO @domicilio,
@codpos
END
CLOSE dom
DEALLOCATE dom
delete from @domicilios
/* Fecha de Nacimiento */
declare @fecha_nac date = (select c02_fecha_nac from datos_personas where c01_cuit = @p_cuit)
if (@fecha_nac is null)
begin
set @error_nac = 'true'
end
else
begin
if (@fecha_nac = @DateOfBirth)
begin
set @error_nac = 'true'
end
end
end
SELECT
@FirstName as FirstName,
@SurName as SurName,
@Gender as Gender,
@StreetAddress as StreetAddress,
@ZipCode as ZipCode,
@DateOfBirth as DateOfBirth,
@IDNumber as IDNumber,
@error_name as error_Name,
@error_gender as error_Gender,
@error_address as error_Address,
@error_zipcode as error_Zipcode,
@error_nac as error_DateOfBirth,
@error_cuit as error_IDNumber,
'Ok' as financial_status,
GETDATE() as request_date,
'20000' as transaction_id,
1 as transaction_status,
'2018' as period_year,
'10' as period_month,
'100' as period_count
END
/*
select top 1
---------------- Item -----------------------------
p.nombre_persona as nombre_completo,
p.sexo as genero,
dp.c02_fecha_nac as fecha_nac,
dt.domicilio,
dt.codpos as zip,
---------------- GlobalResponseData ---------------
'Ok' as financial_status,
GETDATE() as request_date,
'20000' as transaction_id,
1 as transaction_status,
'2018' as period_year,
'10' as period_month,
'100' as period_count
*/
GO
GO
/*
EXEC [Trulioo_Validacion] 'SORIA', 'ines maria', 'm','CONDARCO 34 PISO 1','1406','1969-05-23','27208925658'
*/
CREATE OR ALTER PROCEDURE dbo.Trulioo_Validacion
@FirstName VARCHAR(100),
@SurName VARCHAR(100),
@IDNumber VARCHAR(20),
@Gender VARCHAR(1) = null,
@StreetAddress VARCHAR(250) = null,
@ZipCode VARCHAR(20) = null,
@DateOfBirth DATE = null
AS
BEGIN
SET NOCOUNT ON;
declare @error_cuit varchar(10) = 'false'
declare @error_name varchar(10) = 'false'
declare @error_address varchar(10) = 'false'
declare @error_zipcode varchar(10) = 'false'
declare @error_nac varchar(10) = 'false'
declare @error_gender varchar(10) = 'false'
declare @resp bit
declare @busqueda_cuit int, @busqueda_igual int, @busqueda_contains int
declare @domicilios table (id int, domicilio varchar(200), pai_nombre varchar(20), prv_nombre varchar(100), loc_nombre varchar(100), codpos varchar(10), tipo_domicilio varchar(10), created datetime)
declare @p_cuit varchar(20) = LTRIM(rtrim(@IDNumber))
/* Cuit */
set @busqueda_cuit = (select count(*)
from padrones
where identificacion = @p_Cuit and habilitado = 1 and tipo_persona != 'J'
and identificador in (select identificador from identificadores where country_code = 'AR'))
if( @busqueda_cuit > 0)
begin
set @error_cuit = 'true'
/* Sexo */
declare @sexo char(1) = (select distinct top 1 sexo
from padrones
where identificacion = @p_Cuit and habilitado = 1 and tipo_persona != 'J'
and identificador in (select identificador from identificadores where country_code = 'AR')
and isnull(sexo, '') != '')
if (isnull(@sexo,'') = '')
begin
set @error_gender = 'true'
end
else
begin
if (@sexo = @gender)
begin
set @error_gender = 'true'
end
end
/* Nombre */
declare @nombre varchar(200) = LTRIM(rtrim(@SurName)) + ' ' + LTRIM(rtrim(@FirstName))
declare @nombre_contains varchar(500)
while (@nombre like '% %')
begin
set @nombre = (select replace(@nombre, ' ', ' '))
end
set @nombre_contains = (select replace(@nombre, ' ' , ' NEAR '))
set @busqueda_igual = (select count(distinct nombre_persona)
from padrones
where identificacion = @p_Cuit and habilitado = 1 and tipo_persona != 'J'
and nombre_persona = @nombre
and identificador in (select identificador from identificadores where country_code = 'AR'))
if( @busqueda_igual > 0)
begin
set @error_name = 'true'
end
else
begin
set @busqueda_contains = (select count(distinct nombre_persona)
from padrones
where identificacion = @p_Cuit
and habilitado = 1
and tipo_persona != 'J'
and contains(nombre_persona, @nombre_contains)
and identificador in(select identificador from identificadores where country_code = 'AR'))
if(@busqueda_contains > 0)
begin
set @error_name = 'true'
end
end
/* Domicilio */
declare @domicilio varchar(200)
declare @codpos varchar(20)
insert into @domicilios exec sp_obtener_domicilios @p_cuit
DECLARE dom CURSOR FOR
select distinct upper(domicilio),
codpos
from @domicilios
OPEN dom
FETCH NEXT FROM dom INTO @domicilio,
@codpos
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
exec @resp = [sp_comparo_domicilios] @domicilio,
@StreetAddress
if (@resp = 1)
begin
set @error_address = 'true'
if (lower(ltrim(rtrim(@codpos))) = lower(ltrim(rtrim(@ZipCode))) )
begin
set @error_zipcode = 'true'
end
BREAK
end
FETCH NEXT FROM dom INTO @domicilio,
@codpos
END
CLOSE dom
DEALLOCATE dom
delete from @domicilios
/* Fecha de Nacimiento */
declare @fecha_nac date = (select c02_fecha_nac from datos_personas where c01_cuit = @p_cuit)
if (@fecha_nac is null)
begin
set @error_nac = 'true'
end
else
begin
if (@fecha_nac = @DateOfBirth)
begin
set @error_nac = 'true'
end
end
end
SELECT
@FirstName as FirstName,
@SurName as SurName,
@Gender as Gender,
@StreetAddress as StreetAddress,
@ZipCode as ZipCode,
@DateOfBirth as DateOfBirth,
@IDNumber as IDNumber,
@error_name as error_Name,
@error_gender as error_Gender,
@error_address as error_Address,
@error_zipcode as error_Zipcode,
@error_nac as error_DateOfBirth,
@error_cuit as error_IDNumber,
'Ok' as financial_status,
GETDATE() as request_date,
'20000' as transaction_id,
1 as transaction_status,
'2018' as period_year,
'10' as period_month,
'100' as period_count
END
/*
select top 1
---------------- Item -----------------------------
p.nombre_persona as nombre_completo,
p.sexo as genero,
dp.c02_fecha_nac as fecha_nac,
dt.domicilio,
dt.codpos as zip,
---------------- GlobalResponseData ---------------
'Ok' as financial_status,
GETDATE() as request_date,
'20000' as transaction_id,
1 as transaction_status,
'2018' as period_year,
'10' as period_month,
'100' as period_count
*/
GO
Depends On
5Used By
No items found