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;
|
2023-03-29 11:49:40 +02:00
|
|
|
use App\Models\Invoice;
|
2023-03-19 06:14:04 +01:00
|
|
|
use Tests\MockAccountData;
|
2023-03-29 05:23:06 +02:00
|
|
|
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 11:49:40 +02:00
|
|
|
use App\DataMapper\Tax\ZipTax\Response;
|
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();
|
|
|
|
}
|
|
|
|
|
2023-03-31 06:12:00 +02:00
|
|
|
public function testInvoiceWithCustomTaxIdTax()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2023-03-29 11:49:40 +02:00
|
|
|
|
|
|
|
public function testInvoiceTaxCalcDetoBeNoVat()
|
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
'calculate_taxes' => true,
|
|
|
|
'tax_all_products' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 56,
|
|
|
|
'shipping_country_id' => 56,
|
|
|
|
'has_valid_vat_number' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invoice = Invoice::factory()->create([
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'status_id' => 1,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'uses_inclusive_taxes' => false,
|
|
|
|
'discount' => 0,
|
|
|
|
'line_items' => [
|
|
|
|
[
|
|
|
|
'product_key' => 'Test',
|
|
|
|
'notes' => 'Test',
|
|
|
|
'cost' => 100,
|
|
|
|
'quantity' => 1,
|
|
|
|
'tax_name1' => '',
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_name3' => '',
|
|
|
|
'tax_rate3' => 0,
|
|
|
|
'type_id' => '1',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
|
|
|
'tax_name1' => '',
|
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'tax_data' => new Response([]),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invoice = $invoice->calc()->getInvoice()->service()->markSent()->save();
|
|
|
|
|
|
|
|
$this->assertEquals(21, $invoice->line_items[0]->tax_rate1);
|
|
|
|
$this->assertEquals(121, $invoice->amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceTaxCalcDetoBe()
|
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
'calculate_taxes' => true,
|
|
|
|
'tax_all_products' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 56,
|
|
|
|
'shipping_country_id' => 56,
|
|
|
|
'has_valid_vat_number' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invoice = Invoice::factory()->create([
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'status_id' => 1,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'uses_inclusive_taxes' => false,
|
|
|
|
'discount' => 0,
|
|
|
|
'line_items' => [
|
|
|
|
[
|
|
|
|
'product_key' => 'Test',
|
|
|
|
'notes' => 'Test',
|
|
|
|
'cost' => 100,
|
|
|
|
'quantity' => 1,
|
|
|
|
'tax_name1' => '',
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_name3' => '',
|
|
|
|
'tax_rate3' => 0,
|
|
|
|
'type_id' => '1',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
|
|
|
'tax_name1' => '',
|
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'tax_data' => new Response([]),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invoice = $invoice->calc()->getInvoice()->service()->markSent()->save();
|
|
|
|
|
|
|
|
$this->assertEquals(0, $invoice->line_items[0]->tax_rate1);
|
|
|
|
$this->assertEquals(100, $invoice->amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testInvoiceTaxCalcDetoDe()
|
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
'calculate_taxes' => true,
|
|
|
|
'tax_all_products' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 276,
|
|
|
|
'shipping_country_id' => 276,
|
|
|
|
'has_valid_vat_number' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invoice = Invoice::factory()->create([
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'status_id' => 1,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'uses_inclusive_taxes' => false,
|
|
|
|
'discount' => 0,
|
|
|
|
'line_items' => [
|
|
|
|
[
|
|
|
|
'product_key' => 'Test',
|
|
|
|
'notes' => 'Test',
|
|
|
|
'cost' => 100,
|
|
|
|
'quantity' => 1,
|
|
|
|
'tax_name1' => '',
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_name3' => '',
|
|
|
|
'tax_rate3' => 0,
|
|
|
|
'type_id' => '1',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
|
|
|
'tax_name1' => '',
|
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'tax_data' => new Response([]),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invoice = $invoice->calc()->getInvoice();
|
|
|
|
|
|
|
|
$this->assertEquals(19, $invoice->line_items[0]->tax_rate1);
|
|
|
|
$this->assertEquals(119, $invoice->amount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
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-29 05:23:06 +02:00
|
|
|
'has_valid_vat_number' => false,
|
2023-03-19 06:14:04 +01:00
|
|
|
]);
|
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals('DE', $process->vendor_country_code);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals('DE', $process->client_country_code);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertFalse($client->has_valid_vat_number);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals(19, $process->vat_rate);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals(7, $process->reduced_vat_rate);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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-29 05:23:06 +02:00
|
|
|
'has_valid_vat_number' => false,
|
2023-03-19 06:14:04 +01:00
|
|
|
]);
|
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
2023-03-19 06:14:04 +01:00
|
|
|
|
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals('DE', $process->vendor_country_code);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals('BE', $process->client_country_code);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertFalse($client->has_valid_vat_number);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals(21, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(6, $process->reduced_vat_rate);
|
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-29 05:23:06 +02:00
|
|
|
'has_valid_vat_number' => false,
|
2023-03-19 06:14:04 +01:00
|
|
|
]);
|
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
|
|
|
|
|
|
|
$this->assertEquals('DE', $process->vendor_country_code);
|
|
|
|
|
|
|
|
$this->assertEquals('US', $process->client_country_code);
|
|
|
|
|
|
|
|
$this->assertFalse($client->has_valid_vat_number);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->reduced_vat_rate);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSubThresholdCorrectRate()
|
|
|
|
{
|
|
|
|
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = false;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
]);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 56,
|
|
|
|
'shipping_country_id' => 56,
|
|
|
|
'has_valid_vat_number' => false,
|
|
|
|
]);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertFalse($client->has_valid_vat_number);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
$this->assertEquals(19, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(7, $process->reduced_vat_rate);
|
2023-03-19 06:14:04 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-29 05:23:06 +02:00
|
|
|
//tests with valid vat.
|
2023-03-29 05:42:08 +02:00
|
|
|
public function testDeWithValidVat()
|
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = false;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 276,
|
|
|
|
'shipping_country_id' => 276,
|
|
|
|
'has_valid_vat_number' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
|
|
|
|
|
|
|
$this->assertTrue($client->has_valid_vat_number);
|
|
|
|
|
|
|
|
$this->assertEquals(19, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(7, $process->reduced_vat_rate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//tests with valid vat.
|
|
|
|
public function testDeToEUWithValidVat()
|
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = false;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 56,
|
|
|
|
'shipping_country_id' => 56,
|
|
|
|
'has_valid_vat_number' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
|
|
|
|
|
|
|
$this->assertTrue($client->has_valid_vat_number);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->reduced_vat_rate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-29 11:49:40 +02:00
|
|
|
public function testTaxExemptionDeSellerBeBuyer()
|
2023-03-29 05:42:08 +02:00
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = false;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 56,
|
|
|
|
'shipping_country_id' => 56,
|
|
|
|
'has_valid_vat_number' => true,
|
|
|
|
'is_tax_exempt' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
|
|
|
|
|
|
|
$this->assertTrue($client->is_tax_exempt);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->reduced_vat_rate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-29 11:49:40 +02:00
|
|
|
public function testTaxExemptionDeSellerDeBuyer()
|
2023-03-29 05:42:08 +02:00
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = false;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 276,
|
|
|
|
'shipping_country_id' => 276,
|
|
|
|
'has_valid_vat_number' => true,
|
|
|
|
'is_tax_exempt' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
|
|
|
|
|
|
|
$this->assertTrue($client->is_tax_exempt);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->reduced_vat_rate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTaxExemption3()
|
|
|
|
{
|
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
$settings->country_id = '276'; // germany
|
|
|
|
|
|
|
|
$tax_data = new TaxModel();
|
|
|
|
$tax_data->seller_region = 'DE';
|
|
|
|
$tax_data->seller_subregion = 'DE';
|
|
|
|
$tax_data->regions->EU->has_sales_above_threshold = false;
|
|
|
|
$tax_data->regions->EU->tax_all = true;
|
|
|
|
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
'tax_data' => $tax_data,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'country_id' => 840,
|
|
|
|
'shipping_country_id' => 840,
|
|
|
|
'has_valid_vat_number' => true,
|
|
|
|
'is_tax_exempt' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$process = new Rule();
|
|
|
|
$process->setClient($client);
|
|
|
|
$process->init();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Rule::class, $process);
|
|
|
|
|
|
|
|
$this->assertTrue($client->is_tax_exempt);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->vat_rate);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $process->reduced_vat_rate);
|
|
|
|
|
|
|
|
}
|
2023-03-29 05:23:06 +02:00
|
|
|
|
2023-03-19 06:14:04 +01:00
|
|
|
}
|