mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 05:24:35 -04:00
Fixes for downloading archived PDFs
This commit is contained in:
parent
a6678197eb
commit
5323458411
@ -30,6 +30,7 @@ use Illuminate\Support\Facades\Storage;
|
|||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use ZipStream\Option\Archive;
|
use ZipStream\Option\Archive;
|
||||||
use ZipStream\ZipStream;
|
use ZipStream\ZipStream;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class InvoiceController extends Controller
|
class InvoiceController extends Controller
|
||||||
{
|
{
|
||||||
@ -95,7 +96,8 @@ class InvoiceController extends Controller
|
|||||||
if ($request->input('action') == 'payment') {
|
if ($request->input('action') == 'payment') {
|
||||||
return $this->makePayment((array) $transformed_ids);
|
return $this->makePayment((array) $transformed_ids);
|
||||||
} elseif ($request->input('action') == 'download') {
|
} elseif ($request->input('action') == 'download') {
|
||||||
return $this->downloadInvoicePDF((array) $transformed_ids);
|
return $this->downloadInvoices((array) $transformed_ids);
|
||||||
|
// return $this->downloadInvoicePDF((array) $transformed_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
@ -103,6 +105,25 @@ class InvoiceController extends Controller
|
|||||||
->with('message', ctrans('texts.no_action_provided'));
|
->with('message', ctrans('texts.no_action_provided'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function downloadInvoices($ids)
|
||||||
|
{
|
||||||
|
|
||||||
|
$data['invoices'] = Invoice::whereIn('id', $ids)
|
||||||
|
->whereClientId(auth()->user()->client->id)
|
||||||
|
->withTrashed()
|
||||||
|
->get();
|
||||||
|
|
||||||
|
if(count($data['invoices']) == 0)
|
||||||
|
return back()->with(['message' => ctrans('texts.no_items_selected')]);
|
||||||
|
|
||||||
|
return $this->render('invoices.download', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function download(Request $request)
|
||||||
|
{
|
||||||
|
$transformed_ids = $this->transformKeys($request->invoices);
|
||||||
|
return $this->downloadInvoicePDF((array) $transformed_ids);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param array $ids
|
* @param array $ids
|
||||||
* @return Factory|View|RedirectResponse
|
* @return Factory|View|RedirectResponse
|
||||||
@ -178,6 +199,7 @@ class InvoiceController extends Controller
|
|||||||
private function downloadInvoicePDF(array $ids)
|
private function downloadInvoicePDF(array $ids)
|
||||||
{
|
{
|
||||||
$invoices = Invoice::whereIn('id', $ids)
|
$invoices = Invoice::whereIn('id', $ids)
|
||||||
|
->withTrashed()
|
||||||
->whereClientId(auth()->user()->client->id)
|
->whereClientId(auth()->user()->client->id)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
@ -193,6 +215,8 @@ class InvoiceController extends Controller
|
|||||||
|
|
||||||
$file = $invoice->service()->getInvoicePdf(auth()->user());
|
$file = $invoice->service()->getInvoicePdf(auth()->user());
|
||||||
|
|
||||||
|
// return response()->download(file_get_contents(public_path($file)));
|
||||||
|
|
||||||
return response()->streamDownload(function () use($file) {
|
return response()->streamDownload(function () use($file) {
|
||||||
echo Storage::get($file);
|
echo Storage::get($file);
|
||||||
}, basename($file), ['Content-Type' => 'application/pdf']);
|
}, basename($file), ['Content-Type' => 'application/pdf']);
|
||||||
|
@ -42,7 +42,7 @@ class UrlSetDb
|
|||||||
|
|
||||||
$hashed_db = $hashids->decode($segments[0]);
|
$hashed_db = $hashids->decode($segments[0]);
|
||||||
|
|
||||||
if(!is_array($hashed_db))
|
if(!is_array($hashed_db) || empty($hashed_db))
|
||||||
return response()->json(['message' => 'Invalid confirmation code'], 403);
|
return response()->json(['message' => 'Invalid confirmation code'], 403);
|
||||||
|
|
||||||
MultiDB::setDB(MultiDB::DB_PREFIX.str_pad($hashed_db[0], 2, '0', STR_PAD_LEFT));
|
MultiDB::setDB(MultiDB::DB_PREFIX.str_pad($hashed_db[0], 2, '0', STR_PAD_LEFT));
|
||||||
|
@ -35,6 +35,7 @@ Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence
|
|||||||
|
|
||||||
Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index')->middleware('portal_enabled');
|
Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index')->middleware('portal_enabled');
|
||||||
Route::post('invoices/payment', 'ClientPortal\InvoiceController@bulk')->name('invoices.bulk');
|
Route::post('invoices/payment', 'ClientPortal\InvoiceController@bulk')->name('invoices.bulk');
|
||||||
|
Route::post('invoices/download', 'ClientPortal\InvoiceController@download')->name('invoices.download');
|
||||||
Route::get('invoices/{invoice}', 'ClientPortal\InvoiceController@show')->name('invoice.show');
|
Route::get('invoices/{invoice}', 'ClientPortal\InvoiceController@show')->name('invoice.show');
|
||||||
Route::get('invoices/{invoice_invitation}', 'ClientPortal\InvoiceController@show')->name('invoice.show_invitation');
|
Route::get('invoices/{invoice_invitation}', 'ClientPortal\InvoiceController@show')->name('invoice.show_invitation');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user