2023-03-19 06:14:04 +01:00
|
|
|
<?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\Tax;
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\Company;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use App\DataMapper\Tax\de\Rule;
|
2023-03-29 04:13:50 +02:00
|
|
|
use App\DataMapper\Tax\TaxModel;
|
2023-03-19 06:14:04 +01:00
|
|
|
use App\DataMapper\CompanySettings;
|
2023-03-29 04:13:50 +02:00
|
|
|
use App\Services\Tax\Providers\EuTax;
|
2023-03-19 06:14:04 +01:00
|
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
|
|
|
/**
|
2023-03-26 22:46:26 +02:00
|
|
|
* @test App\Services\Tax\Providers\EuTax
|
2023-03-19 06:14:04 +01:00
|
|
|
*/
|
2023-03-26 22:46:26 +02:00
|
|
|
class EuTaxTest extends TestCase
|
2023-03-19 06:14:04 +01:00
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
protected function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->withoutMiddleware(
|
|
|
|
ThrottleRequests::class
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCorrectRuleInit()
|
|
|
|
{
|
|
|
|
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
2023-03-29 04:13:50 +02:00
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = true;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
2023-03-29 04:13:50 +02:00
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
2023-03-19 06:14:04 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 276,
|
|
|
|
'shipping_country_id' => 276,
|
|
|
|
]);
|
|
|
|
|
2023-03-26 22:46:26 +02:00
|
|
|
$process = new EuTax($company, $client);
|
2023-03-19 06:14:04 +01:00
|
|
|
$process->run();
|
|
|
|
|
|
|
|
$this->assertEquals('de', $process->getVendorCountryCode());
|
|
|
|
|
|
|
|
$this->assertEquals('de', $process->getClientCountryCode());
|
|
|
|
|
|
|
|
$this->assertFalse($process->hasValidVatNumber());
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process->rule);
|
|
|
|
|
|
|
|
$this->assertEquals(19, $process->getVatRate());
|
|
|
|
|
|
|
|
$this->assertEquals(7, $process->getVatReducedRate());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEuCorrectRuleInit()
|
|
|
|
{
|
|
|
|
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
2023-03-29 04:13:50 +02:00
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = true;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
2023-03-29 04:13:50 +02:00
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
2023-03-19 06:14:04 +01:00
|
|
|
]);
|
|
|
|
|
2023-03-29 04:13:50 +02:00
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 56,
|
|
|
|
'shipping_country_id' => 56,
|
|
|
|
]);
|
|
|
|
|
2023-03-26 22:46:26 +02:00
|
|
|
$process = new EuTax($company, $client);
|
2023-03-19 06:14:04 +01:00
|
|
|
$process->run();
|
|
|
|
|
|
|
|
$this->assertEquals('de', $process->getVendorCountryCode());
|
|
|
|
|
|
|
|
$this->assertEquals('be', $process->getClientCountryCode());
|
|
|
|
|
|
|
|
$this->assertFalse($process->hasValidVatNumber());
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process->rule);
|
|
|
|
|
|
|
|
$this->assertEquals(21, $process->getVatRate());
|
|
|
|
|
2023-03-29 04:13:50 +02:00
|
|
|
$this->assertEquals(6, $process->getVatReducedRate());
|
2023-03-19 06:14:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testForeignCorrectRuleInit()
|
|
|
|
{
|
|
|
|
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings
|
|
|
|
]);
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 840,
|
|
|
|
'shipping_country_id' => 840,
|
|
|
|
]);
|
|
|
|
|
2023-03-26 22:46:26 +02:00
|
|
|
$process = new EuTax($company, $client);
|
2023-03-19 06:14:04 +01:00
|
|
|
$process->run();
|
|
|
|
|
|
|
|
$this->assertEquals('de', $process->getVendorCountryCode());
|
|
|
|
|
|
|
|
$this->assertEquals('us', $process->getClientCountryCode());
|
|
|
|
|
|
|
|
$this->assertFalse($process->hasValidVatNumber());
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process->rule);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->getVatRate());
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->getVatReducedRate());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|