lytrax / afm
Greek AFM (TIN) validator and generator
Requires
- php: >=7.2.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-11-07 08:30:02 UTC
README
Validate and generate Greek TIN (Tax Identification Number) / AFM (Αριθμός Φορολογικού Μητρώου). Generation function can create valid or invalid numbers including parameters for old format, individuals, legal entities and repet tolerance digits control.
Online demo and presentation
https://lytrax.io/blog/projects/greek-tin-validator-generator
Installation
composer require lytrax/afm
Usage
Use one or more functions:
use function Lytrax\AFM\validateAFM; use function Lytrax\AFM\generateAFM; use function Lytrax\AFM\generateValidAFM; use function Lytrax\AFM\generateInvalidAFM;
Validate a number:
validateAFM('090000045'); bool(true) validateAFM('123456789'); bool(false)
Generate a valid number:
generateValidAFM(); string(9) "731385437"
Generate an invalid number:
generateInvalidAFM(); string(9) "853003357"
API
validateAFM ($afm, $params = [])
$afm: string
- A number to be checked$params: array (optional)
- Optional associative array for named parameters$params['extendedResult']: boolean = false
- Return aboolean
orarray
- Returns:
boolean
orarray
(Associative array withvalid: boolean
anderror: string ('length' or 'nan' or 'zero' or 'invalid')
)
Example:
validateAFM('ab1234', ['extendedResult' => true]); array(2) { ["valid"]=> bool(false) ["error"]=> string(6) "length" }
generateAFM ($params = [])
$params: array (optional)
- Optional associative array for named parameters$params['forceFirstDigit']: null|int (optional)
- If specified, overrides all pre99, legalEntity and individual$params['pre99']: boolean = false
- Για ΑΦΜ πριν από 1/1/1999 (ξεκινάει με 0), (if true, overrides both legalEntity and individual)$params['individual']: boolean = false
- Φυσικά πρόσωπα, (ξεκινάει με 1-4)$params['legalEntity']: boolean = false
- Νομικές οντότητες (ξεκινάει με 7-9)$params['repeatTolerance']: null|int (optional)
- Number for max repeat tolerance (0 for no repeats, unspecified for no check)$params['valid']: boolean = true
- Generate valid or invalid AFM- Returns:
string
- A valid or invalid 9 digit AFM number
Example:
generateAFM([ 'forceFirstDigit' => 3, 'repeatTolerance' => 1, 'valid' => true ]); string(9) "335151580"
generateValidAFM - Same as generateAFM
with $params['valid']
force and override to true
- Returns:
string
- A valid 9 digit AFM number
Example:
generateValidAFM(['pre99' => true]); string(9) "070825250"
generateInvalidAFM - Same as generateAFM
with $params['valid']
force and override to false
- Returns:
string
- An invalid 9 digit AFM number
Example:
generateInvalidAFM(['legalEntity' => true]); string(9) "877577341"
Test
Clone this repository, intall packages and run PHPUnit:
git clone https://github.com/clytras/afm-php.git && cd afm-php
composer install
./vendor/bin/phpunit --testdox
Run Demo:
php ./demo/index.php
Changelog
See CHANGELOG
License
MIT License - see the LICENSE file for details