feat(emails): implemented sending invoice, estimates and payments as attachements

This commit is contained in:
Sebastian Cretu
2021-03-02 21:49:03 +01:00
parent 1932c5a75e
commit 2b78aacc83
15 changed files with 47 additions and 75 deletions

View File

@ -13,17 +13,15 @@ class SendEstimateMail extends Mailable
use Queueable, SerializesModels; use Queueable, SerializesModels;
public $data = []; public $data = [];
public $pdfData;
/** /**
* Create a new message instance. * Create a new message instance.
* *
* @return void * @return void
*/ */
public function __construct($data, $pdfData) public function __construct($data)
{ {
$this->data = $data; $this->data = $data;
$this->pdfData = $pdfData;
} }
/** /**
@ -42,22 +40,15 @@ class SendEstimateMail extends Mailable
'mailable_id' => $this->data['estimate']['id'] 'mailable_id' => $this->data['estimate']['id']
]); ]);
<<<<<<< HEAD $mailContent = $this->from($this->data['from'], config('mail.from.name'))
$mailContent = $this->from($this->data['from'])
->subject($this->data['subject']) ->subject($this->data['subject'])
->markdown('emails.send.estimate', ['data', $this->data]); ->markdown('emails.send.estimate', ['data', $this->data]);
=======
return $this->from($this->data['from'], config('mail.from.name'))
->subject($this->data['subject'])
->markdown('emails.send.estimate', ['data', $this->data]);
>>>>>>> master
if ($this->pdfData) { if ($this->data['attach']['data'])
$mailContent->attachData( $mailContent->attachData(
$this->pdfData->output(), $this->data['attach']['data']->output(),
$this->data['estimate']['estimate_number'] . '.pdf' $this->data['estimate']['estimate_number'] . '.pdf'
); );
}
return $mailContent; return $mailContent;
} }

View File

@ -14,17 +14,15 @@ class SendInvoiceMail extends Mailable
use Queueable, SerializesModels; use Queueable, SerializesModels;
public $data = []; public $data = [];
public $pdfData;
/** /**
* Create a new message instance. * Create a new message instance.
* *
* @return void * @return void
*/ */
public function __construct($data, $pdfData) public function __construct($data)
{ {
$this->data = $data; $this->data = $data;
$this->pdfData = $pdfData;
} }
/** /**
@ -43,23 +41,16 @@ class SendInvoiceMail extends Mailable
'mailable_id' => $this->data['invoice']['id'] 'mailable_id' => $this->data['invoice']['id']
]); ]);
$mailContent = $this->from($this->data['from']) $mailContent = $this->from($this->data['from'], config('mail.from.name'))
->subject($this->data['subject']) ->subject($this->data['subject'])
->markdown('emails.send.invoice', ['data', $this->data]); ->markdown('emails.send.invoice', ['data', $this->data]);
<<<<<<< HEAD if ($this->data['attach']['data'])
if ($this->pdfData) {
$mailContent->attachData( $mailContent->attachData(
$this->pdfData->output(), $this->data['attach']['data']->output(),
$this->data['invoice']['invoice_number'] . '.pdf' $this->data['invoice']['invoice_number'] . '.pdf'
); );
}
return $mailContent; return $mailContent;
=======
return $this->from($this->data['from'], config('mail.from.name'))
->subject($this->data['subject'])
->markdown('emails.send.invoice', ['data', $this->data]);
>>>>>>> master
} }
} }

View File

@ -14,17 +14,15 @@ class SendPaymentMail extends Mailable
use Queueable, SerializesModels; use Queueable, SerializesModels;
public $data = []; public $data = [];
public $pdfData;
/** /**
* Create a new message instance. * Create a new message instance.
* *
* @return void * @return void
*/ */
public function __construct($data, $pdfData) public function __construct($data)
{ {
$this->data = $data; $this->data = $data;
$this->pdfData = $pdfData;
} }
/** /**
@ -43,24 +41,16 @@ class SendPaymentMail extends Mailable
'mailable_id' => $this->data['payment']['id'] 'mailable_id' => $this->data['payment']['id']
]); ]);
<<<<<<< HEAD $mailContent = $this->from($this->data['from'], config('mail.from.name'))
$mailContent = $this->from($this->data['from'])
->subject($this->data['subject']) ->subject($this->data['subject'])
->markdown('emails.send.payment', ['data', $this->data]); ->markdown('emails.send.payment', ['data', $this->data]);
if ($this->pdfData) { if ($this->data['attach']['data'])
$mailContent->attachData( $mailContent->attachData(
$this->pdfData->output(), $this->data['attach']['data']->output(),
$this->data['payment']['payment_number'] . '.pdf' $this->data['payment']['payment_number'] . '.pdf'
); );
}
return $mailContent; return $mailContent;
=======
return $this->from($this->data['from'], config('mail.from.name'))
->subject($this->data['subject'])
->markdown('emails.send.payment', ['data', $this->data]);
>>>>>>> master
} }
} }

View File

@ -379,9 +379,9 @@ class Estimate extends Model implements HasMedia
$data['user'] = $this->user->toArray(); $data['user'] = $this->user->toArray();
$data['company'] = $this->company->toArray(); $data['company'] = $this->company->toArray();
$data['body'] = $this->getEmailBody($data['body']); $data['body'] = $this->getEmailBody($data['body']);
$pdfData = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null; $data['attach']['data'] = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null;
\Mail::to($data['to'])->send(new SendEstimateMail($data, $pdfData)); \Mail::to($data['to'])->send(new SendEstimateMail($data));
if ($this->status == Estimate::STATUS_DRAFT) { if ($this->status == Estimate::STATUS_DRAFT) {
$this->status = Estimate::STATUS_SENT; $this->status = Estimate::STATUS_SENT;

View File

@ -429,7 +429,7 @@ class Invoice extends Model implements HasMedia
$data['user'] = $this->user->toArray(); $data['user'] = $this->user->toArray();
$data['company'] = Company::find($this->company_id); $data['company'] = Company::find($this->company_id);
$data['body'] = $this->getEmailBody($data['body']); $data['body'] = $this->getEmailBody($data['body']);
$pdfData = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null; $data['attach']['data'] = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null;
if ($this->status == Invoice::STATUS_DRAFT) { if ($this->status == Invoice::STATUS_DRAFT) {
$this->status = Invoice::STATUS_SENT; $this->status = Invoice::STATUS_SENT;
@ -437,7 +437,7 @@ class Invoice extends Model implements HasMedia
$this->save(); $this->save();
} }
\Mail::to($data['to'])->send(new SendInvoiceMail($data, $pdfData)); \Mail::to($data['to'])->send(new SendInvoiceMail($data));
return [ return [
'success' => true 'success' => true

View File

@ -124,9 +124,9 @@ class Payment extends Model implements HasMedia
$data['user'] = $this->user->toArray(); $data['user'] = $this->user->toArray();
$data['company'] = Company::find($this->company_id); $data['company'] = Company::find($this->company_id);
$data['body'] = $this->getEmailBody($data['body']); $data['body'] = $this->getEmailBody($data['body']);
$pdfData = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null; $data['attach']['data'] = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null;
\Mail::to($data['to'])->send(new SendPaymentMail($data, $pdfData)); \Mail::to($data['to'])->send(new SendPaymentMail($data));
return [ return [
'success' => true 'success' => true

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,24 +1,24 @@
/*! /*!
* tiptap v1.29.6 * tiptap v1.30.0
* (c) 2020 überdosis GbR (limited liability) * (c) 2021 überdosis GbR (limited liability)
* @license MIT * @license MIT
*/ */
/*! /*!
* tiptap-commands v1.14.6 * tiptap-commands v1.15.0
* (c) 2020 überdosis GbR (limited liability) * (c) 2021 überdosis GbR (limited liability)
* @license MIT * @license MIT
*/ */
/*! /*!
* tiptap-extensions v1.33.1 * tiptap-extensions v1.33.2
* (c) 2020 überdosis GbR (limited liability) * (c) 2021 überdosis GbR (limited liability)
* @license MIT * @license MIT
*/ */
/*! /*!
* tiptap-utils v1.10.4 * tiptap-utils v1.11.0
* (c) 2020 überdosis GbR (limited liability) * (c) 2021 überdosis GbR (limited liability)
* @license MIT * @license MIT
*/ */
@ -88,8 +88,8 @@
*/ */
/*! /*!
* vue-i18n v8.22.4 * vue-i18n v8.22.2
* (c) 2021 kazuya kawaguchi * (c) 2020 kazuya kawaguchi
* Released under the MIT License. * Released under the MIT License.
*/ */
@ -100,8 +100,8 @@
*/ */
/*! /*!
* vuex v3.6.2 * vuex v3.6.0
* (c) 2021 Evan You * (c) 2020 Evan You
* @license MIT * @license MIT
*/ */

