File: D:/HostingSpaces/Eurotools/euro-tools.nl/app/KommaApp/Shop/ArtisanCommands/VatCheck.php
<?php
namespace App\KommaApp\Shop\ArtisanCommands;
use App\KommaApp\Shop\Vies\ViesResult;
use App\KommaApp\Shop\Vies\ViesService;
use Illuminate\Console\Command;
class VatCheck extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'shop:vatcheck {vatCode? : The vat code to check or nothing if you want to check all vat codes for all customers}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Checks the specified vat code for validity or loops over all non validated customers and validates them. And then notifies admins via mail about the results.';
/**
* IndexCatalog constructor.
*/
public function __construct( )
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
$vatService = new ViesService();
$vatCode = $this->argument('vatCode');
if($vatCode) {
$result = $vatService->validateVatNumber($vatCode);
if (is_a($result, ViesResult::class)) {
/** @var $result ViesResult */
$this->info('Vat number "' . $vatCode . '" is valid for a country with code "' . $result->getCountryCode() . '"');
if ($result->getName() != "") {
$this->info('The vat number belongs to "' . $result->getName() . '"');
}
if ($result->getAddress() != "") {
$this->info($result->getAddress());
}
} else {
if (is_int($result)) {
if ($result == 0) {
$this->error('Vat code "' . $vatCode . '" is not valid');
} else {
if ($result == -1) {
$this->error('Vat code "' . $vatCode . '" could not be checked because the VIES service could not be reached. It may be offline since it often is.');
}
}
}
}
} else {
$this->info('Checking vat numbers of all non validated customers and updating the admins of the results...');
$vatService->recheckUserVatNumbersAndNotifyAdmins();
$this->info('Done!');
}
}
}