mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor for taxes
This commit is contained in:
parent
6c0c0d9372
commit
bd7722f6f0
@ -99,7 +99,7 @@ class BaseRule implements RuleInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function tax(): self
|
||||
public function tax($product_tax_type): self
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
@ -81,10 +81,14 @@ class Rule extends BaseRule implements RuleInterface
|
||||
}
|
||||
|
||||
//need to add logic here to capture if
|
||||
public function tax(): self
|
||||
public function tax($type): self
|
||||
{
|
||||
if($this->client->is_tax_exempt)
|
||||
|
||||
if ($this->client->is_tax_exempt)
|
||||
return $this->taxExempt();
|
||||
|
||||
if ($type)
|
||||
return $this->taxByType($type);
|
||||
|
||||
$this->tax_rate1 = $this->vat_rate;
|
||||
$this->tax_name1 = "MwSt.";
|
||||
|
@ -18,7 +18,7 @@ interface RuleInterface
|
||||
{
|
||||
public function init();
|
||||
|
||||
public function tax();
|
||||
public function tax(mixed $type);
|
||||
|
||||
public function taxByType($type);
|
||||
|
||||
|
@ -55,13 +55,22 @@ class Rule implements RuleInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function tax(): self
|
||||
public function tax($type): self
|
||||
{
|
||||
if($this->client->is_tax_exempt)
|
||||
|
||||
if ($this->client->is_tax_exempt) {
|
||||
return $this->taxExempt();
|
||||
}
|
||||
else if($this->client->company->tax_data->regions->US->tax_all){
|
||||
|
||||
$this->tax_rate1 = $this->tax_data->taxSales * 100;
|
||||
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
|
||||
$this->tax_rate1 = $this->tax_data->taxSales * 100;
|
||||
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if($type)
|
||||
return $this->taxByType($type);
|
||||
|
||||
return $this;
|
||||
|
||||
@ -72,11 +81,6 @@ 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_TYPE_EXEMPT => $this->taxExempt(),
|
||||
Product::PRODUCT_TYPE_DIGITAL => $this->taxDigital(),
|
||||
@ -101,7 +105,7 @@ class Rule implements RuleInterface
|
||||
|
||||
public function taxDigital(): self
|
||||
{
|
||||
$this->tax();
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -109,7 +113,7 @@ class Rule implements RuleInterface
|
||||
public function taxService(): self
|
||||
{
|
||||
if($this->tax_data->txbService == 'Y')
|
||||
$this->tax();
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -117,30 +121,30 @@ class Rule implements RuleInterface
|
||||
public function taxShipping(): self
|
||||
{
|
||||
if($this->tax_data->txbFreight == 'Y')
|
||||
$this->tax();
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function taxPhysical(): self
|
||||
{
|
||||
$this->tax();
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function default(): self
|
||||
{
|
||||
|
||||
$this->tax_name1 = 'Tax Exempt';
|
||||
$this->tax_rate1 = 0;
|
||||
|
||||
$this->tax_rate1 = $this->tax_data->taxSales * 100;
|
||||
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function taxReduced(): self
|
||||
{
|
||||
$this->tax();
|
||||
$this->default();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -199,12 +199,8 @@ class InvoiceItemSum
|
||||
*/
|
||||
private function calcTaxesAutomatically(): self
|
||||
{
|
||||
if ($this->invoice->company->tax_all_products || ( property_exists($this->item, 'tax_id') && $this->item->tax_id != '')) {
|
||||
$this->rule->tax();
|
||||
} else {
|
||||
$this->rule->init()->taxByType($this->item->tax_id);
|
||||
}
|
||||
|
||||
$this->rule->tax($this->item->tax_id ?? null);
|
||||
|
||||
$this->item->tax_name1 = $this->rule->tax_name1;
|
||||
$this->item->tax_rate1 = $this->rule->tax_rate1;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@ -31,6 +32,14 @@ return new class extends Migration
|
||||
$company->tax_data = null;
|
||||
$company->save();
|
||||
});
|
||||
|
||||
Client::query()
|
||||
->cursor()
|
||||
->each(function ($client) {
|
||||
$client->tax_data = null;
|
||||
$client->save();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,7 +204,6 @@ class UsTaxTest extends TestCase
|
||||
$client->save();
|
||||
|
||||
$company = $invoice->company;
|
||||
$company->tax_all_products = false;
|
||||
$tax_data = $company->tax_data;
|
||||
|
||||
$tax_data->regions->US->has_sales_above_threshold = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user