Refactor for taxes

This commit is contained in:
David Bomba 2023-03-27 07:57:29 +11:00
parent d52d2f1f37
commit b94743f42d
3 changed files with 54 additions and 2 deletions

View File

@ -103,6 +103,8 @@ class Rule implements RuleInterface
protected ?Client $client;
protected ?Response $tax_data;
public function __construct()
{
}
@ -123,6 +125,10 @@ class Rule implements RuleInterface
public function tax(): self
{
if($this->client->is_tax_exempt)
return $this->taxExempt();
$this->tax_name1 = $this->vat_rate;
$this->tax_rate1 = "VAT";
@ -132,6 +138,11 @@ class Rule implements RuleInterface
public function taxByType(?int $product_tax_type): self
{
if ($this->client->is_tax_exempt) {
return $this->taxExempt();
}
if(!$product_tax_type)
return $this;

View File

@ -105,6 +105,9 @@ class Rule implements RuleInterface
public function tax(): self
{
if($this->client->is_tax_exempt)
return $this->taxExempt();
$this->tax_rate1 = $this->tax_data->taxSales * 100;
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
@ -117,6 +120,11 @@ class Rule implements RuleInterface
if(!$product_tax_type)
return $this;
if ($this->client->is_tax_exempt) {
return $this->taxExempt();
}
match($product_tax_type){
Product::PRODUCT_TAX_EXEMPT => $this->taxExempt(),
Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),

View File

@ -25,6 +25,38 @@ class InvoiceItemSum
use Discounter;
use Taxer;
private array $tax_jurisdictions = [
'AT', // Austria
'BE', // Belgium
'BG', // Bulgaria
'CY', // Cyprus
'CZ', // Czech Republic
'DE', // Germany
'DK', // Denmark
'EE', // Estonia
'ES', // Spain
'FI', // Finland
'FR', // France
'GR', // Greece
'HR', // Croatia
'HU', // Hungary
'IE', // Ireland
'IT', // Italy
'LT', // Lithuania
'LU', // Luxembourg
'LV', // Latvia
'MT', // Malta
'NL', // Netherlands
'PL', // Poland
'PT', // Portugal
'RO', // Romania
'SE', // Sweden
'SI', // Slovenia
'SK', // Slovakia
'US', //USA
];
protected $invoice;
private $items;
@ -102,18 +134,19 @@ class InvoiceItemSum
private function shouldCalculateTax(): self
{
if (!$this->invoice->company->calculate_taxes || $this->client->is_tax_exempt) {
if (!$this->invoice->company->calculate_taxes) {
$this->calc_tax = false;
return $this;
}
if (in_array($this->client->country->iso_3166_2, ['US'])) { //only calculate for USA
if (in_array($this->client->country->iso_3166_2, $this->tax_jurisdictions)) { //only calculate for supported tax jurisdictions
$class = "App\DataMapper\Tax\\".strtolower($this->client->country->iso_3166_2)."\\Rule";
$tax_data = new Response($this->invoice->tax_data);
$this->rule = new $class();
$this->rule->setTaxData($tax_data);
$this->rule->setClient($this->client);
$this->calc_tax = true;
return $this;