From 1720baccc8401da2209ebe73a3f511fa7291dff0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 15 Jan 2023 14:59:42 +1100 Subject: [PATCH] Checks inside transactions --- app/Services/Invoice/MarkPaid.php | 21 ++++++++++++--------- app/Services/Payment/DeletePayment.php | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index b692144f4044..6c3a12d4cd69 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -57,16 +57,19 @@ class MarkPaid extends AbstractService $this->invoice = Invoice::withTrashed()->where('id', $this->invoice->id)->lockForUpdate()->first(); - $this->payable_balance = $this->invoice->balance; - - $this->invoice - ->service() - ->setExchangeRate() - ->updateBalance($this->payable_balance * -1) - ->updatePaidToDate($this->payable_balance) - ->setStatus(Invoice::STATUS_PAID) - ->save(); + if($this->invoice) + { + $this->payable_balance = $this->invoice->balance; + $this->invoice + ->service() + ->setExchangeRate() + ->updateBalance($this->payable_balance * -1) + ->updatePaidToDate($this->payable_balance) + ->setStatus(Invoice::STATUS_PAID) + ->save(); + } + }, 1); /* Create Payment */ diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 10db3699ee14..5f209d583629 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -40,7 +40,7 @@ class DeletePayment $this->payment = Payment::withTrashed()->where('id', $this->payment->id)->lockForUpdate()->first(); - if (!$this->payment->is_deleted) { + if ($this->payment && !$this->payment->is_deleted) { $this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment ->updateCreditables() //return the credits first