Global Tax Module

This commit is contained in:
David Bomba 2023-03-19 15:09:50 +11:00
parent 30c64b64b9
commit b24be423e8
4 changed files with 180 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<?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;
class ProcessRule
{
public function __construct(protected Company $company, protected Client $client)
{
}
public function run()
{
}
}

View File

@ -0,0 +1,22 @@
<?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;
class TaxService
{
public function __construct(protected Company $company, protected Client $client)
{
}
}

View File

@ -0,0 +1,52 @@
<?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;
class VatNumberCheck
{
public function __construct(protected string $vat_number, protected string $country_code)
{
}
public function run()
{
return $this->checkvat_number();
}
private function checkvat_number(): array
{
$wsdl = "https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl";
try {
$client = new \SoapClient($wsdl);
$params = [
'countryCode' => $this->country_code,
'vatNumber' => $this->vat_number
];
$response = $client->checkVat($params);
if ($response->valid) {
return [
'valid' => true,
'name' => $response->name,
'address' => $response->address
];
} else {
return ['valid' => false];
}
} catch (\SoapFault $e) {
// Handle error, e.g., log or display an error message
return ['error' => $e->getMessage()];
}
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace Tests\Unit;
use Tests\TestCase;
use App\Services\Tax\VatNumberCheck;
/**
* @test App\Services\Tax\VatNumberCheck
*/
class VatNumberTest extends TestCase
{
protected function setUp() :void
{
parent::setUp();
}
public function testVatNumber()
{
// Usage example
$country_code = "IE"; // Ireland
$vat_number = "1234567L"; // Example VAT number
$result = '';
$vat_checker = new VatNumberCheck($vat_number, $country_code);
$result = $vat_checker->run();
if (isset($result['valid'])) {
if ($result['valid']) {
echo "The VAT number is valid.\n";
echo "Name: " . $result['name'] . "\n";
echo "Address: " . $result['address'] . "\n";
} else {
echo "The VAT number is invalid.\n";
}
} else {
echo "Error: " . $result['error'] . "\n";
}
$this->assertFalse($result['valid']);
}
private function testValidVatNumber()
{
// Usage example
$country_code = "AT"; // Ireland
$vat_number = "U12345678"; // Example VAT number
$result = '';
$vat_checker = new VatNumberCheck($vat_number, $country_code);
$result = $vat_checker->run();
if (isset($result['valid'])) {
if ($result['valid']) {
echo "The VAT number is valid.\n";
echo "Name: " . $result['name'] . "\n";
echo "Address: " . $result['address'] . "\n";
} else {
echo "The VAT number is invalid.\n";
}
} else {
echo "Error: " . $result['error'] . "\n";
}
$this->assertFalse($result['valid']);
}
}