1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Refactor taxes for new tax model

This commit is contained in:
David Bomba 2023-04-07 19:26:31 +10:00
parent 9ee545160c
commit 231fdb00be
2 changed files with 8 additions and 37 deletions

View File

@ -61,25 +61,19 @@ class Rule implements RuleInterface
if ($this->client->is_tax_exempt) { if ($this->client->is_tax_exempt) {
return $this->taxExempt(); return $this->taxExempt();
} }
else if($this->client->company->tax_data->regions->US->tax_all){ else if($this->client->company->tax_data->regions->US->tax_all_subregions || $this->client->company->tax_data->regions->US->subregions->{$this->tax_data->geoState}->apply_tax){
$this->tax_rate1 = $this->tax_data->taxSales * 100; $this->taxByType($type);
$this->tax_name1 = "{$this->tax_data->geoState} Sales Tax";
return $this; return $this;
} }
if($type)
return $this->taxByType($type);
return $this; return $this;
} }
public function taxByType($product_tax_type): self public function taxByType($product_tax_type): self
{ {
if(!$product_tax_type)
return $this;
match($product_tax_type){ match($product_tax_type){
Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt(), Product::PRODUCT_TYPE_EXEMPT => $this->taxExempt(),

View File

@ -91,7 +91,7 @@ class UsTaxTest extends TestCase
$tax_data->seller_region = 'US'; $tax_data->seller_region = 'US';
$tax_data->seller_subregion = 'CA'; $tax_data->seller_subregion = 'CA';
$tax_data->regions->US->has_sales_above_threshold = true; $tax_data->regions->US->has_sales_above_threshold = true;
$tax_data->regions->US->tax_all = true; $tax_data->regions->US->tax_all_subregions = true;
$company = Company::factory()->create([ $company = Company::factory()->create([
'account_id' => $this->account->id, 'account_id' => $this->account->id,
@ -129,6 +129,7 @@ class UsTaxTest extends TestCase
'tax_name3' => '', 'tax_name3' => '',
'tax_rate3' => 0, 'tax_rate3' => 0,
'type_id' => '1', 'type_id' => '1',
'tax_id' => 1,
], ],
], ],
'tax_rate1' => 0, 'tax_rate1' => 0,
@ -145,30 +146,6 @@ class UsTaxTest extends TestCase
return $invoice; return $invoice;
} }
// public function testCompanyTaxAllOffTaxExemptProduct()
// {
// $invoice = $this->invoiceStub('92582');
// $client = $invoice->client;
// $client->is_tax_exempt = false;
// $client->save();
// $company = $invoice->company;
// $tax_data = $company->tax_data;
// $tax_data->regions->US->has_sales_above_threshold = true;
// $tax_data->regions->US->tax_all = false;
// $company->tax_data = $tax_data;
// $company->save();
// $invoice = $invoice->calc()->getInvoice()->service()->markSent()->save();
// $this->assertEquals(0, $invoice->line_items[0]->tax_rate1);
// $this->assertEquals(100, $invoice->amount);
// }
public function testCompanyTaxAllOffButTaxUSRegion() public function testCompanyTaxAllOffButTaxUSRegion()
{ {
@ -181,7 +158,7 @@ class UsTaxTest extends TestCase
$tax_data = $company->tax_data; $tax_data = $company->tax_data;
$tax_data->regions->US->has_sales_above_threshold = true; $tax_data->regions->US->has_sales_above_threshold = true;
$tax_data->regions->US->tax_all = true; $tax_data->regions->US->tax_all_subregions = true;
$company->tax_data = $tax_data; $company->tax_data = $tax_data;
$company->save(); $company->save();
@ -205,7 +182,7 @@ class UsTaxTest extends TestCase
$tax_data = $company->tax_data; $tax_data = $company->tax_data;
$tax_data->regions->US->has_sales_above_threshold = true; $tax_data->regions->US->has_sales_above_threshold = true;
$tax_data->regions->US->tax_all = false; $tax_data->regions->US->tax_all_subregions = false;
$company->tax_data = $tax_data; $company->tax_data = $tax_data;
$company->save(); $company->save();
@ -231,7 +208,7 @@ class UsTaxTest extends TestCase
$tax_data = $company->tax_data; $tax_data = $company->tax_data;
$tax_data->regions->US->has_sales_above_threshold = false; $tax_data->regions->US->has_sales_above_threshold = false;
$tax_data->regions->US->tax_all = true; $tax_data->regions->US->tax_all_subregions = true;
$company->tax_data = $tax_data; $company->tax_data = $tax_data;
$company->save(); $company->save();