PHP code example of fidelo-software / vatrates

1. Go to this page and download the library: Download fidelo-software/vatrates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fidelo-software / vatrates example snippets

 js
vatRates.getCountry('UK'); // -> same result as 'GB'
 php
$vatRates = new VATRates();
if ($vatRates->isVATCountry('RO')) {
    var_dump($vatRates->getSuperReducedRate('RO')); // -> null
    var_dump($vatRates->getReducedRates('RO'));     // -> [5, 9]
    var_dump($vatRates->getStandardRate('RO'));     // -> 19
    var_dump($vatRates->getParkingRate('RO'));      // -> null
}
 php
$vatRates = new VATRates(new DateTime('2016-01-01'));
if ($vatRates->isVATCountry('RO')) {
    var_dump($vatRates->getStandardRate('RO')); // -> 20
}
 php
$vatRates = new VATRates();
$vatRates->setDate(new DateTime('2015-01-01'));
if ($vatRates->isVATCountry('RO')) {
    var_dump($vatRates->getStandardRate('RO')); // -> 24
}
 php
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('GB'))) {
    var_dump($country->getName());             // -> "United Kingdom"
    var_dump($country->getCode());             // -> "UK"
    var_dump($country->getCountryCode());      // -> "GB"
    var_dump($country->getSuperReducedRate()); // -> null
    var_dump($country->getReducedRates());     // -> [5]
    var_dump($country->getStandardRate());     // -> 20
    var_dump($country->getParkingRate());      // -> null
}
 php
$vatRates->getCountry('UK'); // -> same result as 'GB'
 php
$vatRates = new VATRates();
$countries = $vatRates->getCountries();

foreach ($countries as $country) {
  print_r($country->getCountryCode() . " has VAT: " . $country->getStandardRate() . "\n");
}
 php
$vatRates = new VATRates();
$vatRates->setDate(new DateTime('2015-01-01'));
 php
$vatRates = new VATRates(new DateTime('2015-01-01'));
 php
$vatRates = new VATRates();
var_dump($vatRates->isVATCountry('FR')); // -> true
var_dump($vatRates->isVATCountry('US')); // -> false
 php
$vatRates = new VATRates();
if ($vatRates->isVATCountry('FR')) {
  var_dump($vatRates->getSuperReducedRate('FR')); // -> 2.1
});
 php
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('FR'))) {
  var_dump($country->getName());             // -> "France"
  var_dump($country->getSuperReducedRate()); // -> 2.1
}
 php
$vatRates = new VATRates();
if ($vatRates->isVATCountry('IE')) {
  var_dump($vatRates->getReducedRates('IE')); // -> [9, 13.5]
}
 php
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('IE'))) {
  var_dump($country->getName());         // -> "Ireland"
  var_dump($country->getReducedRates()); // -> [9, 13.5]
}
 php
$vatRates = new VATRates();
if ($vatRates->isVATCountry('NL')) {
  var_dump($vatRates->getStandardRate('NL')); // -> 21
});
 php
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('NL'))) {
  var_dump($country->getName());         // -> "Netherlands"
  var_dump($country->getStandardRate()); // -> 21
}
 php
$vatRates = new VATRates();
if ($vatRates->isVATCountry('LU')) {
  var_dump($vatRates->getParkingRate('LU')); // -> 14
});
 php
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('LU'))) {
  var_dump($country->getName());        // -> "Luxembourg"
  var_dump($country->getParkingRate()); // -> 14
}