calculate taxes

This commit is contained in:
David Bomba 2023-03-24 07:40:44 +11:00
parent d55e41b772
commit 66772e3897
2 changed files with 35 additions and 2 deletions

View File

@ -11,9 +11,10 @@
namespace App\Helpers\Invoice; namespace App\Helpers\Invoice;
use App\DataMapper\BaseSettings; use App\Models\Client;
use App\DataMapper\InvoiceItem;
use App\Models\Invoice; use App\Models\Invoice;
use App\DataMapper\InvoiceItem;
use App\DataMapper\BaseSettings;
use App\Utils\Traits\NumberFormatter; use App\Utils\Traits\NumberFormatter;
class InvoiceItemSum class InvoiceItemSum
@ -48,6 +49,10 @@ class InvoiceItemSum
private $tax_collection; private $tax_collection;
private ?Client $client;
private bool $calc_tax = false;
public function __construct($invoice) public function __construct($invoice)
{ {
$this->tax_collection = collect([]); $this->tax_collection = collect([]);
@ -56,6 +61,8 @@ class InvoiceItemSum
if ($this->invoice->client) { if ($this->invoice->client) {
$this->currency = $this->invoice->client->currency(); $this->currency = $this->invoice->client->currency();
$this->client = $this->invoice->client;
$this->calc_tax = $this->shouldCalculateTax();
} else { } else {
$this->currency = $this->invoice->vendor->currency(); $this->currency = $this->invoice->vendor->currency();
} }
@ -89,6 +96,17 @@ class InvoiceItemSum
return $this; return $this;
} }
private function shouldCalculateTax(): bool
{
if(!$this->invoice->company->calculate_taxes)
return false;
if(in_array($this->client->country->iso_3166_2, ['US']))
return true;
return false;
}
private function push() private function push()
{ {
$this->sub_total += $this->getLineTotal(); $this->sub_total += $this->getLineTotal();
@ -121,6 +139,16 @@ class InvoiceItemSum
return $this; return $this;
} }
/**
* Attempts to calculate taxes based on the clients location
*
* @return self
*/
private function calcTaxesAutomatically()
{
}
private function calcTaxes() private function calcTaxes()
{ {

View File

@ -79,6 +79,11 @@ class SumTaxTest extends TestCase
// $this->makeTestData(); // $this->makeTestData();
} }
public function testTaxOnInvoice()
{
}
public function testSumOfInvoice() public function testSumOfInvoice()
{ {