This is a wrapper of kdeldycke/vat-rates.
composer require webhub/vat
use Webhub\Vat\Rates;
$rate = (new Rates)->in('NL')->current()->get();
$rate->rate(); // 0.21
$rate->currencyCode(); // 'EUR'
$rate = (new Rates)->in('BE')->at('1990-01-01')->get();
$rate->rate(); // 0.12A Rates instance is a collection of rates.
Rates can be filtered:
->in(string $territory)a territory likeDEorNL->at(string|Carbon $when)a date like2018-01-05, supports Carbon->current()alias for->at(Carbon::now())->type(string $type)rate type, currently the database only contains standard rates.
When one rate remains, the ->get() : Rate method retrieves it, otherwise it throws.
Obtain all rates through ->all() : array.
A Rate has:
->rate() : stringdecimal fraction representation of the rate, e.g. '0.20' for 20%->rateType() : stringtype of the rate, currentlystandard.->(start|stop)Date() : CarbonCarbon date instance of first valid day and subsequent first not-valid day.->currencyCode() : stringcurrency likeSEKorEUR->description() : ?stringoptional description of the rate
Rates proxies method calls to the underlying Rate if it exists and is unique.
// with ->get()
(new Rates)->in('DE')->current()->get()->rate();
// equals shorter:
(new Rates)->in('DE')->current()->rate();
// non unique
(new Rates)->in('FR')->rate(); // throws AmbiguousResultException
(new Rates)->in('XX')->get(); // throws NoResultExceptionA Rate implements ArrayAccess, so when using with for example Laravel's Collection, this is perfectly possible:
collect((new Rates)->in('NL')->all())
->sortBy('start_date')
->pluck('rate', 'start_date');Data is obtained from kdeldycke/vat-rates and written to a PHP file data.php that is included in Rates.
composer install
composer run build // runs Generator::generate()