Tax rule refactor

This commit is contained in:
David Bomba 2023-04-10 20:37:57 +10:00
parent 55a1ddf3c6
commit 4ad389ccec
2 changed files with 7 additions and 11 deletions

View File

@ -139,12 +139,8 @@ class BaseRule implements RuleInterface
if(!array_key_exists($this->client->country->iso_3166_2, $this->region_codes)) if(!array_key_exists($this->client->country->iso_3166_2, $this->region_codes))
throw new \Exception('Country not supported'); throw new \Exception('Country not supported');
nlog($this->client->country->iso_3166_2);
$this->client_region = $this->region_codes[$this->client->country->iso_3166_2] ?? ''; $this->client_region = $this->region_codes[$this->client->country->iso_3166_2] ?? '';
nlog($this->client_region);
match($this->client_region){ match($this->client_region){
'US' => $this->client_subregion = $this->tax_data->geoState, 'US' => $this->client_subregion = $this->tax_data->geoState,
'EU' => $this->client_subregion = $this->client->country->iso_3166_2, 'EU' => $this->client_subregion = $this->client->country->iso_3166_2,

View File

@ -144,19 +144,19 @@ class Rule extends BaseRule implements RuleInterface
public function calculateRates(): self public function calculateRates(): self
{ {
if ($this->client->is_tax_exempt) { if ($this->client->is_tax_exempt) {
nlog("tax exempt"); // nlog("tax exempt");
$this->vat_rate = 0; $this->vat_rate = 0;
$this->reduced_vat_rate = 0; $this->reduced_vat_rate = 0;
} }
elseif($this->client_subregion != $this->vendor_iso_3166_2 && in_array($this->client_subregion, $this->eu_country_codes) && $this->client->has_valid_vat_number && $this->eu_business_tax_exempt) elseif($this->client_subregion != $this->vendor_iso_3166_2 && in_array($this->client_subregion, $this->eu_country_codes) && $this->client->has_valid_vat_number && $this->eu_business_tax_exempt)
{ {
nlog("euro zone and tax exempt"); // nlog("euro zone and tax exempt");
$this->vat_rate = 0; $this->vat_rate = 0;
$this->reduced_vat_rate = 0; $this->reduced_vat_rate = 0;
} }
elseif(!in_array($this->client_subregion, $this->eu_country_codes) && ($this->foreign_consumer_tax_exempt || $this->foreign_business_tax_exempt)) //foreign + tax exempt elseif(!in_array($this->client_subregion, $this->eu_country_codes) && ($this->foreign_consumer_tax_exempt || $this->foreign_business_tax_exempt)) //foreign + tax exempt
{nlog($this->client_subregion); {
nlog("foreign and tax exempt"); // nlog("foreign and tax exempt");
$this->vat_rate = 0; $this->vat_rate = 0;
$this->reduced_vat_rate = 0; $this->reduced_vat_rate = 0;
} }
@ -164,18 +164,18 @@ class Rule extends BaseRule implements RuleInterface
{ {
if(($this->vendor_iso_3166_2 != $this->client_subregion) && $this->client->company->tax_data->regions->EU->has_sales_above_threshold) if(($this->vendor_iso_3166_2 != $this->client_subregion) && $this->client->company->tax_data->regions->EU->has_sales_above_threshold)
{ {
nlog("eu zone with sales above threshold"); // nlog("eu zone with sales above threshold");
$this->vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->vat_rate; $this->vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->vat_rate;
$this->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->reduced_vat_rate; $this->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->reduced_vat_rate;
} }
else { else {
nlog("EU with intra-community supply ie DE to DE"); // nlog("EU with intra-community supply ie DE to DE");
$this->vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->vat_rate; $this->vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->vat_rate;
$this->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_vat_rate; $this->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_vat_rate;
} }
} }
else { else {
nlog("default tax"); // nlog("default tax");
$this->vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->vat_rate; $this->vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->vat_rate;
$this->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_vat_rate; $this->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_vat_rate;
} }