View File

@ -1,4 +1,4 @@
{ {
"/assets/js/app.js": "/assets/js/app.js?id=55c4ce4eeeff3bbd8033", "/assets/js/app.js": "/assets/js/app.js?id=8fb7348f2257eedcb3e8",
"/assets/css/crater.css": "/assets/css/crater.css?id=d0c099a892a9295e5c6d" "/assets/css/crater.css": "/assets/css/crater.css?id=7a822f915d7e413148f6"
} }

View File

@ -746,7 +746,7 @@
"autogenerate_invoice_number": "Auto-generate Invoice Number", "autogenerate_invoice_number": "Auto-generate Invoice Number",
"invoice_setting_description": "Disable this, If you don't wish to auto-generate invoice numbers each time you create a new invoice.", "invoice_setting_description": "Disable this, If you don't wish to auto-generate invoice numbers each time you create a new invoice.",
"invoice_email_attachment": "Send invoices as attachments", "invoice_email_attachment": "Send invoices as attachments",
"invoice_email_attachment_setting_description": "Enable this if you want to send invoices as email attachment.", "invoice_email_attachment_setting_description": "Enable this if you want to send invoices as email attachment. Please note that 'View Invoice' button in emails will not be displayed anymore when enabled.",
"enter_invoice_prefix": "Enter invoice prefix", "enter_invoice_prefix": "Enter invoice prefix",
"terms_and_conditions": "Terms and Conditions", "terms_and_conditions": "Terms and Conditions",
"company_address_format": "Company Address Format", "company_address_format": "Company Address Format",
@ -762,7 +762,7 @@
"autogenerate_estimate_number": "Auto-generate Estimate Number", "autogenerate_estimate_number": "Auto-generate Estimate Number",
"estimate_setting_description": "Disable this, If you don't wish to auto-generate estimate numbers each time you create a new estimate.", "estimate_setting_description": "Disable this, If you don't wish to auto-generate estimate numbers each time you create a new estimate.",
"estimate_email_attachment": "Send estimates as attachments", "estimate_email_attachment": "Send estimates as attachments",
"estimate_email_attachment_setting_description": "Enable this if you want to send the estimates as an email attachment.", "estimate_email_attachment_setting_description": "Enable this if you want to send the estimates as an email attachment. Please note that 'View Estimate' button in emails will not be displayed anymore when enabled.",
"enter_estimate_prefix": "Enter estmiate prefix", "enter_estimate_prefix": "Enter estmiate prefix",
"estimate_setting_updated": "Estimate Setting updated successfully", "estimate_setting_updated": "Estimate Setting updated successfully",
"company_address_format": "Company Address Format", "company_address_format": "Company Address Format",
@ -778,7 +778,7 @@
"autogenerate_payment_number": "Auto-generate Payment Number", "autogenerate_payment_number": "Auto-generate Payment Number",
"payment_setting_description": "Disable this, If you don't wish to auto-generate payment numbers each time you create a new payment.", "payment_setting_description": "Disable this, If you don't wish to auto-generate payment numbers each time you create a new payment.",
"payment_email_attachment": "Send payments as attachments", "payment_email_attachment": "Send payments as attachments",
"payment_email_attachment_setting_description": "Enable this if you want to send the payment receipts as an email attachment.", "payment_email_attachment_setting_description": "Enable this if you want to send the payment receipts as an email attachment. Please note that 'View Payment' button in emails will not be displayed anymore when enabled.",
"enter_payment_prefix": "Enter Payment Prefix", "enter_payment_prefix": "Enter Payment Prefix",
"payment_setting_updated": "Payment Setting updated successfully", "payment_setting_updated": "Payment Setting updated successfully",
"payment_modes": "Payment Modes", "payment_modes": "Payment Modes",

