mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add option to attach documents to invoice email
This commit is contained in:
parent
942f543bbb
commit
f7d8f819b6
@ -651,6 +651,7 @@ class AccountController extends BaseController
|
||||
$account->subdomain = $subdomain;
|
||||
$account->iframe_url = $iframeURL;
|
||||
$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');
|
||||
|
||||
if (Utils::isNinja()) {
|
||||
|
@ -432,6 +432,7 @@ if (!defined('CONTACT_EMAIL')) {
|
||||
define('MAX_LOGO_FILE_SIZE', 200); // KB
|
||||
define('MAX_FAILED_LOGINS', 10);
|
||||
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('DEFAULT_FONT_SIZE', 9);
|
||||
define('DEFAULT_HEADER_FONT', 1);// Roboto
|
||||
|
@ -60,8 +60,25 @@ class ContactMailer extends Mailer
|
||||
$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) {
|
||||
$response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString);
|
||||
$response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString, $documentStrings);
|
||||
if ($response === true) {
|
||||
$sent = true;
|
||||
}
|
||||
@ -80,7 +97,7 @@ class ContactMailer extends Mailer
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function sendInvitation($invitation, $invoice, $body, $subject, $pdfString)
|
||||
private function sendInvitation($invitation, $invoice, $body, $subject, $pdfString, $documentStrings)
|
||||
{
|
||||
$client = $invoice->client;
|
||||
$account = $invoice->account;
|
||||
@ -127,6 +144,7 @@ class ContactMailer extends Mailer
|
||||
'account' => $account,
|
||||
'client' => $client,
|
||||
'invoice' => $invoice,
|
||||
'documents' => $documentStrings,
|
||||
];
|
||||
|
||||
if ($account->attatchPDF()) {
|
||||
|
@ -44,6 +44,13 @@ class Mailer
|
||||
if (!empty($data['pdfString']) && !empty($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);
|
||||
|
@ -16,6 +16,7 @@ class AddDocuments extends Migration {
|
||||
$table->unsignedInteger('logo_height');
|
||||
$table->unsignedInteger('logo_size');
|
||||
$table->boolean('invoice_embed_documents')->default(1);
|
||||
$table->boolean('document_email_attachment')->default(1);
|
||||
});
|
||||
|
||||
DB::table('accounts')->update(array('logo' => ''));
|
||||
|
@ -1102,6 +1102,7 @@ $LANG = array(
|
||||
'document_upload_message' => 'Drop files here or click to upload.',
|
||||
'invoice_embed_documents' => 'Embed Documents',
|
||||
'invoice_embed_documents_help' => 'Include attached images in the invoice.',
|
||||
'document_email_attachment' => 'Attach Documents',
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -19,6 +19,7 @@
|
||||
])->addClass('warn-on-exit') !!}
|
||||
{{ Former::populate($account) }}
|
||||
{{ 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)) }}
|
||||
|
||||
<div class="panel panel-default">
|
||||
@ -27,6 +28,7 @@
|
||||
</div>
|
||||
<div class="panel-body form-padding-right">
|
||||
{!! Former::checkbox('pdf_email_attachment')->text(trans('texts.enable')) !!}
|
||||
{!! Former::checkbox('document_email_attachment')->text(trans('texts.enable')) !!}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user