From 7573c611cf85abaa45ff87b091574cd83a963a04 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 15 Aug 2025 10:57:35 +1000 Subject: [PATCH] check vat number prior to validation --- app/Services/Tax/TaxService.php | 2 +- app/Services/Tax/VatNumberCheck.php | 7 +- .../Export/ReportCsvGenerationTest.php | 73 ++++++++++++------- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/app/Services/Tax/TaxService.php b/app/Services/Tax/TaxService.php index 960fc58147..a22bb85df3 100644 --- a/app/Services/Tax/TaxService.php +++ b/app/Services/Tax/TaxService.php @@ -31,7 +31,7 @@ class TaxService $vat_check = (new VatNumberCheck($this->client->vat_number, $client_country_code))->run(); - nlog($vat_check); + // nlog($vat_check); if ($vat_check->isValid()) { diff --git a/app/Services/Tax/VatNumberCheck.php b/app/Services/Tax/VatNumberCheck.php index 36d77de502..93f1a931aa 100644 --- a/app/Services/Tax/VatNumberCheck.php +++ b/app/Services/Tax/VatNumberCheck.php @@ -22,7 +22,12 @@ class VatNumberCheck public function run() { - return $this->checkvat_number(); + if(strlen($this->vat_number ?? '') == ){ + $this->response = ['valid' => false, 'error' => 'No VAT number provided']; + } + else{ + return $this->checkvat_number(); + } } private function checkvat_number(): self diff --git a/tests/Feature/Export/ReportCsvGenerationTest.php b/tests/Feature/Export/ReportCsvGenerationTest.php index be3202c8a0..aa6ebfa184 100644 --- a/tests/Feature/Export/ReportCsvGenerationTest.php +++ b/tests/Feature/Export/ReportCsvGenerationTest.php @@ -1172,13 +1172,15 @@ $this->account->forceDelete(); $this->assertEquals('', $this->getFirstValueByColumn($csv, 'Client Assigned User')); $this->assertEquals('USD', $this->getFirstValueByColumn($csv, 'Client Currency')); -$this->account->forceDelete(); + $this->account->forceDelete(); } public function testCreditJsonReport() { + config(['queue.default' => 'redis']); + Credit::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, @@ -1205,7 +1207,6 @@ $this->account->forceDelete(); 'X-API-TOKEN' => $this->token, ])->postJson('/api/v1/reports/credits?output=json', $data); - $response->assertStatus(200); $arr = $response->json(); @@ -1217,8 +1218,7 @@ $this->account->forceDelete(); $response->assertStatus(409); - -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -1285,7 +1285,7 @@ $this->account->forceDelete(); public function testInvoiceCustomColumnsCsvGeneration() { - \App\Models\Invoice::factory()->create([ + $invoice = \App\Models\Invoice::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id, @@ -1475,7 +1475,7 @@ $this->account->forceDelete(); public function testInvoiceItemsCustomColumnsCsvGeneration() { - \App\Models\Invoice::factory()->create([ + $invoice = \App\Models\Invoice::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id, @@ -1642,7 +1642,6 @@ $this->account->forceDelete(); $csv = $response->body(); - $this->assertEquals('bob', $this->getFirstValueByColumn($csv, 'Client Name')); $this->assertEquals('1234', $this->getFirstValueByColumn($csv, 'Quote Number')); $this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Item Quantity')); @@ -1655,7 +1654,6 @@ $this->account->forceDelete(); $this->assertEquals('GST', $this->getFirstValueByColumn($csv, 'Item Tax Name 1')); $this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Item Tax Rate 1')); - $data = [ 'date_range' => 'all', 'report_keys' => $this->all_client_report_keys, @@ -1668,8 +1666,7 @@ $this->account->forceDelete(); 'X-API-TOKEN' => $this->token, ])->post('/api/v1/reports/quote_items', $data)->assertStatus(200); - -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -1730,8 +1727,7 @@ $this->account->forceDelete(); $this->assertEquals('Private', $this->getFirstValueByColumn($csv, 'Purchase Order Private Notes')); $this->assertEquals('Terms', $this->getFirstValueByColumn($csv, 'Purchase Order Terms')); - -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -1748,7 +1744,6 @@ $this->account->forceDelete(); ] ); - \App\Models\PurchaseOrder::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, @@ -1817,7 +1812,7 @@ $this->account->forceDelete(); $this->assertEquals('GST', $this->getFirstValueByColumn($csv, 'Item Tax Name 1')); $this->assertEquals('10', $this->getFirstValueByColumn($csv, 'Item Tax Rate 1')); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -1879,7 +1874,7 @@ $this->account->forceDelete(); ])->post('/api/v1/reports/quotes', $data)->assertStatus(200); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -1896,11 +1891,25 @@ $this->account->forceDelete(); 'balance' => 100, 'number' => '12345', 'status_id' => 2, - 'discount' => 10, + 'discount' => 0, 'po_number' => '1234', 'public_notes' => 'Public', 'private_notes' => 'Private', 'terms' => 'Terms', + 'tax_rate1' => 0, + 'tax_rate2' => 0, + 'tax_rate3' => 0, + 'line_items' => [ + [ + 'quantity' => 1, + 'product_key' => 'product_key', + 'notes' => 'notes', + 'cost' => 100, + 'custom_value1' => 'Custom 1', + 'custom_value2' => 'Custom 2', + 'custom_value3' => 'Custom 3', + ] + ] ]); $repo = new InvoiceRepository(); @@ -1935,7 +1944,7 @@ $this->account->forceDelete(); $this->assertEquals(100, $this->getFirstValueByColumn($csv, 'Payment Amount')); $this->assertEquals(now()->addSeconds($this->company->timezone()->utc_offset)->format('Y-m-d'), $this->getFirstValueByColumn($csv, 'Payment Date')); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -1982,7 +1991,7 @@ $this->account->forceDelete(); $this->assertEquals('john@doe.com', $res[1]); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -2019,6 +2028,20 @@ $this->account->forceDelete(); 'public_notes' => 'Public', 'private_notes' => 'Private', 'terms' => 'Terms', + 'tax_rate1' => 0, + 'tax_rate2' => 0, + 'tax_rate3' => 0, + 'line_items' => [ + [ + 'quantity' => 1, + 'product_key' => 'product_key', + 'notes' => 'notes', + 'cost' => 110, + 'custom_value1' => 'Custom 1', + 'custom_value2' => 'Custom 2', + 'custom_value3' => 'Custom 3', + ] + ] ]); $data = [ @@ -2034,8 +2057,6 @@ $this->account->forceDelete(); $response->assertStatus(200); - $response->assertStatus(200); - $arr = $response->json(); $hash = $arr['message']; @@ -2079,7 +2100,7 @@ $this->account->forceDelete(); 'X-API-TOKEN' => $this->token, ])->post('/api/v1/reports/credits', $data)->assertStatus(200); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -2165,7 +2186,7 @@ $this->account->forceDelete(); $this->assertEquals(floatval(30), $this->getFirstValueByColumn($csv, 'Invoice Tax Rate 3')); $this->assertEquals('Sent', $this->getFirstValueByColumn($csv, 'Invoice Status')); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -2249,7 +2270,7 @@ $this->account->forceDelete(); $this->assertEquals(floatval(30), $this->getFirstValueByColumn($csv, 'Recurring Invoice Tax Rate 3')); $this->assertEquals('Daily', $this->getFirstValueByColumn($csv, 'Recurring Invoice How Often')); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -2257,7 +2278,7 @@ $this->account->forceDelete(); public function testQuoteCsvGeneration() { - \App\Models\Quote::factory()->create([ + $quote = \App\Models\Quote::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id, @@ -2333,7 +2354,7 @@ $this->account->forceDelete(); $this->assertEquals(floatval(30), $this->getFirstValueByColumn($csv, 'Quote Tax Rate 3')); $this->assertEquals('Expired', $this->getFirstValueByColumn($csv, 'Quote Status')); -$this->account->forceDelete(); + $this->account->forceDelete(); } @@ -2386,7 +2407,7 @@ $this->account->forceDelete(); $response = $this->poll($hash); $csv = $response->body(); -$this->account->forceDelete(); + $this->account->forceDelete(); }