From 0a49bd4afae90da4c2fe821b0187344cfae152c8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 13 Apr 2023 11:09:24 +1000 Subject: [PATCH] tests for invocies --- app/Jobs/Company/CompanyImport.php | 3 ++- tests/Unit/InvoiceTest.php | 34 +++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 52049d9dc29c..fabd3ccd1118 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -1338,7 +1338,8 @@ class CompanyImport implements ShouldQueue unset($obj_array[$un]); } - if ($class instanceof CompanyGateway) { + if ($class == 'App\Models\CompanyGateway') { + if (Ninja::isHosted() && $obj_array['gateway_key'] == 'd14dd26a37cecc30fdd65700bfb55b23') { $obj_array['gateway_key'] = 'd14dd26a47cecc30fdd65700bfb67b34'; } diff --git a/tests/Unit/InvoiceTest.php b/tests/Unit/InvoiceTest.php index a289f8f01356..e580155cacb2 100644 --- a/tests/Unit/InvoiceTest.php +++ b/tests/Unit/InvoiceTest.php @@ -11,13 +11,15 @@ namespace Tests\Unit; +use Tests\TestCase; +use App\Models\Invoice; +use Tests\MockAccountData; +use App\DataMapper\InvoiceItem; +use App\Factory\InvoiceFactory; use App\Factory\InvoiceItemFactory; use App\Helpers\Invoice\InvoiceSum; use App\Helpers\Invoice\InvoiceSumInclusive; -use App\Models\Invoice; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Tests\MockAccountData; -use Tests\TestCase; /** * @test @@ -47,6 +49,32 @@ class InvoiceTest extends TestCase $this->invoice_calc = new InvoiceSum($this->invoice); } + public function testRoundingWithLargeUnitCostPrecision() + { + $invoice = InvoiceFactory::create($this->company->id, $this->user->id); + $invoice->client_id = $this->client->id; + $invoice->uses_inclusive_taxes = false; + + $line_items = []; + + $line_item = new InvoiceItem; + $line_item->quantity = 1; + $line_item->cost = 82.6446; + $line_item->tax_rate1 = 21; + $line_item->tax_name1 = 'Test'; + $line_item->product_key = 'Test'; + $line_item->notes = 'Test'; + $line_items[] = $line_item; + + $invoice->line_items = $line_items; + $invoice->save(); + + $invoice = $invoice->calc()->getInvoice(); + + $this->assertEquals(100, $invoice->amount); + + } + public function testInclusiveRounding() { $this->invoice->line_items = [];