From 4ad389ccec5510ff59b0c2f87ed74a0da4fd2cd3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 10 Apr 2023 20:37:57 +1000 Subject: [PATCH] Tax rule refactor --- app/DataMapper/Tax/BaseRule.php | 4 ---- app/DataMapper/Tax/DE/Rule.php | 14 +++++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/DataMapper/Tax/BaseRule.php b/app/DataMapper/Tax/BaseRule.php index dcf747150830..856501bc3002 100644 --- a/app/DataMapper/Tax/BaseRule.php +++ b/app/DataMapper/Tax/BaseRule.php @@ -139,12 +139,8 @@ class BaseRule implements RuleInterface if(!array_key_exists($this->client->country->iso_3166_2, $this->region_codes)) 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] ?? ''; - nlog($this->client_region); - match($this->client_region){ 'US' => $this->client_subregion = $this->tax_data->geoState, 'EU' => $this->client_subregion = $this->client->country->iso_3166_2, diff --git a/app/DataMapper/Tax/DE/Rule.php b/app/DataMapper/Tax/DE/Rule.php index 6acc7135cba7..3111f2d0fca3 100644 --- a/app/DataMapper/Tax/DE/Rule.php +++ b/app/DataMapper/Tax/DE/Rule.php @@ -144,19 +144,19 @@ class Rule extends BaseRule implements RuleInterface public function calculateRates(): self { if ($this->client->is_tax_exempt) { - nlog("tax exempt"); + // nlog("tax exempt"); $this->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) { - nlog("euro zone and tax exempt"); + // nlog("euro zone and tax exempt"); $this->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 - {nlog($this->client_subregion); - nlog("foreign and tax exempt"); + { + // nlog("foreign and tax exempt"); $this->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) { - 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->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->country->iso_3166_2}->reduced_vat_rate; } 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->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_vat_rate; } } 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->reduced_vat_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_vat_rate; }