Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Spain country handler to support Natural Persons without DNI or NIE and Non-Natural Persons TIN formats #36

Closed
wants to merge 0 commits into from

Conversation

alphp
Copy link
Contributor

@alphp alphp commented Apr 19, 2024

This PR

  • Refactor Spanish country handler to support Natural Persons without DNI or NIE and Non-Natural Persons TIN formats
  • Documentation

Spanish Natural Persons without DNI or NIE and Non-Natural Persons TIN formats:

Format Explanation Comments Example
K9999999C Letter K + 7 digits + 1 Control character Resident Spaniards under 14 without DNI K0867756I
L9999999C Letter L + 7 digits + 1 Control character Non-resident Spaniards without DNI L2812345C
M9999999C Letter M + 7 digits + 1 Control character Foreigners without NIE M2812345C
L9999999C 1 Letter + 7 digits + 1 Control character Non-Natural Persons P2009300A

@alphp alphp requested a review from lekoala as a code owner April 19, 2024 12:26
@drupol
Copy link
Contributor

drupol commented Apr 19, 2024

Hello,

Are these changes from somewhere? Can you please provide the documentation?

In the TIN specifications hasn't been updated since 2019, do you have an updated specification?

Thanks!

@alphp
Copy link
Contributor Author

alphp commented Apr 19, 2024

I have refactored the code according to the validation that I created in 2015 and with which I have validated hundreds of TINs from public organizations in Spain.
https://lab.fawno.com/2015/08/27/validacion-de-cif-nif/

The code is based on the information collected in the Spanish Wikipedia:
https://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal

Right now I do not have official sources on the validation of Spanish TINs. If I find something I will share it here.

@alphp
Copy link
Contributor Author

alphp commented Apr 19, 2024

The 'P2009300A' corresponds to the City Council of Mendaro (Gipuzkoa, Spain) and is one of the many CIFs that did not validate the current code:
https://www.euskadi.eus/ac70cPublicidadWar/trazabilidad/336188?idioma=es&R01HNoPortal=true
The CIF 'B05327986' is based on a real company code, but modified so that, although valid, it does not correspond to any company.

Estos son validadores online que validan correctamente los TIN con los que he tenido problemas:
https://factura.city/validar-vat
https://www.validardni.es/

@drupol
Copy link
Contributor

drupol commented Apr 19, 2024

Let's be consistent here to make sure that the message you're trying to tell me is well understood.

From what I understand:

  1. You've created a Spain TIN validator, used hundreds of times.
  2. Its code is based on Wikipedia
  3. You would like to implement updates so that more Spain TINs can be supported?

Questions:

  1. Is CIF equals TIN ? Can you please clarify that?
  2. Can we please continue the conversation in English. I don't really speak Spanish even though I think I have understood what you meant.

Thoughts:

Regarding making changes, I wish I could have official sources to implement these changes, even though they seem totally correct. Do you know where we can find that documentation?

@alphp
Copy link
Contributor Author

alphp commented Apr 19, 2024

The Código de Identificación Fiscal (CIF, tax identification code) was the name given to TINs in Spain from 1975 to 2008.
https://www.boe.es/buscar/doc.php?id=BOE-A-1975-21698
https://www.boe.es/buscar/act.php?id=BOE-A-2008-3580

For historical reasons, we commonly call the TIN of a company, organization or public entity as CIF.

There are three algorithms:

  1. For natural persons (real people): Spain::PATTERN_1
    https://www.interior.gob.es/opencms/ca/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
  2. For legal entities (companies, organizations and public entities):
    a. Ended in control digit (0-9): Spain::PATTERN_2
    b. Ending in control letter (A-J): Spain::PATTERN_3

From experience I know that my implementation is correct, I have been able to verify it with hundreds of TINs of different types of legal entities.

I am looking for information on official sites such as pages of the Spanish Government or the BOE (where the laws are published).
I also prefer to have official references.

@drupol
Copy link
Contributor

drupol commented Apr 19, 2024

Thanks, I also wrote an email to DG Taxud for having more official informations too, I'll keep you posted.

@alphp
Copy link
Contributor Author

alphp commented Apr 19, 2024

This document is interesting, it is on a Spanish Government website but it is prepared from information from a forum or similar:
https://www.mapa.gob.es/app/materialvegetal/docs/CIF.pdf
It is interesting because the code follows the algorithm described on Wikipedia, which I have implemented. Except that it only contemplates two types of CIF that end in a letter, when there are a few more cases.
I keep searching, but I probably won't find an official source, this is Spain and its public administration.

@alphp
Copy link
Contributor Author

alphp commented Apr 20, 2024

I have found a public administration that describes the validation algorithm for TINs of legal entities.
This is the Junta de Andalucía, the highest public institution of the autonomous community of Andalusia.
The help website for software development for public administration describes the two algorithms for verifying Spanish TINs.
This is the link:
https://www.juntadeandalucia.es/servicios/madeja/sites/default/files/historico/1.4.0/contenido-libro-pautas-196.html#Validacion_de_NIF_con_tipo_distinto_a_DNI

Unfortunately it does not provide information about the regulations where these algorithms are defined. However, we have a description of them from an institutional website.

Screenshot 2024-04-20 at 13-02-51 NIF Marco de Desarrollo de la Junta de Andalucía

@alphp alphp changed the title Refactor Spain country handler to support more Spanish TIN Refactor Spain country handler to support Natural Persons without DNI or NIE and Non-Natural Persons TIN formats Apr 22, 2024
@drupol
Copy link
Contributor

drupol commented Jun 6, 2024

Please don't use merge but do a simple rebase... it will be easier for me to review.

@alphp
Copy link
Contributor Author

alphp commented Jun 6, 2024

Something went wrong while trying to rebase.
I have created a new branch and a new PR #41 with the changes applied to the last commit of the master branch.

@alphp alphp closed this Jun 6, 2024
@drupol drupol reopened this Jun 6, 2024
@drupol drupol closed this Jun 6, 2024
@drupol drupol mentioned this pull request Jun 6, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants