Add support for Mozambique TIN (CUIT) #473
Open
+264
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #360
Based on #392
Source
In the following government webpage it is effectively possible to check the validity of CUIT numbers.
https://nuit.at.gov.mz/nuit/bootstrap/theme/work/Impressao_Carta.aspx
To validate a CUIT the user should enter it in the first field (without any separation characters) and either enter a date in the second field or check "NUIT COLECTIVO". He can then press the blue button with written "Pesquisar"
2.1. if an incorrect birth date was entered, this error message is showed in light red: "Por favor, dirija-se a uma Unidade Orgânica da Autoridade Tributária afim de resolver problemas de validação do seu NUIT."
2.2. if the entered date was correct, or "NUIT COLECTIVO" was selected, the user is redirected to a page where he can download a document that certifies that that CUIT number was issued on a certain date to a certain individual or company.
CUIT doctest
From the numbers incluced in the doctest in #392, every one is considered valid from the above website, except two:
Since this could be easily explained by there being a typo in these two instances (2 out of 86), the above numbers have been excluded from the doctest.
Checksum validation
The checksum algorithm has been reverse engineered from the above website as follows:
The checksum of a given number can be determined by trial and error.
Comparing the checksum of numbers differing by only one digit, it turns out to follow a regular sequence of 11 digits:
the sequence for the first digit is the same as taking every 8th digit from the number 01234567891 (looping back when necessary), for the second digit you take every 9th number, for the third every 4th and so on. These are the weights in the mod 11 algorithm.
The algorithm obtained by the above method was checked against the numbers in the doctest. Also a collection of randomly generated numbers with the check digit calculated by the algorithm have been checked on the above website.