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/SBogers10/helder.komma.pro/app/Komma/Shop/ArtisanCommands/VatCheck.php
<?php

namespace App\Komma\Shop\ArtisanCommands;

use App\Komma\Shop\Vies\ViesResult;
use App\Komma\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!');
        }
    }
}