From 897f170307cd012497a73ff8be8da320a09429de Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 8 Jun 2023 17:11:19 +1000 Subject: [PATCH] Clean up of Apply Number class for payments --- .../Migration/PaymentMigrationRepository.php | 5 +++-- app/Services/Payment/ApplyNumber.php | 10 ++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index d5a00202522b..7fab7943fbd1 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -98,11 +98,10 @@ class PaymentMigrationRepository extends BaseRepository } $payment->deleted_at = $data['deleted_at'] ?: null; - $payment->save(); + if ($payment->currency_id == 0) { $payment->currency_id = $payment->company->settings->currency_id; - $payment->save(); } /*Ensure payment number generated*/ @@ -110,6 +109,8 @@ class PaymentMigrationRepository extends BaseRepository $payment->number = $payment->client->getNextPaymentNumber($payment->client, $payment); } + $payment->save(); + $invoice_totals = 0; $credit_totals = 0; $invoices = false; diff --git a/app/Services/Payment/ApplyNumber.php b/app/Services/Payment/ApplyNumber.php index 9345867cd176..76c915204fa5 100644 --- a/app/Services/Payment/ApplyNumber.php +++ b/app/Services/Payment/ApplyNumber.php @@ -20,15 +20,10 @@ class ApplyNumber extends AbstractService { use GeneratesCounter; - private $payment; - private bool $completed = true; - public function __construct(Payment $payment) + public function __construct(private Payment $payment) { - $this->client = $payment->client; - - $this->payment = $payment; } public function run() @@ -38,7 +33,6 @@ class ApplyNumber extends AbstractService } $this->trySaving(); - // $this->payment->number = $this->getNextPaymentNumber($this->client, $this->payment); return $this->payment; } @@ -49,7 +43,7 @@ class ApplyNumber extends AbstractService do { try { - $this->payment->number = $this->getNextPaymentNumber($this->client, $this->payment); + $this->payment->number = $this->getNextPaymentNumber($this->payment->client, $this->payment); $this->payment->saveQuietly(); $this->completed = false;