From 0d654dae952345d63132389f6e331a741e670241 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 Jul 2024 11:47:38 +1000 Subject: [PATCH] Fixes for tax map display of surcharge taxes --- app/Filters/InvoiceFilters.php | 2 +- app/Helpers/Invoice/InvoiceSumInclusive.php | 9 ++--- app/Repositories/ExpenseRepository.php | 3 +- tests/Feature/ExpenseApiTest.php | 38 +++++++++++++++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index 0343402a37b2..8567e9908344 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -320,7 +320,7 @@ class InvoiceFilters extends QueryFilters { $sort_col = explode('|', $sort); - if (!is_array($sort_col) || count($sort_col) != 2) { + if (!is_array($sort_col) || count($sort_col) != 2 || in_array($sort_col[0], ['documents'])) { return $this->builder; } diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index fe50d9cb1fb0..cb297250b273 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -74,8 +74,8 @@ class InvoiceSumInclusive { $this->calculateLineItems() ->calculateDiscount() - ->calculateInvoiceTaxes() - ->calculateCustomValues() + ->calculateCustomValues() //06-07-2024 + ->calculateInvoiceTaxes() //shuffle order of invoicetaxes/custom values to include the surcharge taxes in the tax map ->setTaxMap() ->calculateTotals() //just don't add the taxes!! ->calculateBalance() @@ -119,8 +119,6 @@ class InvoiceSumInclusive $this->total_taxes += $this->multiInclusiveTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_tax4); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4); - $this->total += $this->total_custom_values; - return $this; } @@ -172,6 +170,8 @@ class InvoiceSumInclusive $this->total_tax_map[] = ['name' => $this->invoice->tax_name3.' '.floatval($this->invoice->tax_rate3).'%', 'total' => $tax]; } + $this->total += $this->total_custom_values; //06-07-2024 add the custom surcharge totals here after the tax calculations. + return $this; } @@ -395,4 +395,5 @@ class InvoiceSumInclusive { return $this; } + } diff --git a/app/Repositories/ExpenseRepository.php b/app/Repositories/ExpenseRepository.php index 1bb055ecc733..ab83f2f80fb1 100644 --- a/app/Repositories/ExpenseRepository.php +++ b/app/Repositories/ExpenseRepository.php @@ -47,11 +47,10 @@ class ExpenseRepository extends BaseRepository $user = auth()->user(); $payment_date = &$data['payment_date']; - $vendor_id = &$data['vendor_id']; if($payment_date && $payment_date == $expense->payment_date) { //do nothing - } elseif($payment_date && strlen($payment_date) > 1 && $user->company()->notify_vendor_when_paid && ($vendor_id || $expense->vendor_id)) { + } elseif($payment_date && strlen($payment_date) > 1 && $user->company()->notify_vendor_when_paid && (isset($data['vendor_id']) || $expense->vendor_id)) { $this->notify_vendor = true; } diff --git a/tests/Feature/ExpenseApiTest.php b/tests/Feature/ExpenseApiTest.php index 8ffb2ab43d98..5cf695cb90d1 100644 --- a/tests/Feature/ExpenseApiTest.php +++ b/tests/Feature/ExpenseApiTest.php @@ -47,6 +47,44 @@ class ExpenseApiTest extends TestCase Model::reguard(); } + public function testExpensePutWithVendorStatus() + { + + + $data = + [ + 'vendor_id' => $this->vendor->hashed_id, + 'amount' => 10, + 'date' => '2021-10-01', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/expenses', $data); + + $arr = $response->json(); + $response->assertStatus(200); + + + $this->assertEquals($this->vendor->hashed_id, $arr['data']['vendor_id']); + + $data = [ + 'payment_date' => now()->format('Y-m-d') + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->putJson('/api/v1/expenses/'.$arr['data']['id'], $data); + + $arr = $response->json(); + $response->assertStatus(200); + + $this->assertEquals($this->vendor->hashed_id, $arr['data']['vendor_id']); + + } + public function testTransactionIdClearedOnDelete() { $bi = BankIntegration::factory()->create([