mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 19:51:09 -04:00
Merge pull request #407 from sebastiancretu/send_inv_est_pay_as_attachment
Send invoices, estimates and payments as attachments
This commit is contained in:
@ -40,9 +40,16 @@ class SendEstimateMail extends Mailable
|
||||
'mailable_id' => $this->data['estimate']['id']
|
||||
]);
|
||||
|
||||
return $this->from($this->data['from'], config('mail.from.name'))
|
||||
$mailContent = $this->from($this->data['from'], config('mail.from.name'))
|
||||
->subject($this->data['subject'])
|
||||
->markdown('emails.send.estimate', ['data', $this->data]);
|
||||
|
||||
if ($this->data['attach']['data'])
|
||||
$mailContent->attachData(
|
||||
$this->data['attach']['data']->output(),
|
||||
$this->data['estimate']['estimate_number'] . '.pdf'
|
||||
);
|
||||
|
||||
return $mailContent;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,9 +40,17 @@ class SendInvoiceMail extends Mailable
|
||||
'mailable_type' => Invoice::class,
|
||||
'mailable_id' => $this->data['invoice']['id']
|
||||
]);
|
||||
|
||||
$mailContent = $this->from($this->data['from'], config('mail.from.name'))
|
||||
->subject($this->data['subject'])
|
||||
->markdown('emails.send.invoice', ['data', $this->data]);
|
||||
|
||||
return $this->from($this->data['from'], config('mail.from.name'))
|
||||
->subject($this->data['subject'])
|
||||
->markdown('emails.send.invoice', ['data', $this->data]);
|
||||
if ($this->data['attach']['data'])
|
||||
$mailContent->attachData(
|
||||
$this->data['attach']['data']->output(),
|
||||
$this->data['invoice']['invoice_number'] . '.pdf'
|
||||
);
|
||||
|
||||
return $mailContent;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,9 +41,16 @@ class SendPaymentMail extends Mailable
|
||||
'mailable_id' => $this->data['payment']['id']
|
||||
]);
|
||||
|
||||
return $this->from($this->data['from'], config('mail.from.name'))
|
||||
$mailContent = $this->from($this->data['from'], config('mail.from.name'))
|
||||
->subject($this->data['subject'])
|
||||
->markdown('emails.send.payment', ['data', $this->data]);
|
||||
|
||||
if ($this->data['attach']['data'])
|
||||
$mailContent->attachData(
|
||||
$this->data['attach']['data']->output(),
|
||||
$this->data['payment']['payment_number'] . '.pdf'
|
||||
);
|
||||
|
||||
return $mailContent;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user