diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index fe9809860eab..c3c752e29e0e 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -30,6 +30,7 @@ use Illuminate\Support\Facades\Storage; use Illuminate\View\View; use ZipStream\Option\Archive; use ZipStream\ZipStream; +use Illuminate\Http\Request; class InvoiceController extends Controller { @@ -95,7 +96,8 @@ class InvoiceController extends Controller if ($request->input('action') == 'payment') { return $this->makePayment((array) $transformed_ids); } 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() @@ -103,6 +105,25 @@ class InvoiceController extends Controller ->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 * @return Factory|View|RedirectResponse @@ -178,6 +199,7 @@ class InvoiceController extends Controller private function downloadInvoicePDF(array $ids) { $invoices = Invoice::whereIn('id', $ids) + ->withTrashed() ->whereClientId(auth()->user()->client->id) ->get(); @@ -193,6 +215,8 @@ class InvoiceController extends Controller $file = $invoice->service()->getInvoicePdf(auth()->user()); + // return response()->download(file_get_contents(public_path($file))); + return response()->streamDownload(function () use($file) { echo Storage::get($file); }, basename($file), ['Content-Type' => 'application/pdf']); diff --git a/app/Http/Middleware/UrlSetDb.php b/app/Http/Middleware/UrlSetDb.php index 3c9d779e31b1..f77b9d6c1e02 100644 --- a/app/Http/Middleware/UrlSetDb.php +++ b/app/Http/Middleware/UrlSetDb.php @@ -42,7 +42,7 @@ class UrlSetDb $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); MultiDB::setDB(MultiDB::DB_PREFIX.str_pad($hashed_db[0], 2, '0', STR_PAD_LEFT)); diff --git a/routes/client.php b/routes/client.php index cd8860c6f960..b2b2c7f1af05 100644 --- a/routes/client.php +++ b/routes/client.php @@ -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::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_invitation}', 'ClientPortal\InvoiceController@show')->name('invoice.show_invitation');