From e302b9f9cb89efac0d3b2d9d7a412c006124aaf8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 22 Feb 2023 20:13:50 +1100 Subject: [PATCH] Only send one payment email receipt --- app/Jobs/Payment/EmailPayment.php | 1 - app/Jobs/Util/UnlinkFile.php | 4 ++-- app/Services/Invoice/ApplyPaymentAmount.php | 2 +- app/Services/Invoice/InvoiceService.php | 1 - app/Services/Payment/SendEmail.php | 14 +++++++------- app/Utils/Traits/Uploadable.php | 4 +--- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index a4b83262f70a..4ef30426d22c 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -60,7 +60,6 @@ class EmailPayment implements ShouldQueue /** * Execute the job. * - * * @return void */ public function handle() diff --git a/app/Jobs/Util/UnlinkFile.php b/app/Jobs/Util/UnlinkFile.php index 7b87d43edf7b..82757879f794 100644 --- a/app/Jobs/Util/UnlinkFile.php +++ b/app/Jobs/Util/UnlinkFile.php @@ -26,7 +26,7 @@ class UnlinkFile implements ShouldQueue protected $disk; - public function __construct(string $disk, string $file_path) + public function __construct(string $disk, ?string $file_path) { $this->file_path = $file_path; $this->disk = $disk; @@ -40,7 +40,7 @@ class UnlinkFile implements ShouldQueue public function handle() { /* Do not delete files if we are on the sync queue*/ - if (config('queue.default') == 'sync') { + if (config('queue.default') == 'sync' || ! $this->file_path) { return; } diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index 690d54f86146..59f7269d9a57 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -114,7 +114,7 @@ class ApplyPaymentAmount extends AbstractService $exchange_rate = new CurrencyApi(); $payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date)); - //$payment->exchange_currency_id = $client_currency; // 23/06/2021 + $payment->exchange_currency_id = $company_currency; $payment->saveQuietly(); diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 34919ad37ad8..6c4fe4882003 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -103,7 +103,6 @@ class InvoiceService * @param Payment $payment The Payment * @param float $payment_amount The Payment amount * @return InvoiceService Parent class object - * @deprecated 24-11-2022 - cannot find any references to this method anywhere */ public function applyPayment(Payment $payment, float $payment_amount) { diff --git a/app/Services/Payment/SendEmail.php b/app/Services/Payment/SendEmail.php index 04c8e2da6da8..ed07083bc6fa 100644 --- a/app/Services/Payment/SendEmail.php +++ b/app/Services/Payment/SendEmail.php @@ -36,12 +36,12 @@ class SendEmail $contact = $this->payment->client->contacts()->first(); - $this->payment->invoices->sortByDesc('id')->first(function ($invoice) { - $invoice->invitations->each(function ($invitation) { - if (!$invitation->contact->trashed() && $invitation->contact->email) { - EmailPayment::dispatch($this->payment, $this->payment->company, $invitation->contact); - } - }); - }); + // $this->payment->invoices->sortByDesc('id')->first(function ($invoice) { + // $invoice->invitations->each(function ($invitation) { + // if (!$invitation->contact->trashed() && $invitation->contact->email) { + EmailPayment::dispatch($this->payment, $this->payment->company, $contact); + // } + // }); + // }); } } diff --git a/app/Utils/Traits/Uploadable.php b/app/Utils/Traits/Uploadable.php index 69be5021f470..2e3987a329fe 100644 --- a/app/Utils/Traits/Uploadable.php +++ b/app/Utils/Traits/Uploadable.php @@ -22,9 +22,7 @@ trait Uploadable { public function removeLogo($company) { - //if (Storage::disk(config('filesystems.default'))->exists($company->settings->company_logo)) { - (new UnlinkFile(config('filesystems.default'), $company->settings->company_logo))->handle(); - //} + (new UnlinkFile(config('filesystems.default'), $company?->settings?->company_logo))->handle(); } public function uploadLogo($file, $company, $entity)