Send Invoices/Estimates/Payments as email attachments

This commit is contained in:
Sebastian Cretu
2021-02-05 20:24:56 +01:00
parent f47029ca78
commit 392f6f469b
21 changed files with 574099 additions and 47 deletions

View File

@@ -379,8 +379,9 @@ class Estimate extends Model implements HasMedia
$data['user'] = $this->user->toArray();
$data['company'] = $this->company->toArray();
$data['body'] = $this->getEmailBody($data['body']);
$pdfData = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null;
\Mail::to($data['to'])->send(new SendEstimateMail($data));
\Mail::to($data['to'])->send(new SendEstimateMail($data, $pdfData));
if ($this->status == Estimate::STATUS_DRAFT) {
$this->status = Estimate::STATUS_SENT;
@@ -468,6 +469,17 @@ class Estimate extends Model implements HasMedia
return $this->getFormattedString($this->notes);
}
public function getEmailAttachmentSetting()
{
$estimateAsAttachment = CompanySetting::getSetting('estimate_email_attachment', $this->company_id);
if($estimateAsAttachment == 'NO') {
return false;
}
return true;
}
public function getEmailBody($body)
{
$values = array_merge($this->getFieldsArray(), $this->getExtraFields());