diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 6036a93b3753..4747146dbd65 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -263,6 +263,8 @@ class AccountController extends \BaseController $account->invoice_number_counter = Input::get('invoice_number_counter'); $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'); diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 28a04b3cbaf9..6d6598842256 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -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); + } + } + } } diff --git a/app/database/migrations/2015_03_15_174122_add_pdf_email_attachment_option.php b/app/database/migrations/2015_03_15_174122_add_pdf_email_attachment_option.php new file mode 100644 index 000000000000..de89c6475a19 --- /dev/null +++ b/app/database/migrations/2015_03_15_174122_add_pdf_email_attachment_option.php @@ -0,0 +1,34 @@ +smallInteger('pdf_email_attachment')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('accounts', function($table) + { + $table->dropColumn('pdf_email_attachment'); + }); + } + +} diff --git a/app/lang/da/texts.php b/app/lang/da/texts.php index 9df8d9e79d82..e52e94cf3e3a 100644 --- a/app/lang/da/texts.php +++ b/app/lang/da/texts.php @@ -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', diff --git a/app/lang/de/texts.php b/app/lang/de/texts.php index 87de74960d85..7260f383be13 100644 --- a/app/lang/de/texts.php +++ b/app/lang/de/texts.php @@ -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', diff --git a/app/lang/en/texts.php b/app/lang/en/texts.php index 50727cfdd6c2..3f00ff7b80ee 100644 --- a/app/lang/en/texts.php +++ b/app/lang/en/texts.php @@ -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', diff --git a/app/lang/es/texts.php b/app/lang/es/texts.php index 5d5a04863c32..2bc9984cd7cc 100644 --- a/app/lang/es/texts.php +++ b/app/lang/es/texts.php @@ -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', diff --git a/app/lang/fr/texts.php b/app/lang/fr/texts.php index 9c78aa59e0ff..011c3793f1be 100644 --- a/app/lang/fr/texts.php +++ b/app/lang/fr/texts.php @@ -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', diff --git a/app/lang/it/texts.php b/app/lang/it/texts.php index b3c96be0a247..0c9123b8abb2 100644 --- a/app/lang/it/texts.php +++ b/app/lang/it/texts.php @@ -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', diff --git a/app/lang/lt/texts.php b/app/lang/lt/texts.php index 81cfdee8f893..79811bf4f1da 100644 --- a/app/lang/lt/texts.php +++ b/app/lang/lt/texts.php @@ -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', diff --git a/app/lang/nb_NO/texts.php b/app/lang/nb_NO/texts.php index 2d066fc016d7..a978a7b3ec75 100644 --- a/app/lang/nb_NO/texts.php +++ b/app/lang/nb_NO/texts.php @@ -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', diff --git a/app/lang/nl/texts.php b/app/lang/nl/texts.php index 45304e64b143..c335331e7b13 100644 --- a/app/lang/nl/texts.php +++ b/app/lang/nl/texts.php @@ -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', diff --git a/app/lang/pt_BR/texts.php b/app/lang/pt_BR/texts.php index 47ff16ff5dd6..bfafbed7cc9f 100644 --- a/app/lang/pt_BR/texts.php +++ b/app/lang/pt_BR/texts.php @@ -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', diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 09e1f887d34d..8aca78ea0c5e 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -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; diff --git a/app/ninja/mailers/ContactMailer.php b/app/ninja/mailers/ContactMailer.php index 0a262aecba08..fe91c8e4b848 100755 --- a/app/ninja/mailers/ContactMailer.php +++ b/app/ninja/mailers/ContactMailer.php @@ -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); diff --git a/app/ninja/mailers/Mailer.php b/app/ninja/mailers/Mailer.php index 16264d91cc55..20b7d5b11f7a 100755 --- a/app/ninja/mailers/Mailer.php +++ b/app/ninja/mailers/Mailer.php @@ -2,6 +2,7 @@ use Mail; use Utils; +use Invoice; class Mailer { @@ -12,13 +13,27 @@ 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 if (Utils::isNinja() && $toEmail != CONTACT_EMAIL) { $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); diff --git a/app/views/accounts/invoice_settings.blade.php b/app/views/accounts/invoice_settings.blade.php index bf789be9be32..beb4fef9e022 100644 --- a/app/views/accounts/invoice_settings.blade.php +++ b/app/views/accounts/invoice_settings.blade.php @@ -42,6 +42,10 @@ ->append(Former::checkbox('share_counter')->raw()->onclick('setQuoteNumberEnabled()') . ' ' . trans('texts.share_invoice_counter')) }}

 

+ {{ Former::legend('email_settings') }} + {{ Former::checkbox('pdf_email_attachment') }} +

 

+ @if (Auth::user()->isPro()) {{ Former::actions( Button::lg_success_submit(trans('texts.save'))->append_with_icon('floppy-disk') ) }} @else diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index c94c0930dfbd..9013969b43d3 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -718,17 +718,23 @@ } function onEmailClick() { - if (confirm('{{ trans("texts.confirm_email_$entityType") }}')) { + if (confirm('{{ trans("texts.confirm_email_$entityType") }}')) { submitAction('email'); } } function onSaveClick() { if (model.invoice().is_recurring()) { - if (confirm('{{ trans("texts.confirm_recurring_email_$entityType") }}')) { + if (confirm('{{ trans("texts.confirm_recurring_email_$entityType") }}')) { submitAction(''); - } + } } else { + var invoice = createInvoiceModel(); + var design = getDesignJavascript(); + if (!design) return; + var doc = generatePDF(invoice, design, true); + + $('form.form-horizontal.warn-on-exit').append(''); submitAction(''); } } @@ -739,7 +745,7 @@ return; } $('#action').val(value); - $('#submitButton').click(); + $('#submitButton').click(); } function isSaveValid() {