diff --git a/app/Services/Email/EmailMailable.php b/app/Services/Email/EmailMailable.php index 085325cecff6..665a0c0ac797 100644 --- a/app/Services/Email/EmailMailable.php +++ b/app/Services/Email/EmailMailable.php @@ -14,12 +14,16 @@ namespace App\Services\Email; use App\Models\Document; use Illuminate\Mail\Mailable; use Illuminate\Mail\Attachment; +use Illuminate\Support\Facades\URL; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Headers; use Illuminate\Mail\Mailables\Envelope; class EmailMailable extends Mailable { + + public int $max_attachment_size = 3000000; + /** * Create a new message instance. * @@ -53,6 +57,16 @@ class EmailMailable extends Mailable */ public function content() { + + $links = Document::whereIn('id',$this->email_object->documents) + ->where('size', '>', $this->max_attachment_size) + ->cursor() + ->map(function ($document){ + + return " $document->hash]) ."'>". $document->name .""; + + }); + return new Content( view: $this->email_object->html_template, text: $this->email_object->text_template, @@ -64,7 +78,8 @@ class EmailMailable extends Mailable 'logo' => $this->email_object->logo, 'signature' => $this->email_object->signature, 'company' => $this->email_object->company, - 'greeting' => '' + 'greeting' => '', + 'links' => array_merge($this->email_object->links, $links->toArray()), ] ); } @@ -78,18 +93,20 @@ class EmailMailable extends Mailable { $attachments = []; - foreach ($this->email_object->attachments as $file) { - $attachments[] = Attachment::fromData(fn () => base64_decode($file['file']), $file['name']); - } + $attachments = collect($this->email_object->attachments)->map(function ($file){ + return Attachment::fromData(fn () => base64_decode($file['file']), $file['name']); + }); - foreach($this->email_object->documents as $doc_id){ - $document = Document::find($doc_id); + $documents = Document::whereIn('id',$this->email_object->documents) + ->where('size', '<', $this->max_attachment_size) + ->cursor() + ->map(function ($document){ - if($document) - $attachments[] = Attachment::fromData(fn () => $document->getFile(), $document->name); - } + return Attachment::fromData(fn () => $document->getFile(), $document->name); - return $attachments; + }); + + return $attachments->merge($documents)->toArray(); } /** diff --git a/app/Services/Email/EmailObject.php b/app/Services/Email/EmailObject.php index 6f3c10ece3b5..c5f160016115 100644 --- a/app/Services/Email/EmailObject.php +++ b/app/Services/Email/EmailObject.php @@ -111,4 +111,6 @@ class EmailObject public array $documents = []; public ?string $template = null; //invoice //quote //reminder1 + + public array $links = []; } diff --git a/resources/views/email/template/client.blade.php b/resources/views/email/template/client.blade.php index b4d5e9a27429..544437512b3d 100644 --- a/resources/views/email/template/client.blade.php +++ b/resources/views/email/template/client.blade.php @@ -167,13 +167,15 @@ + @isset($links)