From cea6d437ec04705fa5935ceb9c81d9325f28cc14 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 16 Nov 2024 15:37:24 +1100 Subject: [PATCH] GB rules --- app/DataMapper/Tax/GB/Rule.php | 243 +++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 app/DataMapper/Tax/GB/Rule.php diff --git a/app/DataMapper/Tax/GB/Rule.php b/app/DataMapper/Tax/GB/Rule.php new file mode 100644 index 0000000000..cf5b4a1569 --- /dev/null +++ b/app/DataMapper/Tax/GB/Rule.php @@ -0,0 +1,243 @@ +calculateRates(); + + return $this; + } + + /** + * Sets the correct tax rate based on the product type. + * + * @param mixed $item + * @return self + */ + public function taxByType($item): self + { + + if ($this->client->is_tax_exempt || !property_exists($item, 'tax_id')) { + return $this->taxExempt($item); + } + + match(intval($item->tax_id)) { + Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt($item), + Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital($item), + Product::PRODUCT_TYPE_SERVICE => $this->taxService($item), + Product::PRODUCT_TYPE_SHIPPING => $this->taxShipping($item), + Product::PRODUCT_TYPE_PHYSICAL => $this->taxPhysical($item), + Product::PRODUCT_TYPE_REDUCED_TAX => $this->taxReduced($item), + Product::PRODUCT_TYPE_OVERRIDE_TAX => $this->override($item), + Product::PRODUCT_TYPE_ZERO_RATED => $this->zeroRated($item), + Product::PRODUCT_TYPE_REVERSE_TAX => $this->reverseTax($item), + default => $this->default($item), + }; + + return $this; + } + + /** + * Calculates the tax rate for a reduced tax product + * + * @return self + */ + public function reverseTax($item): self + { + $this->tax_rate1 = 20; + $this->tax_name1 = 'VAT'; + + return $this; + } + + /** + * Calculates the tax rate for a reduced tax product + * + * @return self + */ + public function taxReduced($item): self + { + $this->tax_rate1 = $this->reduced_tax_rate; + $this->tax_name1 = 'VAT'; + + return $this; + } + + /** + * Calculates the tax rate for a zero rated tax product + * + * @return self + */ + public function zeroRated($item): self + { + $this->tax_rate1 = 0; + $this->tax_name1 = 'VAT'; + + return $this; + } + + + /** + * Calculates the tax rate for a tax exempt product + * + * @return self + */ + public function taxExempt($item): self + { + $this->tax_name1 = ''; + $this->tax_rate1 = 0; + + return $this; + } + + /** + * Calculates the tax rate for a digital product + * + * @return self + */ + public function taxDigital($item): self + { + + $this->tax_rate1 = $this->tax_rate; + $this->tax_name1 = 'VAT'; + + return $this; + } + + /** + * Calculates the tax rate for a service product + * + * @return self + */ + public function taxService($item): self + { + + $this->tax_rate1 = $this->tax_rate; + $this->tax_name1 = 'VAT'; + + return $this; + } + + /** + * Calculates the tax rate for a shipping product + * + * @return self + */ + public function taxShipping($item): self + { + + $this->tax_rate1 = $this->tax_rate; + $this->tax_name1 = 'VAT'; + + return $this; + } + + /** + * Calculates the tax rate for a physical product + * + * @return self + */ + public function taxPhysical($item): self + { + + $this->tax_rate1 = $this->tax_rate; + $this->tax_name1 = 'VAT'; + + return $this; + } + + /** + * Calculates the tax rate for a default product + * + * @return self + */ + public function default($item): self + { + + $this->tax_name1 = ''; + $this->tax_rate1 = 0; + + return $this; + } + + /** + * Calculates the tax rate for an override product + * + * @return self + */ + public function override($item): self + { + return $this; + } + + /** + * Calculates the tax rates based on the client's location. + * + * @return self + */ + public function calculateRates(): self + { + if ($this->client->is_tax_exempt) { + + $this->tax_rate = 0; + $this->reduced_tax_rate = 0; + + return $this; + } + + // $this->tax_rate = $this->client->company->tax_data->regions->UK->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate ?? 0; + // $this->reduced_tax_rate = $this->client->company->tax_data->regions->UK->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate ?? 0; + + return $this; + + } + +}