HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/egovers/edwingovers.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}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Indexes the shop catalog. You can specify an action argument that can be index, clear or clean depending on what you want to do';

    /**
     * IndexCatalog constructor.
     */
    public function __construct( )
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $vatService = new ViesService();

        $vatCode = $this->argument('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.');
        }
    }
}