diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 7d6cad5386a5..bc1a0c10ab52 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -257,7 +257,8 @@ class PaymentRepository extends BaseRepository { $payment = $payment->service()->deletePayment(); - event(new PaymentWasDeleted($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + if($payment) + event(new PaymentWasDeleted($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); return $payment; diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index 221c048ed0e5..e60fee96e2a0 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -37,7 +37,7 @@ class ClientService $this->client->balance += $amount; $this->client->save(); - }, 2); + }, 1); } catch (\Throwable $throwable) { nlog("DB ERROR " . $throwable->getMessage()); @@ -58,7 +58,7 @@ class ClientService $this->client->paid_to_date += $paid_to_date; $this->client->save(); - }, 2); + }, 1); } catch (\Throwable $throwable) { nlog("DB ERROR " . $throwable->getMessage()); @@ -79,7 +79,7 @@ class ClientService $this->client->paid_to_date += $amount; $this->client->save(); - }, 2); + }, 1); return $this; } diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index beab99fb323f..10db3699ee14 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -38,22 +38,21 @@ class DeletePayment \DB::connection(config('database.default'))->transaction(function () { - - if ($this->payment->is_deleted) { - return $this->payment; - } - $this->payment = Payment::withTrashed()->where('id', $this->payment->id)->lockForUpdate()->first(); - $this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment - ->updateCreditables() //return the credits first - ->adjustInvoices() - ->deletePaymentables() - ->cleanupPayment() - ->save(); + if (!$this->payment->is_deleted) { + + $this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment + ->updateCreditables() //return the credits first + ->adjustInvoices() + ->deletePaymentables() + ->cleanupPayment() + ->save(); + + } - }, 2); + }, 1); return $this->payment;