Add option to attach documents to invoice email

This commit is contained in:
Joshua Dwire 2016-03-23 19:20:08 -04:00
parent 942f543bbb
commit f7d8f819b6
7 changed files with 34 additions and 3 deletions

View File

@ -651,6 +651,7 @@ class AccountController extends BaseController
$account->subdomain = $subdomain; $account->subdomain = $subdomain;
$account->iframe_url = $iframeURL; $account->iframe_url = $iframeURL;
$account->pdf_email_attachment = Input::get('pdf_email_attachment') ? true : false; $account->pdf_email_attachment = Input::get('pdf_email_attachment') ? true : false;
$account->document_email_attachment = Input::get('document_email_attachment') ? true : false;
$account->email_design_id = Input::get('email_design_id'); $account->email_design_id = Input::get('email_design_id');
if (Utils::isNinja()) { if (Utils::isNinja()) {

View File

@ -432,6 +432,7 @@ if (!defined('CONTACT_EMAIL')) {
define('MAX_LOGO_FILE_SIZE', 200); // KB define('MAX_LOGO_FILE_SIZE', 200); // KB
define('MAX_FAILED_LOGINS', 10); define('MAX_FAILED_LOGINS', 10);
define('MAX_DOCUMENT_SIZE', env('MAX_DOCUMENT_SIZE', 10000));// KB define('MAX_DOCUMENT_SIZE', env('MAX_DOCUMENT_SIZE', 10000));// KB
define('MAX_EMAIL_DOCUMENTS_SIZE', env('MAX_EMAIL_DOCUMENTS_SIZE', 10000));// Total KB
define('DOCUMENT_PREVIEW_SIZE', env('DOCUMENT_PREVIEW_SIZE', 300));// pixels define('DOCUMENT_PREVIEW_SIZE', env('DOCUMENT_PREVIEW_SIZE', 300));// pixels
define('DEFAULT_FONT_SIZE', 9); define('DEFAULT_FONT_SIZE', 9);
define('DEFAULT_HEADER_FONT', 1);// Roboto define('DEFAULT_HEADER_FONT', 1);// Roboto

View File

@ -59,9 +59,26 @@ class ContactMailer extends Mailer
if ($account->attatchPDF() && !$pdfString) { if ($account->attatchPDF() && !$pdfString) {
$pdfString = $invoice->getPDFString(); $pdfString = $invoice->getPDFString();
} }
$documentStrings = array();
if ($account->document_email_attachment && !empty($invoice->documents)) {
$documents = $invoice->documents->sortBy('size');
$size = 0;
$maxSize = MAX_EMAIL_DOCUMENTS_SIZE * 1000;
foreach($documents as $document){
$size += $document->size;
if($size > $maxSize)break;
$documentStrings[] = array(
'name' => $document->name,
'data' => $document->getRaw(),
);
}
}
foreach ($invoice->invitations as $invitation) { foreach ($invoice->invitations as $invitation) {
$response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString); $response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString, $documentStrings);
if ($response === true) { if ($response === true) {
$sent = true; $sent = true;
} }
@ -80,7 +97,7 @@ class ContactMailer extends Mailer
return $response; return $response;
} }
private function sendInvitation($invitation, $invoice, $body, $subject, $pdfString) private function sendInvitation($invitation, $invoice, $body, $subject, $pdfString, $documentStrings)
{ {
$client = $invoice->client; $client = $invoice->client;
$account = $invoice->account; $account = $invoice->account;
@ -127,6 +144,7 @@ class ContactMailer extends Mailer
'account' => $account, 'account' => $account,
'client' => $client, 'client' => $client,
'invoice' => $invoice, 'invoice' => $invoice,
'documents' => $documentStrings,
]; ];
if ($account->attatchPDF()) { if ($account->attatchPDF()) {

View File

@ -44,6 +44,13 @@ class Mailer
if (!empty($data['pdfString']) && !empty($data['pdfFileName'])) { if (!empty($data['pdfString']) && !empty($data['pdfFileName'])) {
$message->attachData($data['pdfString'], $data['pdfFileName']); $message->attachData($data['pdfString'], $data['pdfFileName']);
} }
// Attach documents to the email
if(!empty($data['documents'])){
foreach($data['documents'] as $document){
$message->attachData($document['data'], $document['name']);
}
}
}); });
return $this->handleSuccess($response, $data); return $this->handleSuccess($response, $data);

View File

@ -16,6 +16,7 @@ class AddDocuments extends Migration {
$table->unsignedInteger('logo_height'); $table->unsignedInteger('logo_height');
$table->unsignedInteger('logo_size'); $table->unsignedInteger('logo_size');
$table->boolean('invoice_embed_documents')->default(1); $table->boolean('invoice_embed_documents')->default(1);
$table->boolean('document_email_attachment')->default(1);
}); });
DB::table('accounts')->update(array('logo' => '')); DB::table('accounts')->update(array('logo' => ''));

View File

@ -1101,7 +1101,8 @@ $LANG = array(
'invoice_documents' => 'Attached Documents', 'invoice_documents' => 'Attached Documents',
'document_upload_message' => 'Drop files here or click to upload.', 'document_upload_message' => 'Drop files here or click to upload.',
'invoice_embed_documents' => 'Embed Documents', 'invoice_embed_documents' => 'Embed Documents',
'invoice_embed_documents_help' => 'Include attached images in the invoice.', 'invoice_embed_documents_help' => 'Include attached images in the invoice.',
'document_email_attachment' => 'Attach Documents',
); );
return $LANG; return $LANG;

View File

@ -19,6 +19,7 @@
])->addClass('warn-on-exit') !!} ])->addClass('warn-on-exit') !!}
{{ Former::populate($account) }} {{ Former::populate($account) }}
{{ Former::populateField('pdf_email_attachment', intval($account->pdf_email_attachment)) }} {{ Former::populateField('pdf_email_attachment', intval($account->pdf_email_attachment)) }}
{{ Former::populateField('document_email_attachment', intval($account->document_email_attachment)) }}
{{ Former::populateField('enable_email_markup', intval($account->enable_email_markup)) }} {{ Former::populateField('enable_email_markup', intval($account->enable_email_markup)) }}
<div class="panel panel-default"> <div class="panel panel-default">
@ -27,6 +28,7 @@
</div> </div>
<div class="panel-body form-padding-right"> <div class="panel-body form-padding-right">
{!! Former::checkbox('pdf_email_attachment')->text(trans('texts.enable')) !!} {!! Former::checkbox('pdf_email_attachment')->text(trans('texts.enable')) !!}
{!! Former::checkbox('document_email_attachment')->text(trans('texts.enable')) !!}
&nbsp; &nbsp;