From d68918b213b062eb71d4f9b61a506968d5b031bf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 12 Sep 2022 08:33:59 +1000 Subject: [PATCH] Ensure we also query trashed client records before lock --- app/Services/Client/ClientService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index 9e9c5fbf9579..a4d033c34559 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -33,7 +33,7 @@ class ClientService \DB::connection(config('database.default'))->transaction(function () use($amount) { - $this->client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client->balance += $amount; $this->client->save(); @@ -49,7 +49,7 @@ class ClientService \DB::connection(config('database.default'))->transaction(function () use($balance, $paid_to_date) { - $this->client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client->balance += $balance; $this->client->paid_to_date += $paid_to_date; $this->client->save(); @@ -65,7 +65,7 @@ class ClientService \DB::connection(config('database.default'))->transaction(function () use($amount) { - $this->client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client->paid_to_date += $amount; $this->client->save(); @@ -83,7 +83,7 @@ class ClientService public function getCreditBalance() :float { - $credits = Credit::where('client_id', $this->client->id) + $credits = Credit::withTrashed()->where('client_id', $this->client->id) ->where('is_deleted', false) ->where('balance', '>', 0) ->where(function ($query) {