DavidePastore / codice-fiscale

A PHP library to calculate and check the italian tax code (codice fiscale).
GNU General Public License v2.0
100 stars 19 forks source link

Partial check #64

Open Polm90 opened 1 year ago

Polm90 commented 1 year ago

Is it possibile to check if only a part of the codice fiscale is valid? For example, only the name - surname part and/or the lettera di controllo part?

Thank you!

DavidePastore commented 1 year ago

Hi @Polm90. Unfortunately, it's not possible to partially check a codice fiscale with this package. If you are interested in the project, feel free to submit a PR for it.👍

darnel commented 1 year ago

@Polm90 I set up the Subject with name and surname and fills the rest with fictional values. Then checking 6 characters of calculated value with user input:

            $calculator = new Calculator(
                new Subject(
                    [
                        'name' => $name,
                        'surname' => $surname,
                        // fake data to make calculator work
                        'birthDate' => new \DateTimeImmutable('1980-01-01'),
                        'gender' => 'M',
                        'belfioreCode' => 'D641', // Fobello (VC)
                    ]),
                ['omocodiaAllowed' => true]
            );

            $calculated = $calculator->calculate();

            // compare first 6 characters only
            return substr($cf, 0, 6) === substr($calculated, 0, 6);

Is that what you need?

Polm90 commented 1 year ago

Perfect, thank you!