From 3345984b65d3af4d982ecfcb811485a8ff451390 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 22 Nov 2022 10:46:42 +1100 Subject: [PATCH] Fixes for applying the correct amount to client balance --- VERSION.txt | 2 +- app/Services/Payment/DeletePayment.php | 8 +++----- app/Services/Payment/UpdateInvoicePayment.php | 4 +++- app/Utils/SystemHealth.php | 6 +++++- config/ninja.php | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 8a55abf0b000..5c41e37e4728 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.5.41 \ No newline at end of file +5.5.42 \ No newline at end of file diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 0b70b4c9f855..e81b7a932f5a 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -104,7 +104,6 @@ class DeletePayment $client = $this->payment ->client - ->fresh() ->service() ->updateBalance($net_deletable) ->save(); @@ -136,9 +135,8 @@ class DeletePayment }); } - $client = $this->payment->client->fresh(); - - $client + $this->payment + ->client ->service() ->updatePaidToDate(($this->payment->amount - $this->payment->refunded) * -1) ->save(); @@ -146,7 +144,7 @@ class DeletePayment $transaction = [ 'invoice' => [], 'payment' => [], - 'client' => $client->transaction_event(), + 'client' => $this->payment->client->transaction_event(), 'credit' => [], 'metadata' => [], ]; diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 4efbeddb715c..f3cb3debfe6a 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -62,12 +62,14 @@ class UpdateInvoicePayment $paid_amount = $paid_invoice->amount; } - $client->service()->updateBalanceAndPaidToDate($paid_amount*-1, $paid_amount); + $client->service()->updatePaidToDate($paid_amount); //always use the payment->amount /* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */ if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance) $paid_amount = $invoice->balance; + $client->service()->updateBalance($paid_amount*-1); //only ever use the amount applied to the invoice + /*Improve performance here - 26-01-2022 - also change the order of events for invoice first*/ //caution what if we amount paid was less than partial - we wipe it! $invoice->balance -= $paid_amount; diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index 88f64e12c535..c8629c9f70f1 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -95,10 +95,14 @@ class SystemHealth if(strlen(config('ninja.currency_converter_api_key')) == 0){ + try{ $cs = DB::table('clients') ->select('settings->currency_id as id') ->get(); - + } + catch(\Exception $e){ + return true; //fresh installs, there may be no DB connection, nor migrations could have run yet. + } $currency_count = $cs->unique('id')->filter(function ($value){ return !is_null($value->id); diff --git a/config/ninja.php b/config/ninja.php index edfc4c68b0f2..b850fef4ff1e 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.5.41', - 'app_tag' => '5.5.41', + 'app_version' => '5.5.42', + 'app_tag' => '5.5.42', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),