mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for eu taxes
This commit is contained in:
parent
45632721a2
commit
aa91604814
@ -83,7 +83,7 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
//need to add logic here to capture if
|
//need to add logic here to capture if
|
||||||
public function tax(): self
|
public function tax(): self
|
||||||
{
|
{
|
||||||
if($this->client->is_tax_exempt || $this->client->has_valid_vat_number)
|
if($this->client->is_tax_exempt)
|
||||||
return $this->taxExempt();
|
return $this->taxExempt();
|
||||||
|
|
||||||
$this->tax_name1 = $this->vat_rate;
|
$this->tax_name1 = $this->vat_rate;
|
||||||
@ -178,10 +178,12 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
public function calculateRates(): self
|
public function calculateRates(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
if(
|
if ($this->client->is_tax_exempt) {
|
||||||
(($this->vendor_country_code == $this->client_country_code) && $this->client->has_valid_vat_number && $this->business_tax_exempt) || //same country / exempt for tax / valid vat number
|
$this->vat_rate = 0;
|
||||||
(in_array($this->client_country_code, $this->eu_country_codes) && $this->client->has_valid_vat_number && $this->eu_business_tax_exempt) //eu country / exempt for tax / valid vat number
|
$this->reduced_vat_rate = 0;
|
||||||
) {
|
}
|
||||||
|
elseif($this->client_country_code != $this->vendor_country_code && in_array($this->client_country_code, $this->eu_country_codes) && $this->client->has_valid_vat_number && $this->eu_business_tax_exempt)
|
||||||
|
{
|
||||||
$this->vat_rate = 0;
|
$this->vat_rate = 0;
|
||||||
$this->reduced_vat_rate = 0;
|
$this->reduced_vat_rate = 0;
|
||||||
nlog("euro zone and tax exempt");
|
nlog("euro zone and tax exempt");
|
||||||
|
@ -157,7 +157,6 @@ class EuTaxTest extends TestCase
|
|||||||
$process->setClient($client);
|
$process->setClient($client);
|
||||||
$process->init();
|
$process->init();
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals('DE', $process->vendor_country_code);
|
$this->assertEquals('DE', $process->vendor_country_code);
|
||||||
|
|
||||||
$this->assertEquals('US', $process->client_country_code);
|
$this->assertEquals('US', $process->client_country_code);
|
||||||
@ -216,5 +215,208 @@ class EuTaxTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
//tests with valid vat.
|
//tests with valid vat.
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTaxExemption1()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTaxExemption2()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user