mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-21 17:20:54 -04:00
Merge pull request #260 from Destination-Design/feature_email_pdf_attachment
Feature: Added ability to attach invoice as pdf to email templates.
This commit is contained in:
commit
8271330700
@ -264,6 +264,8 @@ class AccountController extends \BaseController
|
||||
$account->quote_number_prefix = Input::get('quote_number_prefix');
|
||||
$account->share_counter = Input::get('share_counter') ? true : false;
|
||||
|
||||
$account->pdf_email_attachment = Input::get('pdf_email_attachment') ? true : false;
|
||||
|
||||
if (!$account->share_counter) {
|
||||
$account->quote_number_counter = Input::get('quote_number_counter');
|
||||
}
|
||||
|
@ -397,6 +397,10 @@ class InvoiceController extends \BaseController
|
||||
Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url);
|
||||
}
|
||||
|
||||
if (!empty(Input::get('pdfupload')) && strpos(Input::get('pdfupload'), 'data:application/pdf;base64,') === 0) {
|
||||
$this->storePDF(Input::get('pdfupload'), $input->invoice->public_id);
|
||||
}
|
||||
|
||||
if ($action == 'clone') {
|
||||
return $this->cloneInvoice($publicId);
|
||||
} elseif ($action == 'convert') {
|
||||
@ -539,4 +543,18 @@ class InvoiceController extends \BaseController
|
||||
|
||||
return View::make('invoices.history', $data);
|
||||
}
|
||||
|
||||
private function storePDF($encodedString, $public_id)
|
||||
{
|
||||
$uploadsDir = storage_path().'/pdfcache/';
|
||||
$encodedString = str_replace('data:application/pdf;base64,', '', $encodedString);
|
||||
$name = 'cache-'.$public_id.'.pdf';
|
||||
|
||||
if (file_put_contents($uploadsDir.$name, base64_decode($encodedString)) !== false) {
|
||||
$finfo = new finfo(FILEINFO_MIME);
|
||||
if ($finfo->file($uploadsDir.$name) !== 'application/pdf; charset=binary') {
|
||||
unlink($uploadsDir.$name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddPdfEmailAttachmentOption extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('accounts', function($table)
|
||||
{
|
||||
$table->smallInteger('pdf_email_attachment')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('accounts', function($table)
|
||||
{
|
||||
$table->dropColumn('pdf_email_attachment');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -208,6 +208,8 @@ return array(
|
||||
'import_to' => 'Importer til',
|
||||
'client_will_create' => 'Klient vil blive oprettet',
|
||||
'clients_will_create' => 'Klienter vil blive oprettet',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Klient oprettet succesfuldt',
|
||||
|
@ -205,6 +205,8 @@ return array(
|
||||
'import_to' => 'Importieren nach',
|
||||
'client_will_create' => 'Kunde wird erstellt',
|
||||
'clients_will_create' => 'Kunden werden erstellt',
|
||||
'email_settings' => 'E-Mail Einstellungen',
|
||||
'pdf_email_attachment' => 'PDF an E-Mails anhängen',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Kunde erfolgreich angelegt',
|
||||
|
@ -206,6 +206,8 @@ return array(
|
||||
'import_to' => 'Import to',
|
||||
'client_will_create' => 'client will be created',
|
||||
'clients_will_create' => 'clients will be created',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Successfully created client',
|
||||
|
@ -205,6 +205,8 @@ return array(
|
||||
'import_to' => 'Importar a',
|
||||
'client_will_create' => 'cliente se creará', //What is this for, context of it's use
|
||||
'clients_will_create' => 'clientes se crearan', //What is this for, context of it's use
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'cliente creado con éxito',
|
||||
|
@ -206,6 +206,8 @@ return array(
|
||||
'import_to' => 'Importer en tant que',
|
||||
'client_will_create' => 'client sera créé',
|
||||
'clients_will_create' => 'clients seront créés',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Client créé avec succès',
|
||||
|
@ -206,6 +206,8 @@ return array(
|
||||
'import_to' => 'Importa in',
|
||||
'client_will_create' => 'il cliente sarà creato',
|
||||
'clients_will_create' => 'i clienti saranno creati',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Cliente creato con successo',
|
||||
|
@ -206,6 +206,8 @@ return array(
|
||||
'import_to' => 'Import to',
|
||||
'client_will_create' => 'client will be created',
|
||||
'clients_will_create' => 'clients will be created',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Successfully created client',
|
||||
|
@ -206,6 +206,8 @@ return array(
|
||||
'import_to' => 'Importer til',
|
||||
'client_will_create' => 'Klient vil bli opprettet',
|
||||
'clients_will_create' => 'Klienter vil bli opprettet',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Klient opprettet suksessfullt',
|
||||
|
@ -205,6 +205,8 @@ return array(
|
||||
'import_to' => 'Importeer naar',
|
||||
'client_will_create' => 'klant zal aangemaakt worden',
|
||||
'clients_will_create' => 'klanten zullen aangemaakt worden',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Klant succesvol aangemaakt',
|
||||
|
@ -204,6 +204,8 @@ return array(
|
||||
'import_to' => 'Importar para',
|
||||
'client_will_create' => 'cliente será criado',
|
||||
'clients_will_create' => 'clientes serão criados',
|
||||
'email_settings' => 'Email Settings',
|
||||
'pdf_email_attachment' => 'Attach PDF to Emails',
|
||||
|
||||
// application messages
|
||||
'created_client' => 'Cliente criado com sucesso',
|
||||
|
@ -93,7 +93,8 @@ class Invoice extends EntityModel
|
||||
'custom_value1',
|
||||
'custom_value2',
|
||||
'custom_taxes1',
|
||||
'custom_taxes2', ]);
|
||||
'custom_taxes2',
|
||||
]);
|
||||
|
||||
$this->client->setVisible([
|
||||
'name',
|
||||
@ -110,7 +111,8 @@ class Invoice extends EntityModel
|
||||
'country',
|
||||
'currency_id',
|
||||
'custom_value1',
|
||||
'custom_value2', ]);
|
||||
'custom_value2',
|
||||
]);
|
||||
|
||||
$this->account->setVisible([
|
||||
'name',
|
||||
@ -136,7 +138,9 @@ class Invoice extends EntityModel
|
||||
'hide_quantity',
|
||||
'hide_paid_to_date',
|
||||
'custom_invoice_label1',
|
||||
'custom_invoice_label2', ]);
|
||||
'custom_invoice_label2',
|
||||
'pdf_email_attachment',
|
||||
]);
|
||||
|
||||
foreach ($this->invoice_items as $invoiceItem) {
|
||||
$invoiceItem->setVisible([
|
||||
@ -145,7 +149,8 @@ class Invoice extends EntityModel
|
||||
'cost',
|
||||
'qty',
|
||||
'tax_name',
|
||||
'tax_rate', ]);
|
||||
'tax_rate',
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($this->client->contacts as $contact) {
|
||||
@ -153,7 +158,8 @@ class Invoice extends EntityModel
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'phone', ]);
|
||||
'phone',
|
||||
]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -43,6 +43,7 @@ class ContactMailer extends Mailer
|
||||
$data['body'] = str_replace(array_keys($variables), array_values($variables), $emailTemplate);
|
||||
$data['link'] = $invitation->getLink();
|
||||
$data['entityType'] = $entityType;
|
||||
$data['id'] = $invoice->getAttributes()['id'];
|
||||
|
||||
$fromEmail = $invitation->user->email;
|
||||
$this->sendTo($invitation->contact->email, $fromEmail, $accountName, $subject, $view, $data);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use Mail;
|
||||
use Utils;
|
||||
use Invoice;
|
||||
|
||||
class Mailer
|
||||
{
|
||||
@ -12,7 +13,7 @@ class Mailer
|
||||
'emails.'.$view.'_text',
|
||||
];
|
||||
|
||||
Mail::send($views, $data, function ($message) use ($toEmail, $fromEmail, $fromName, $subject) {
|
||||
Mail::send($views, $data, function ($message) use ($toEmail, $fromEmail, $fromName, $subject, $data) {
|
||||
$replyEmail = $fromEmail;
|
||||
|
||||
// http://stackoverflow.com/questions/2421234/gmail-appearing-to-ignore-reply-to
|
||||
@ -20,6 +21,20 @@ class Mailer
|
||||
$fromEmail = NINJA_FROM_EMAIL;
|
||||
}
|
||||
|
||||
if(isset($data['id'])) {
|
||||
$invoice = Invoice::find($data['id']);
|
||||
$invoice->load('account');
|
||||
$accountAttributes = $invoice->account()->getParent()->getRelations()['account']->getAttributes();
|
||||
$pdfPath = storage_path().'/pdfcache/cache-'.$invoice->getAttributes()['public_id'].'.pdf';
|
||||
|
||||
if($accountAttributes['pdf_email_attachment'] === 1 && file_exists($pdfPath)) {
|
||||
$message->attach(
|
||||
$pdfPath,
|
||||
array('as' => $accountAttributes['name'].'_'.$accountAttributes['invoice_number_prefix'].$invoice->getName().'.pdf', 'mime' => 'application/pdf')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//$message->setEncoder(\Swift_Encoding::get8BitEncoding());
|
||||
$message->to($toEmail)->from($fromEmail, $fromName)->replyTo($replyEmail, $fromName)->subject($subject);
|
||||
});
|
||||
|
@ -42,6 +42,10 @@
|
||||
->append(Former::checkbox('share_counter')->raw()->onclick('setQuoteNumberEnabled()') . ' ' . trans('texts.share_invoice_counter')) }}
|
||||
<p> </p>
|
||||
|
||||
{{ Former::legend('email_settings') }}
|
||||
{{ Former::checkbox('pdf_email_attachment') }}
|
||||
<p> </p>
|
||||
|
||||
@if (Auth::user()->isPro())
|
||||
{{ Former::actions( Button::lg_success_submit(trans('texts.save'))->append_with_icon('floppy-disk') ) }}
|
||||
@else
|
||||
|
@ -729,6 +729,12 @@
|
||||
submitAction('');
|
||||
}
|
||||
} else {
|
||||
var invoice = createInvoiceModel();
|
||||
var design = getDesignJavascript();
|
||||
if (!design) return;
|
||||
var doc = generatePDF(invoice, design, true);
|
||||
|
||||
$('form.form-horizontal.warn-on-exit').append('<input type="hidden" name="pdfupload" value="'+doc.output('datauristring')+'">');
|
||||
submitAction('');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user