diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index ff77463df864..2fcd68874a81 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -18,7 +18,6 @@ use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\HtmlEngine; use App\Utils\Ninja; use Illuminate\Mail\Mailable; -use Illuminate\Support\Facades\Storage; class TemplateEmail extends Mailable { @@ -111,7 +110,7 @@ class TemplateEmail extends Mailable if (Ninja::isHosted()) { $bccs = explode(',', str_replace(' ', '', $settings->bcc_email)); $this->bcc(array_slice($bccs, 0, 2)); - //$this->bcc(reset($bccs)); //remove whitespace if any has been inserted. + //$this->bcc(reset($bccs)); //remove whitespace if any has been inserted. } else { $this->bcc(explode(',', str_replace(' ', '', $settings->bcc_email))); }//remove whitespace if any has been inserted. @@ -149,16 +148,21 @@ class TemplateEmail extends Mailable if ($this->invitation && $this->invitation->invoice && $settings->ubl_email_attachment && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { $ubl_string = (new CreateUbl($this->invitation->invoice))->handle(); + nlog("template {$ubl_string}"); + if ($ubl_string) { $this->attachData($ubl_string, $this->invitation->invoice->getFileName('xml')); } + } if ($this->invitation && $this->invitation->invoice && $this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { - - $xinvoice_filepath = $this->invitation->invoice->service()->getEInvoice($this->invitation->contact); + $xml_string = $this->invitation->invoice->service()->getEInvoice($this->invitation->contact); - if(Storage::disk(config('filesystems.default'))->exists($xinvoice_filepath)) - $this->attach(Storage::disk(config('filesystems.default'))->path($xinvoice_filepath), ['as' => $this->invitation->invoice->getFileName("xml"), 'mime' => null]); + nlog("template {$xml_string}"); + + if($xml_string) { + $this->attachData($xml_string, $this->invitation->invoice->getEFileName("xml")); + } } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index bd55d0684203..eb4c1772236a 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -237,6 +237,15 @@ class BaseModel extends Model return $this->numberFormatter().'.'.$extension; } + /** + * @param string $extension + * @return string + */ + public function getEFileName($extension = 'pdf') + { + return ctrans("texts.e_invoice"). "_" . $this->numberFormatter().'.'.$extension; + } + public function numberFormatter() { $number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);