|
23 | 23 | use Illuminate\Bus\Queueable;
|
24 | 24 | use Illuminate\Mail\Mailable;
|
25 | 25 | use Illuminate\Queue\SerializesModels;
|
| 26 | +use App\Utils\Ninja; |
26 | 27 |
|
27 | 28 | class TemplateEmail extends Mailable
|
28 | 29 | {
|
@@ -87,52 +88,64 @@ public function build()
|
87 | 88 |
|
88 | 89 | $this->from(config('mail.from.address'), $email_from_name);
|
89 | 90 |
|
90 |
| - if (strlen($settings->bcc_email) > 1) |
91 |
| - $this->bcc(explode(",",str_replace(" ", "", $settings->bcc_email)));//remove whitespace if any has been inserted. |
92 |
| - |
93 |
| - $this->subject($this->build_email->getSubject()) |
94 |
| - ->text('email.template.plain', [ |
95 |
| - 'body' => $this->build_email->getBody(), |
96 |
| - 'footer' => $this->build_email->getFooter(), |
97 |
| - 'whitelabel' => $this->client->user->account->isPaid() ? true : false, |
98 |
| - 'settings' => $settings, |
99 |
| - ]) |
100 |
| - ->view($template_name, [ |
101 |
| - 'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]), |
102 |
| - 'body' => $this->build_email->getBody(), |
103 |
| - 'footer' => $this->build_email->getFooter(), |
104 |
| - 'view_link' => $this->build_email->getViewLink(), |
105 |
| - 'view_text' => $this->build_email->getViewText(), |
106 |
| - 'title' => '', |
107 |
| - 'signature' => $signature, |
108 |
| - 'settings' => $settings, |
109 |
| - 'company' => $company, |
110 |
| - 'whitelabel' => $this->client->user->account->isPaid() ? true : false, |
111 |
| - 'logo' => $this->company->present()->logo(), |
112 |
| - ]) |
113 |
| - ->withSwiftMessage(function ($message) use($company){ |
114 |
| - $message->getHeaders()->addTextHeader('Tag', $company->company_key); |
115 |
| - $message->invitation = $this->invitation; |
116 |
| - }); |
| 91 | + if (strlen($settings->bcc_email) > 1) { |
| 92 | + if (Ninja::isHosted()) { |
117 | 93 |
|
118 |
| - foreach ($this->build_email->getAttachments() as $file) { |
119 |
| - |
120 |
| - if(is_string($file)) |
121 |
| - $this->attach($file); |
122 |
| - elseif(is_array($file)) |
123 |
| - $this->attach($file['path'], ['as' => $file['name'], 'mime' => $file['mime']]); |
| 94 | + if($company->account->isPaid()) { |
| 95 | + $bccs = explode(',', str_replace(' ', '', $settings->bcc_email)); |
| 96 | + $this->bcc(array_slice($bccs, 0, 5)); |
| 97 | + } |
124 | 98 |
|
| 99 | + } else { |
| 100 | + $this->bcc(explode(',', str_replace(' ', '', $settings->bcc_email))); |
| 101 | + } |
125 | 102 | }
|
126 | 103 |
|
127 |
| - if($this->invitation && $this->invitation->invoice && $settings->ubl_email_attachment && $this->company->account->hasFeature(Account::FEATURE_DOCUMENTS)){ |
| 104 | + $this->subject(str_replace("<br>", "", $this->build_email->getSubject())) |
| 105 | + ->text('email.template.text', [ |
| 106 | + 'text_body' => $this->build_email->getTextBody(), |
| 107 | + 'whitelabel' => $this->client->user->account->isPaid() ? true : false, |
| 108 | + 'settings' => $settings, |
| 109 | + ]) |
| 110 | + ->view($template_name, [ |
| 111 | + 'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]), |
| 112 | + 'body' => $this->build_email->getBody(), |
| 113 | + 'footer' => $this->build_email->getFooter(), |
| 114 | + 'view_link' => $this->build_email->getViewLink(), |
| 115 | + 'view_text' => $this->build_email->getViewText(), |
| 116 | + 'title' => '', |
| 117 | + 'signature' => $signature, |
| 118 | + 'settings' => $settings, |
| 119 | + 'company' => $company, |
| 120 | + 'whitelabel' => $this->client->user->account->isPaid() ? true : false, |
| 121 | + 'logo' => $this->company->present()->logo($settings), |
| 122 | + 'links' => $this->build_email->getAttachmentLinks(), |
| 123 | + ]); |
128 | 124 |
|
129 |
| - $ubl_string = CreateZugferd::dispatchNow($this->invitation->invoice); |
| 125 | + foreach ($this->build_email->getAttachments() as $file) { |
| 126 | + if (array_key_exists('file', $file)) { |
| 127 | + $this->attachData(base64_decode($file['file']), $file['name']); |
| 128 | + } else { |
| 129 | + $this->attach($file['path'], ['as' => $file['name'], 'mime' => null]); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + if($this->invitation && $this->invitation->invoice && $settings->ubl_email_attachment && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)){ |
| 134 | + $ubl_string = (new CreateZugferd($this->invitation->invoice))->handle(); |
130 | 135 |
|
131 | 136 | nlog($ubl_string);
|
132 | 137 |
|
133 | 138 | if($ubl_string)
|
134 | 139 | $this->attachData($ubl_string, $this->invitation->invoice->getFileName('xml'));
|
135 | 140 |
|
| 141 | + } |
| 142 | + if ($this->invitation && $this->invitation->invoice && $this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { |
| 143 | + $xml_string = $this->invitation->invoice->service()->getEInvoice($this->invitation->contact); |
| 144 | + |
| 145 | + if($xml_string) { |
| 146 | + $this->attachData($xml_string, $this->invitation->invoice->getEFileName("xml")); |
| 147 | + } |
| 148 | + |
136 | 149 | }
|
137 | 150 |
|
138 | 151 | return $this;
|
|
0 commit comments