1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Reworked pdf store flow from AjaxController to invoice save.

This commit is contained in:
Viktor Rennert 2015-03-18 13:20:02 +01:00
parent 00fb18a52f
commit 2a6f7e00b5
4 changed files with 26 additions and 45 deletions

View File

@ -1,23 +0,0 @@
<?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);
}
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -147,8 +147,6 @@ 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');
});

View File

@ -719,25 +719,7 @@
function onEmailClick() {
if (confirm('{{ trans("texts.confirm_email_$entityType") }}')) {
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');
});
submitAction('email');
}
}
@ -747,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('');
}
}
@ -757,7 +745,7 @@
return;
}
$('#action').val(value);
$('#submitButton').click();
$('#submitButton').click();
}
function isSaveValid() {