View File

@ -216,9 +216,9 @@ export default {
this.payment_email_attachment = val ? val.payment_email_attachment : '' this.payment_email_attachment = val ? val.payment_email_attachment : ''
if (this.payment_email_attachment === 'YES') { if (this.payment_email_attachment === 'YES') {
this.payment_email_attachment = true this.paymentAsAttachment = true
} else { } else {
this.payment_email_attachment = false this.paymentAsAttachment = false
} }
}, },
}, },

View File

@ -17,7 +17,7 @@
@slot('subcopy') @slot('subcopy')
@component('mail::subcopy') @component('mail::subcopy')
{!! $data['body'] !!} {!! $data['body'] !!}
@if(!$pdfData) @if(!$data['attach']['data'])
@component('mail::button', ['url' => url('/customer/estimates/pdf/'.$data['estimate']['unique_hash'])]) @component('mail::button', ['url' => url('/customer/estimates/pdf/'.$data['estimate']['unique_hash'])])
View Estimate View Estimate
@endcomponent @endcomponent

View File

@ -17,7 +17,7 @@
@slot('subcopy') @slot('subcopy')
@component('mail::subcopy') @component('mail::subcopy')
{!! $data['body'] !!} {!! $data['body'] !!}
@if(!$pdfData) @if(!$data['attach']['data'])
@component('mail::button', ['url' => url('/customer/invoices/pdf/'.$data['invoice']['unique_hash'])]) @component('mail::button', ['url' => url('/customer/invoices/pdf/'.$data['invoice']['unique_hash'])])
View Invoice View Invoice
@endcomponent @endcomponent

View File

@ -17,7 +17,7 @@
@slot('subcopy') @slot('subcopy')
@component('mail::subcopy') @component('mail::subcopy')
{!! $data['body'] !!} {!! $data['body'] !!}
@if(!$pdfData) @if(!$data['attach']['data'])
@component('mail::button', ['url' => url('/payments/pdf/'.$data['payment']['unique_hash'])]) @component('mail::button', ['url' => url('/payments/pdf/'.$data['payment']['unique_hash'])])
View Payment View Payment
@endcomponent @endcomponent