Merge pull request #407 from sebastiancretu/send_inv_est_pay_as_attachment

Send invoices, estimates and payments as attachments
This commit is contained in:
Mohit Panjwani
2021-03-22 12:06:06 +05:30
committed by GitHub
19 changed files with 207 additions and 21 deletions

View File

@ -379,6 +379,7 @@ class Estimate extends Model implements HasMedia
$data['user'] = $this->user->toArray();
$data['company'] = $this->company->toArray();
$data['body'] = $this->getEmailBody($data['body']);
$data['attach']['data'] = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null;
\Mail::to($data['to'])->send(new SendEstimateMail($data));
@ -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());

View File

@ -429,6 +429,7 @@ class Invoice extends Model implements HasMedia
$data['user'] = $this->user->toArray();
$data['company'] = Company::find($this->company_id);
$data['body'] = $this->getEmailBody($data['body']);
$data['attach']['data'] = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null;
if ($this->status == Invoice::STATUS_DRAFT) {
$this->status = Invoice::STATUS_SENT;
@ -526,6 +527,17 @@ class Invoice extends Model implements HasMedia
return PDF::loadView('app.pdf.invoice.' . $invoiceTemplate->view);
}
public function getEmailAttachmentSetting()
{
$invoiceAsAttachment = CompanySetting::getSetting('invoice_email_attachment', $this->company_id);
if($invoiceAsAttachment == 'NO') {
return false;
}
return true;
}
public function getCompanyAddress()
{
$format = CompanySetting::getSetting('invoice_company_address_format', $this->company_id);

View File

@ -124,6 +124,7 @@ class Payment extends Model implements HasMedia
$data['user'] = $this->user->toArray();
$data['company'] = Company::find($this->company_id);
$data['body'] = $this->getEmailBody($data['body']);
$data['attach']['data'] = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null;
\Mail::to($data['to'])->send(new SendPaymentMail($data));
@ -400,6 +401,17 @@ class Payment extends Model implements HasMedia
return $this->getFormattedString($format);
}
public function getEmailAttachmentSetting()
{
$paymentAsAttachment = CompanySetting::getSetting('payment_email_attachment', $this->company_id);
if($paymentAsAttachment == 'NO') {
return false;
}
return true;
}
public function getNotes()
{
return $this->getFormattedString($this->notes);