From 9888d7acb9aed6dd923edc7b9b04370f6f229bc4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Mar 2021 13:28:35 +1100 Subject: [PATCH] Improve delete pdf performance --- app/Http/Controllers/InvoiceController.php | 8 +++++--- app/Services/Invoice/MarkPaid.php | 1 + app/Services/Invoice/MarkSent.php | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 77ab97a7d900..59e400e60c45 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -396,6 +396,8 @@ class InvoiceController extends BaseController } $invoice = $this->invoice_repo->save($request->all(), $invoice); + + $invoice->service()->deletePdf(); event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars())); @@ -697,14 +699,14 @@ class InvoiceController extends BaseController } break; case 'cancel': - $invoice = $invoice->service()->handleCancellation()->save(); + $invoice = $invoice->service()->handleCancellation()->deletePdf()->save(); if (! $bulk) { $this->itemResponse($invoice); } break; case 'reverse': - $invoice = $invoice->service()->handleReversal()->save(); + $invoice = $invoice->service()->handleReversal()->deletePdf()->save(); if (! $bulk) { $this->itemResponse($invoice); @@ -720,7 +722,7 @@ class InvoiceController extends BaseController } //touch reminder1,2,3_sent + last_sent here if the email is a reminder. - $invoice->service()->touchReminder($this->reminder_template)->save(); + $invoice->service()->touchReminder($this->reminder_template)->deletePdf()->save(); $invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) { EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index e3f2c1c5bb54..7f827a5fd842 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -74,6 +74,7 @@ class MarkPaid extends AbstractService ->updatePaidToDate($payment->amount) ->setStatus(Invoice::STATUS_PAID) ->applyNumber() + ->deletePdf() ->save(); if ($this->invoice->client->getSetting('client_manual_payment_notification')) diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 1767e61e94f3..c5149a462577 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -47,6 +47,7 @@ class MarkSent extends AbstractService ->applyNumber() ->setDueDate() ->updateBalance($this->invoice->amount) + ->deletePdf() ->save(); $this->client->service()->updateBalance($this->invoice->balance)->save();