From 594646823ca585a92ce5cb3d81c85f5ea0ae5b91 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Mar 2023 20:47:13 +1100 Subject: [PATCH] Add UBL feature to invoices --- app/Jobs/Invoice/CreateUbl.php | 6 ++---- app/Models/Invoice.php | 1 - app/Services/Email/EmailDefaults.php | 14 +++++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Invoice/CreateUbl.php b/app/Jobs/Invoice/CreateUbl.php index 0087e98fd8d0..441726583507 100644 --- a/app/Jobs/Invoice/CreateUbl.php +++ b/app/Jobs/Invoice/CreateUbl.php @@ -48,10 +48,8 @@ class CreateUbl implements ShouldQueue } /** - * Execute the job. - * - * - * @return void + * Execute the job + * @return ?string */ public function handle() { diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index d7a50c34ec42..84cb253604fa 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1,4 +1,3 @@ - email->email_object->settings->document_email_attachment || $this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) + if (!$this->email->email_object->settings->document_email_attachment || !$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) return $this; $this->email->email_object->documents = array_merge($this->email->email_object->documents, $this->email->company->documents->pluck('id')->toArray()); @@ -318,6 +320,16 @@ class EmailDefaults } + + if ($this->email->email_object->entity instanceof Invoice && $this->email->email_object->settings->ubl_email_attachment) { + $ubl_string = (new CreateUbl($this->email->email_object->entity))->handle(); + + if ($ubl_string) { + $this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [Attachment::fromData(fn () => $ubl_string, $this->email->email_object->entity->getFileName('xml'))]); + + } + } + return $this; }