laudis / fiscal
library for common fiscal operations
Requires
- ext-json: *
- ext-pdo: *
- laudis/typed-enum: ^1.0
- php-ds/php-ds: ^1.0
Requires (Dev)
- ext-json: *
- cocur/slugify: ^4.0
- fakerphp/faker: ^1.16
- friendsofphp/php-cs-fixer: ^3.3
- phpunit/phpunit: ^9.0
- psalm/plugin-phpunit: ^0.16
- robmorgan/phinx: ^0.12.4
- symfony/uid: ^5.2
- vimeo/psalm: ^4.12
README
Installation
Install via composer:
composer require laudis/fiscal
General usage
Laudis fiscal library is essentially a client which pulls fiscal information from a database and provides classes to translate it into business logic.
Initializing the repository
Everything starts from the repository:
$repository = new \Laudis\Fiscal\FiscalRepository(new PDO(getenv('PDO_DSN'), getenv('USERNAME'), getenv('PASSWORD')));
Loading indexed values
Indexed values a values that change over a period in time. Laudis fiscal interprets indexed values as essentially ranges of dates with a value and some identifying information.
// The date argument can either be a string in the Y-m-d format, an integer representing a timestamp, or an object implementing \DateTimeInterface. $values = $repository->loadIndexedValuesWithSlugs('2010-01-01', ['cpi', 'euribor', 'protected-property-car-amount-AUS']); $euribor = $values->get('euribor'); // Returns the euribor of that day $cpi = $values->get('cpi'); // Throws OutOfBoundsException if it wasn't found for that day $protected = $values->get('protected-property-car-amount-AUS', null); // Will return null instead of throwing when it wasn't found on that day.
Loading scales
Scales are a combination of ranges composed by rules which in turn will apply a factor on the value of each of these rules.
Example:
Scale personal tax Belgium taxation year 2020 (yes this is real):
Laudis fiscal understands this logic which they can be loaded like this:
$scale = $repository->loadScaleWithSlugs(DateTime::createFromFormat('Y-m-d', '2020-01-01'), ['personal-tax'])->first(); echo $scale->calculate(50000); // echos 13 250.00 echo $scale->calculate(8000); // echos 2000
Scales can further be exploited to fully explain the logic they are doing:
$explanation = $scale->explain(50000);
Fiscal Feature Support
Requirements
- PHP >= 7.4
- A mariadb/mysql database
- ext-json
- ext-pdo
- ext-pdo_mysql