diff --git a/app/DataMapper/Tax/BaseRule.php b/app/DataMapper/Tax/BaseRule.php index 136fbf0bfcea..1cf893d5dded 100644 --- a/app/DataMapper/Tax/BaseRule.php +++ b/app/DataMapper/Tax/BaseRule.php @@ -374,4 +374,10 @@ class BaseRule implements RuleInterface { return $this; } + + public function regionWithNoTaxCoverage(string $iso_3166_2): bool + { + return ! in_array($iso_3166_2, array_merge($this->eu_country_codes, array_keys($this->region_codes))); + } + } diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index a3b1c3cee835..3be7e878ceb8 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -179,6 +179,10 @@ class InvoiceItemSum $class = "App\DataMapper\Tax\\".$this->client->company->country()->iso_3166_2."\\Rule"; $this->rule = new $class(); + + if($this->rule->regionWithNoTaxCoverage($this->client->country->iso_3166_2)) + return $this; + $this->rule ->setEntity($this->invoice) ->init(); diff --git a/tests/Unit/Tax/EuTaxTest.php b/tests/Unit/Tax/EuTaxTest.php index 1e7fb438167b..b497ddee4d2d 100644 --- a/tests/Unit/Tax/EuTaxTest.php +++ b/tests/Unit/Tax/EuTaxTest.php @@ -122,6 +122,80 @@ class EuTaxTest extends TestCase } + public function testEuToBrazilTaxCalculations() + { + + $settings = CompanySettings::defaults(); + $settings->country_id = '276'; // germany + + $tax_data = new TaxModel(); + $tax_data->seller_subregion = 'DE'; + $tax_data->regions->EU->has_sales_above_threshold = false; + $tax_data->regions->EU->tax_all_subregions = true; + $tax_data->regions->AU->tax_all_subregions = true; + $tax_data->regions->AU->has_sales_above_threshold = true; + + $company = Company::factory()->create([ + 'account_id' => $this->account->id, + 'settings' => $settings, + 'tax_data' => $tax_data, + 'calculate_taxes' => true, + ]); + + $client = Client::factory()->create([ + 'user_id' => $this->user->id, + 'company_id' => $company->id, + 'country_id' => 76, + 'shipping_country_id' => 76, + 'has_valid_vat_number' => false, + 'is_tax_exempt' => false, + // 'tax_data' => new Response([ + // 'geoState' => 'CA', + // 'taxSales' => 0.07, + // ]), + ]); + + $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_id' => Product::PRODUCT_TYPE_PHYSICAL, + ], + ], + 'tax_rate1' => 0, + 'tax_rate2' => 0, + 'tax_rate3' => 0, + 'tax_name1' => '', + 'tax_name2' => '', + 'tax_name3' => '', + // 'tax_data' => new Response([ + // 'geoState' => 'CA', + // 'taxSales' => 0.07, + // ]), + ]); + + $invoice = $invoice->calc()->getInvoice()->service()->markSent()->save(); + + $this->assertEquals(100, $invoice->amount); + + } + public function testEuToAuTaxCalculationExemptProduct() { @@ -981,6 +1055,8 @@ class EuTaxTest extends TestCase 'user_id' => $this->user->id, 'company_id' => $company->id, 'country_id' => 840, + 'state' => 'CA', + 'postal_code' => '90210', 'shipping_country_id' => 840, 'has_valid_vat_number' => true, 'is_tax_exempt' => true, @@ -992,7 +1068,7 @@ class EuTaxTest extends TestCase 'user_id' => $this->user->id, 'status_id' => Invoice::STATUS_SENT, 'tax_data' => new Response([ - 'geoState' => 'CA', + 'geoState' => 'CA', ]), ]);