From 1b551796c512c21a6f705cea99ae7582605a8216 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 15 Jan 2021 14:10:35 +1100 Subject: [PATCH] Recurring PDF Dependencies --- .../Presenters/RecurringInvoicePresenter.php | 31 ++++++++++ app/Services/Recurring/GetInvoicePdf.php | 60 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 app/Models/Presenters/RecurringInvoicePresenter.php create mode 100644 app/Services/Recurring/GetInvoicePdf.php diff --git a/app/Models/Presenters/RecurringInvoicePresenter.php b/app/Models/Presenters/RecurringInvoicePresenter.php new file mode 100644 index 000000000000..99a3eafbab91 --- /dev/null +++ b/app/Models/Presenters/RecurringInvoicePresenter.php @@ -0,0 +1,31 @@ +entity = $entity; + + $this->contact = $contact; + } + + public function run() + { + if (! $this->contact) { + $this->contact = $this->entity->client->primary_contact()->first(); + } + + $invitation = $this->entity->invitations->where('client_contact_id', $this->contact->id)->first(); + + $path = $this->entity->client->recurring_invoice_filepath(); + + $file_path = $path.$this->entity->hashed_id.'.pdf'; + + $disk = config('filesystems.default'); + + $file = Storage::disk($disk)->exists($file_path); + + if (! $file) { + $file_path = CreateEntityPdf::dispatchNow($invitation); + } + + + /* Copy from remote disk to local when using cloud file storage. */ + if(config('filesystems.default') == 's3') + return TempFile::path(Storage::disk($disk)->url($file_path)); + + // return Storage::disk($disk)->url($file_path); + return Storage::disk($disk)->path($file_path); + } +}