1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Services/Tax/TaxService.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2023-03-19 05:09:50 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Tax;
2023-03-21 22:00:20 +01:00
use App\Models\Client;
2023-03-19 05:09:50 +01:00
class TaxService
{
2023-05-08 11:28:31 +02:00
public function __construct(public Client $client)
2023-03-19 05:09:50 +01:00
{
}
2023-05-08 11:28:31 +02:00
public function validateVat(): self
2023-03-29 05:23:06 +02:00
{
2023-05-25 09:19:52 +02:00
if(!extension_loaded('soap')) {
nlog("Install the PHP SOAP extension if you wish to check VAT Numbers. See https://www.php.net/manual/en/soap.installation.php for more information on installing the PHP");
return $this;
}
2023-03-29 05:23:06 +02:00
$client_country_code = $this->client->shipping_country ? $this->client->shipping_country->iso_3166_2 : $this->client->country->iso_3166_2;
$vat_check = (new VatNumberCheck($this->client->vat_number, $client_country_code))->run();
2023-05-25 09:19:52 +02:00
nlog($vat_check);
2023-05-25 08:41:29 +02:00
if($vat_check->isValid()) {
2023-05-25 09:19:52 +02:00
2023-05-25 08:41:29 +02:00
$this->client->has_valid_vat_number = true;
2023-05-25 09:19:52 +02:00
if(!$this->client->name && strlen($vat_check->getName()) > 2) {
$this->client->name = $vat_check->getName();
}
if(empty($this->client->private_notes) && strlen($vat_check->getAddress()) > 2) {
$this->client->private_notes = $vat_check->getAddress();
}
2023-05-25 08:41:29 +02:00
$this->client->saveQuietly();
}
2023-03-29 05:23:06 +02:00
return $this;
2023-05-25 09:19:52 +02:00
2023-03-29 05:23:06 +02:00
}
2023-05-15 04:37:38 +02:00
public function initTaxProvider()
{
}
2023-03-19 05:09:50 +01:00
}