Minor fixes for emails

This commit is contained in:
David Bomba 2023-08-17 09:24:36 +10:00
parent f10c880ffb
commit eee79c90a2
2 changed files with 19 additions and 6 deletions

View File

@ -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)) {
$xml_string = $this->invitation->invoice->service()->getEInvoice($this->invitation->contact);
$xinvoice_filepath = $this->invitation->invoice->service()->getEInvoice($this->invitation->contact);
nlog("template {$xml_string}");
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]);
if($xml_string) {
$this->attachData($xml_string, $this->invitation->invoice->getEFileName("xml"));
}
}

View File

@ -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);