Fixes for taxes

This commit is contained in:
David Bomba 2023-04-10 17:27:59 +10:00
parent 699c3cdd9b
commit f9886fdf89
4 changed files with 17 additions and 44 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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;