diff --git a/app/DataMapper/Tax/BaseRule.php b/app/DataMapper/Tax/BaseRule.php index b6c5e80bc713..cf33bfff88eb 100644 --- a/app/DataMapper/Tax/BaseRule.php +++ b/app/DataMapper/Tax/BaseRule.php @@ -11,7 +11,9 @@ namespace App\DataMapper\Tax; +use App\DataMapper\InvoiceItem; use App\DataMapper\Tax\ZipTax\Response; +use App\DataProviders\USStates; use App\Models\Client; class BaseRule implements RuleInterface @@ -33,6 +35,8 @@ class BaseRule implements RuleInterface public string $client_region = ''; + public string $client_subregion = ''; + public array $eu_country_codes = [ 'AT', // Austria 'BE', // Belgium @@ -137,10 +141,12 @@ class BaseRule implements RuleInterface if(!array_key_exists($this->client->country->iso_3166_2, $this->region_codes)) throw new \Exception('Country not supported'); - + $this->client_region = $this->region_codes[$this->client->country->iso_3166_2] ?? ''; - $this->client_subregion = + if($this->client_region == 'US'){ + $this->client_subregion = $this->tax_data->geoState; + } return $this; } @@ -152,12 +158,12 @@ class BaseRule implements RuleInterface return $this; } - public function tax($product_tax_type): self + public function tax(mixed $type, ?InvoiceItem $item = null): self { return $this; } - public function taxByType($product_tax_type): self + public function taxByType(mixed $type): self { return $this; } diff --git a/app/DataMapper/Tax/DE/Rule.php b/app/DataMapper/Tax/DE/Rule.php index 025cecec310e..b80424d41354 100644 --- a/app/DataMapper/Tax/DE/Rule.php +++ b/app/DataMapper/Tax/DE/Rule.php @@ -13,6 +13,7 @@ namespace App\DataMapper\Tax\DE; use App\Models\Client; use App\Models\Product; +use App\DataMapper\InvoiceItem; use App\DataMapper\Tax\BaseRule; use App\DataMapper\Tax\RuleInterface; use App\DataMapper\Tax\ZipTax\Response; @@ -45,25 +46,9 @@ class Rule extends BaseRule implements RuleInterface return $this; } - public function setClient(Client $client): self - { - $this->client = $client; - - return $this; - } - - public function setTaxData(Response $tax_data): self - { - $this->tax_data = $tax_data; - - return $this; - } - - //need to add logic here to capture if - public function tax($type): self + public function tax(mixed $type, ?InvoiceItem $item = null): self { - if ($this->client->is_tax_exempt) { return $this->taxExempt(); diff --git a/app/DataMapper/Tax/RuleInterface.php b/app/DataMapper/Tax/RuleInterface.php index c210f2809c6a..3b0699c6d62c 100644 --- a/app/DataMapper/Tax/RuleInterface.php +++ b/app/DataMapper/Tax/RuleInterface.php @@ -11,6 +11,7 @@ namespace App\DataMapper\Tax; +use App\DataMapper\InvoiceItem; use App\Models\Client; use App\DataMapper\Tax\ZipTax\Response; @@ -18,7 +19,7 @@ interface RuleInterface { public function init(); - public function tax(mixed $type); + public function tax(mixed $type, ?InvoiceItem $item = null); public function taxByType($type); @@ -38,9 +39,5 @@ interface RuleInterface public function override(); - public function setClient(Client $client); - - public function setTaxData(Response $tax_data); - public function calculateRates(); } \ No newline at end of file diff --git a/app/DataMapper/Tax/US/Rule.php b/app/DataMapper/Tax/US/Rule.php index 62c91e1ebc8e..af30769ed536 100644 --- a/app/DataMapper/Tax/US/Rule.php +++ b/app/DataMapper/Tax/US/Rule.php @@ -11,8 +11,8 @@ namespace App\DataMapper\Tax\US; -use App\Models\Client; use App\Models\Product; +use App\DataMapper\InvoiceItem; use App\DataMapper\Tax\BaseRule; use App\DataMapper\Tax\RuleInterface; use App\DataMapper\Tax\ZipTax\Response; @@ -25,22 +25,7 @@ class Rule extends BaseRule implements RuleInterface return $this; } - public function setTaxData(Response $tax_data): self - { - $this->tax_data = $tax_data; - - return $this; - } - - public function setClient(Client $client):self - { - $this->client = $client; - $this->client_iso_3166_2 = $client->country->iso_3166_2; - - return $this; - } - - public function tax($type): self + public function tax(mixed $type, ?InvoiceItem $item = null): self { if ($this->client->is_tax_exempt) { @@ -52,7 +37,7 @@ class Rule extends BaseRule implements RuleInterface return $this; } - 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_iso_3166_2}->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;