mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 19:14:40 -04:00
Added ability to attach invoice as pdf to email templates.
Added flag in setting to turn pdf attachments on/off. Client side generated pdf is uploaded on send email action. Backend will check for actuall pdf. Added dummy strings to all languages. Added migration.
This commit is contained in:
parent
2cdf6d517a
commit
00fb18a52f
@ -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');
|
||||
}
|
||||
|
23
app/controllers/AjaxController.php
Normal file
23
app/controllers/AjaxController.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class AjaxController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function pdfupload()
|
||||
{
|
||||
$uploadsDir = storage_path().'/pdfcache/';
|
||||
if ($_FILES['fileblob']['error'] === UPLOAD_ERR_OK && $_FILES['fileblob']['type'] === 'application/pdf') {
|
||||
$tmpName = $_FILES['fileblob']['tmp_name'];
|
||||
$name = $_POST['filename'];
|
||||
|
||||
$finfo = new finfo(FILEINFO_MIME);
|
||||
if ($finfo->file($tmpName) === 'application/pdf; charset=binary') {
|
||||
move_uploaded_file($tmpName, $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);
|
||||
});
|
||||
|
@ -147,6 +147,8 @@ Route::group(array('before' => 'auth'), function() {
|
||||
Route::get('api/credits/{client_id?}', array('as'=>'api.credits', 'uses'=>'CreditController@getDatatable'));
|
||||
Route::post('credits/bulk', 'CreditController@bulk');
|
||||
|
||||
Route::post('ajax/pdfupload', 'AjaxController@pdfupload');
|
||||
|
||||
//Route::resource('timesheets', 'TimesheetController');
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
|
@ -719,7 +719,25 @@
|
||||
|
||||
function onEmailClick() {
|
||||
if (confirm('{{ trans("texts.confirm_email_$entityType") }}')) {
|
||||
submitAction('email');
|
||||
var invoice = createInvoiceModel();
|
||||
var design = getDesignJavascript();
|
||||
if (!design) return;
|
||||
var doc = generatePDF(invoice, design, true);
|
||||
|
||||
var formdata = new FormData();
|
||||
formdata.append('filename', 'cache-' + invoice.public_id + '.pdf');
|
||||
formdata.append('fileblob', doc.output('blob'));
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '{{ URL::to("ajax/pdfupload") }}',
|
||||
data: formdata,
|
||||
processData: false,
|
||||
contentType: false
|
||||
}).done(function( data ) {
|
||||
submitAction('email');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user