Giter VIP home page Giter VIP logo

Comments (16)

MollieRick avatar MollieRick commented on June 19, 2024 2

I can disclose my VAT number: (removed since its not necessary anymore)

from vies.

krzaczek avatar krzaczek commented on June 19, 2024 1

Found it: http://kleineondernemer.nl/index.php/nieuw-btw-identificatienummer-vanaf-1-januari-2020-voor-eenmanszaken

from vies.

krzaczek avatar krzaczek commented on June 19, 2024 1

That's my plan . I will validate the TIN against both algo. If the first one fails -> will try the new one

from vies.

krzaczek avatar krzaczek commented on June 19, 2024 1

Waiting for code review ....

from vies.

DragonBe avatar DragonBe commented on June 19, 2024 1

Sorry being late at the game, this holiday time is for me the only time I can truly spend with my family in full. But now when they're off playing games themselves, I can have a look at this.

from vies.

Smitsel avatar Smitsel commented on June 19, 2024 1

Many thanks for the fast fix! 🥇

from vies.

krzaczek avatar krzaczek commented on June 19, 2024

@Smitsel Could You provide an example VAT number that validates in VIES and does not pass a checksum test ?

from vies.

Smitsel avatar Smitsel commented on June 19, 2024

Yes, for example: NL000099998B57

Taken from: https://www.belastingdienst.nl/wps/wcm/connect/nl/btw/content/gebruik-vanaf-1-januari-2020-uw-nieuwe-btw-identificatienummer

I can not disclose any real VAT numbers ofcourse.

from vies.

krzaczek avatar krzaczek commented on June 19, 2024

@MollieRick thx. Yep Your number validates in VIES but there is no information on the new algorithm to calculate the checksum. I'll try to google a little bit more but i may be easier to look for it in Dutch rather than in English ;)

from vies.

Smitsel avatar Smitsel commented on June 19, 2024

We've looked for it as well, could not find any information about calculating the checksum.
I will try to find a contact with the dutch government.

from vies.

krzaczek avatar krzaczek commented on June 19, 2024

Yep it works 23210023426721142 % 97 = 1 - so it's correct. Now I just need to find a way to distinguish old numbers from the new one's so that both validate ;)

from vies.

Smitsel avatar Smitsel commented on June 19, 2024

If they can't be differentiated you could do it by doing this check when the first one fails.
So in a failover kind of way.

from vies.

Smitsel avatar Smitsel commented on June 19, 2024

We can totally review your PR once you have something too btw.

from vies.

Smitsel avatar Smitsel commented on June 19, 2024

Awesome, i left some not super important comments. It works as intended, i've tried it out in our fork.

from vies.

krzaczek avatar krzaczek commented on June 19, 2024

@Smitsel should be fine now. I did add a regex expression to check if the number has only valid characters before calculating checksum [0-9A-Z+*]. This way it should be safer. In the older version there was a small % of chance that a number with an invalid char would validate :) It would then error on VIES but still :)

from vies.

AleksanderGladkov avatar AleksanderGladkov commented on June 19, 2024

Found this page in google, thanks to all participants for the information.
To those who also gets to this page, here is my version of this algorithm in C#. The simple conversion of VAT number to integer can cause overflow error, because the maximum length of converted VAT number is 26, while the max length of ulong type in C# is 20. Therefore I write converted VAT number to a string first and then subsequently convert the string to an integer and divide it by 97.

// Positions 1-2 must be NL, positions 13-14 must be digits. Positions 3-12 can contain digits, uppercase letters, '+' and '*'.
// Each letter is replaced by two-digit number, where 'A' = 10, 'B' = 11, ..., 'Z' = 35; '+' = 36, '*' = 37.
// Remainder of division the converted VAT number by 97 must be equal to 1.
// Example: NL123456789B13 is converted to 2321 123456789 11 13, i.e. to 23211234567891113 integer number. 23211234567891113 mod 97 = 1, it is a valid VAT number.

public void ValidateVatMod97Algorithm(string vat) {
    if (vat.Length != 14) {
        throw new System.Exception("VAT must have exactly 14 chars");
    }

    if (vat.Substring(0, 2) != "NL") {
        throw new System.FormatException("First two chars must be NL");
    }
    
    if (!char.IsDigit(vat[12]) || !char.IsDigit(vat[13])) {
        throw new System.FormatException("Last two chars must be digits");
    }
    // we can also check that the two-digit number in the end is between 02 and 98.
    
    var sb = new StringBuilder();
    foreach (char ch in vat) {
        int currNumber = 0;

        if (char.IsDigit(ch)) currNumber = ch - '0';
        else if (char.IsUpper(ch)) currNumber = ch - 55;
        else if (ch == '+') currNumber = 36;
        else if (ch == '*') currNumber = 37;
        else throw new System.FormatException("VAT contains incorrect chars");

        sb.Append(currNumber);
    }

    string vatDigitString = sb.ToString();
    int remainder = 0;
    foreach (char ch in vatDigitString) {
        int digit = ch - '0';
        remainder = (remainder * 10 + digit) % 97;
    }

    if (remainder != 1) {
        throw new System.FormatException("VAT is not valid according to the Modulus-97 checksum algorithm.");
    }
}

from vies.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.