mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactor for taxes
This commit is contained in:
parent
d52d2f1f37
commit
b94743f42d
@ -103,6 +103,8 @@ class Rule implements RuleInterface
|
|||||||
|
|
||||||
protected ?Client $client;
|
protected ?Client $client;
|
||||||
|
|
||||||
|
protected ?Response $tax_data;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -123,6 +125,10 @@ class Rule implements RuleInterface
|
|||||||
|
|
||||||
public function tax(): self
|
public function tax(): self
|
||||||
{
|
{
|
||||||
|
if($this->client->is_tax_exempt)
|
||||||
|
return $this->taxExempt();
|
||||||
|
|
||||||
|
|
||||||
$this->tax_name1 = $this->vat_rate;
|
$this->tax_name1 = $this->vat_rate;
|
||||||
$this->tax_rate1 = "VAT";
|
$this->tax_rate1 = "VAT";
|
||||||
|
|
||||||
@ -132,6 +138,11 @@ class Rule implements RuleInterface
|
|||||||
|
|
||||||
public function taxByType(?int $product_tax_type): self
|
public function taxByType(?int $product_tax_type): self
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ($this->client->is_tax_exempt) {
|
||||||
|
return $this->taxExempt();
|
||||||
|
}
|
||||||
|
|
||||||
if(!$product_tax_type)
|
if(!$product_tax_type)
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
|
@ -105,6 +105,9 @@ class Rule implements RuleInterface
|
|||||||
|
|
||||||
public function tax(): self
|
public function tax(): self
|
||||||
{
|
{
|
||||||
|
if($this->client->is_tax_exempt)
|
||||||
|
return $this->taxExempt();
|
||||||
|
|
||||||
$this->tax_rate1 = $this->tax_data->taxSales * 100;
|
$this->tax_rate1 = $this->tax_data->taxSales * 100;
|
||||||
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
|
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
|
||||||
|
|
||||||
@ -117,6 +120,11 @@ class Rule implements RuleInterface
|
|||||||
if(!$product_tax_type)
|
if(!$product_tax_type)
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
|
|
||||||
|
if ($this->client->is_tax_exempt) {
|
||||||
|
return $this->taxExempt();
|
||||||
|
}
|
||||||
|
|
||||||
match($product_tax_type){
|
match($product_tax_type){
|
||||||
Product::PRODUCT_TAX_EXEMPT => $this->taxExempt(),
|
Product::PRODUCT_TAX_EXEMPT => $this->taxExempt(),
|
||||||
Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
|
Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
|
||||||
|
@ -25,6 +25,38 @@ class InvoiceItemSum
|
|||||||
use Discounter;
|
use Discounter;
|
||||||
use Taxer;
|
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;
|
protected $invoice;
|
||||||
|
|
||||||
private $items;
|
private $items;
|
||||||
@ -102,18 +134,19 @@ class InvoiceItemSum
|
|||||||
|
|
||||||
private function shouldCalculateTax(): self
|
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;
|
$this->calc_tax = false;
|
||||||
return $this;
|
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";
|
$class = "App\DataMapper\Tax\\".strtolower($this->client->country->iso_3166_2)."\\Rule";
|
||||||
|
|
||||||
$tax_data = new Response($this->invoice->tax_data);
|
$tax_data = new Response($this->invoice->tax_data);
|
||||||
|
|
||||||
$this->rule = new $class();
|
$this->rule = new $class();
|
||||||
$this->rule->setTaxData($tax_data);
|
$this->rule->setTaxData($tax_data);
|
||||||
|
$this->rule->setClient($this->client);
|
||||||
$this->calc_tax = true;
|
$this->calc_tax = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user