2023-03-19 05:09:50 +01:00
< ? php
/**
* Invoice Ninja ( https :// invoiceninja . com ) .
*
* @ link https :// github . com / invoiceninja / invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @ copyright Copyright ( c ) 2024. Invoice Ninja LLC ( https :// invoiceninja . com )
2023-03-19 05:09:50 +01:00
*
* @ 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
2023-10-26 04:57:44 +02:00
if ( ! $this -> client -> name && strlen ( $vat_check -> getName ()) > 2 ) {
$this -> client -> name = $vat_check -> getName ();
}
2023-05-25 09:19:52 +02:00
2023-10-26 04:57:44 +02:00
if ( empty ( $this -> client -> private_notes ) && strlen ( $vat_check -> getAddress ()) > 2 ) {
$this -> client -> private_notes = $vat_check -> getAddress ();
}
2023-05-25 09:19:52 +02:00
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 ()
{
2024-01-14 05:05:00 +01:00
2023-05-15 04:37:38 +02:00
}
2023-10-26 04:57:44 +02:00
}