mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 10:54:30 -04:00
Centralize resolution of subregion
This commit is contained in:
parent
d6bb7a3510
commit
e88bf18fe7
@ -134,6 +134,7 @@ class BaseRule implements RuleInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refactor to support switching between shipping / billing country / region / subregion
|
||||||
private function resolveRegions(): self
|
private function resolveRegions(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -142,13 +143,20 @@ class BaseRule implements RuleInterface
|
|||||||
|
|
||||||
$this->client_region = $this->region_codes[$this->client->country->iso_3166_2] ?? '';
|
$this->client_region = $this->region_codes[$this->client->country->iso_3166_2] ?? '';
|
||||||
|
|
||||||
if($this->client_region == 'US'){
|
match($this->client_region){
|
||||||
$this->client_subregion = $this->tax_data->geoState;
|
'US' => $this->client_subregion = $this->tax_data->geoState,
|
||||||
}
|
'EU' => $this->client->country->iso_3166_2,
|
||||||
|
default => '',
|
||||||
|
};
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isTaxableRegion(): bool
|
||||||
|
{
|
||||||
|
return $this->client->company->tax_data->regions->{$this->client_region}->tax_all_subregions || $this->client->company->tax_data->regions->{$this->client_region}->subregions->{$this->client_subregion}->apply_tax;
|
||||||
|
}
|
||||||
|
|
||||||
public function setTaxData(Response $tax_data): self
|
public function setTaxData(Response $tax_data): self
|
||||||
{
|
{
|
||||||
$this->tax_data = $tax_data;
|
$this->tax_data = $tax_data;
|
||||||
|
@ -50,7 +50,7 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
|
|
||||||
return $this->taxExempt();
|
return $this->taxExempt();
|
||||||
|
|
||||||
} elseif ($this->client->company->tax_data->regions->EU->tax_all_subregions || $this->client->company->tax_data->regions->EU->subregions->{$this->client_iso_3166_2}->apply_tax) {
|
} elseif ($this->client->company->tax_data->regions->EU->tax_all_subregions || $this->client->company->tax_data->regions->EU->subregions->{$this->client_subregion}->apply_tax) {
|
||||||
|
|
||||||
$this->taxByType($item->tax_id);
|
$this->taxByType($item->tax_id);
|
||||||
|
|
||||||
|
@ -11,13 +11,20 @@
|
|||||||
|
|
||||||
namespace App\DataMapper\Tax\US;
|
namespace App\DataMapper\Tax\US;
|
||||||
|
|
||||||
use App\Models\Product;
|
|
||||||
use App\DataMapper\Tax\BaseRule;
|
use App\DataMapper\Tax\BaseRule;
|
||||||
use App\DataMapper\Tax\RuleInterface;
|
use App\DataMapper\Tax\RuleInterface;
|
||||||
|
use App\Models\Product;
|
||||||
|
|
||||||
class Rule extends BaseRule implements RuleInterface
|
class Rule extends BaseRule implements RuleInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function init(): self
|
||||||
|
{
|
||||||
|
$this->calculateRates();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function override(): self
|
public function override(): self
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
@ -28,14 +35,12 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
|
|
||||||
if ($this->client->is_tax_exempt) {
|
if ($this->client->is_tax_exempt) {
|
||||||
return $this->taxExempt();
|
return $this->taxExempt();
|
||||||
}
|
} elseif($this->client->company->tax_data->regions->US->tax_all_subregions || $this->client->company->tax_data->regions->US->subregions->{$this->client_subregion}->apply_tax) {
|
||||||
else if($this->client->company->tax_data->regions->US->tax_all_subregions || $this->client->company->tax_data->regions->US->subregions->{$this->tax_data->geoState}->apply_tax){
|
|
||||||
|
|
||||||
$this->taxByType($item->tax_id);
|
$this->taxByType($item->tax_id);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
} elseif($this->client->company->tax_data->regions->{$this->client_region}->tax_all_subregions || $this->client->company->tax_data->regions->{$this->client_region}->subregions->{$this->client_subregion}->apply_tax) { //other regions outside of US
|
||||||
else if($this->client->company->tax_data->regions->{$this->client_region}->tax_all_subregions || $this->client->company->tax_data->regions->{$this->client_region}->subregions->{$this->client_subregion}->apply_tax){ //other regions outside of US
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
@ -45,7 +50,7 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
public function taxByType($product_tax_type): self
|
public function taxByType($product_tax_type): self
|
||||||
{
|
{
|
||||||
|
|
||||||
match($product_tax_type){
|
match($product_tax_type) {
|
||||||
Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt(),
|
Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt(),
|
||||||
Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
|
Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
|
||||||
Product::PRODUCT_TYPE_SERVICE => $this->taxService(),
|
Product::PRODUCT_TYPE_SERVICE => $this->taxService(),
|
||||||
@ -76,16 +81,18 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
|
|
||||||
public function taxService(): self
|
public function taxService(): self
|
||||||
{
|
{
|
||||||
if($this->tax_data->txbService == 'Y')
|
if($this->tax_data->txbService == 'Y') {
|
||||||
$this->default();
|
$this->default();
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function taxShipping(): self
|
public function taxShipping(): self
|
||||||
{
|
{
|
||||||
if($this->tax_data->txbFreight == 'Y')
|
if($this->tax_data->txbFreight == 'Y') {
|
||||||
$this->default();
|
$this->default();
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -113,13 +120,12 @@ class Rule extends BaseRule implements RuleInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init(): self
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function calculateRates(): self
|
public function calculateRates(): self
|
||||||
{
|
{
|
||||||
|
if($this->client_region != 'US' && $this->isTaxableRegion()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -604,6 +604,7 @@ class EuTaxTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$process = new Rule();
|
$process = new Rule();
|
||||||
|
$process->setTaxData(new Response([]));
|
||||||
$process->setClient($client);
|
$process->setClient($client);
|
||||||
$process->init();
|
$process->init();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user