mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Global Tax Module
This commit is contained in:
parent
30c64b64b9
commit
b24be423e8
24
app/Services/Tax/ProcessRule.php
Normal file
24
app/Services/Tax/ProcessRule.php
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
22
app/Services/Tax/TaxService.php
Normal file
22
app/Services/Tax/TaxService.php
Normal 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
app/Services/Tax/VatNumberCheck.php
Normal file
52
app/Services/Tax/VatNumberCheck.php
Normal 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()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
82
tests/Unit/VatNumberTest.php
Normal file
82
tests/Unit/VatNumberTest.php
Normal 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']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user