Fixes for applying the correct amount to client balance

This commit is contained in:
David Bomba 2022-11-22 10:46:42 +11:00
parent cf84f5b24d
commit 3345984b65
5 changed files with 14 additions and 10 deletions

View File

@ -1 +1 @@
5.5.41 5.5.42

View File

@ -104,7 +104,6 @@ class DeletePayment
$client = $this->payment $client = $this->payment
->client ->client
->fresh()
->service() ->service()
->updateBalance($net_deletable) ->updateBalance($net_deletable)
->save(); ->save();
@ -136,9 +135,8 @@ class DeletePayment
}); });
} }
$client = $this->payment->client->fresh(); $this->payment
->client
$client
->service() ->service()
->updatePaidToDate(($this->payment->amount - $this->payment->refunded) * -1) ->updatePaidToDate(($this->payment->amount - $this->payment->refunded) * -1)
->save(); ->save();
@ -146,7 +144,7 @@ class DeletePayment
$transaction = [ $transaction = [
'invoice' => [], 'invoice' => [],
'payment' => [], 'payment' => [],
'client' => $client->transaction_event(), 'client' => $this->payment->client->transaction_event(),
'credit' => [], 'credit' => [],
'metadata' => [], 'metadata' => [],
]; ];

View File

@ -62,12 +62,14 @@ class UpdateInvoicePayment
$paid_amount = $paid_invoice->amount; $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 */ /* 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) if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
$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*/ /*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! //caution what if we amount paid was less than partial - we wipe it!
$invoice->balance -= $paid_amount; $invoice->balance -= $paid_amount;

View File

@ -95,10 +95,14 @@ class SystemHealth
if(strlen(config('ninja.currency_converter_api_key')) == 0){ if(strlen(config('ninja.currency_converter_api_key')) == 0){
try{
$cs = DB::table('clients') $cs = DB::table('clients')
->select('settings->currency_id as id') ->select('settings->currency_id as id')
->get(); ->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){ $currency_count = $cs->unique('id')->filter(function ($value){
return !is_null($value->id); return !is_null($value->id);

View File

@ -14,8 +14,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => '5.5.41', 'app_version' => '5.5.42',
'app_tag' => '5.5.41', 'app_tag' => '5.5.42',
'minimum_client_version' => '5.0.16', 'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1', 'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', ''), 'api_secret' => env('API_SECRET', ''),