From 1208e942aa34a56d2ab614ff9c3c2343398b5a69 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 12 Mar 2023 16:41:43 +1100 Subject: [PATCH] Fixes for attachments --- app/Services/Email/EmailDefaults.php | 30 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index 8a391fa8e5cb..7ac53f20731a 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -273,24 +273,41 @@ class EmailDefaults $documents = []; /* Return early if the user cannot attach documents */ - if (!$this->email->email_object->settings->document_email_attachment || !$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { + if (!$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { return $this; } /** Purchase Order / Invoice / Credit / Quote PDF */ - if ($this->email->email_object->entity instanceof PurchaseOrder) { + if ($this->email->email_object->settings->pdf_email_attachment && $this->email->email_object->entity instanceof PurchaseOrder) { + $pdf = (new CreatePurchaseOrderPdf($this->email->email_object->invitation))->rawPdf(); $this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]); + } elseif ($this->email->email_object->settings->pdf_email_attachment && ($this->email->email_object->entity instanceof Invoice || $this->email->email_object->entity instanceof Quote || $this->email->email_object->entity instanceof Credit)) { + $pdf = ((new CreateRawPdf($this->email->email_object->invitation, $this->email->company->db))->handle()); $this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]); + } + /** UBL xml file */ + 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, [['file' => base64_encode($ubl_string), 'name' => $this->email->email_object->entity->getFileName('xml')]]); + } + } + + if(!$this->email->email_object->settings->document_email_attachment) + return $this; + + /* Company Documents */ $this->email->email_object->documents = array_merge($this->email->email_object->documents, $this->email->company->documents->pluck('id')->toArray()); @@ -337,15 +354,6 @@ class EmailDefaults } } - /** UBL xml file */ - 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, [['file' => base64_encode($ubl_string), 'name' => $this->email->email_object->entity->getFileName('xml')]]); - } - } - return $this; }