laudis/fiscal

library for common fiscal operations

1.4.0 2021-11-20 21:10 UTC

This package is auto-updated.

Last update: 2024-11-21 23:57:17 UTC


README

Latest Stable Version Total Downloads Monthly Downloads Maintainability Test Coverage MIT License

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