mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #7038 from turbo124/v5-develop
Fixes for download PDFs
This commit is contained in:
commit
81d9e7a6ec
2
.github/workflows/phpunit.yml
vendored
2
.github/workflows/phpunit.yml
vendored
@ -55,7 +55,7 @@ jobs:
|
||||
|
||||
- name: Start mysql service
|
||||
run: |
|
||||
sudo /etc/init.d/mysql start
|
||||
sudo systemctl start mysql.service
|
||||
- name: Verify MariaDB connection
|
||||
env:
|
||||
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
|
||||
|
@ -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']);
|
||||
|
@ -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));
|
||||
|
@ -51,6 +51,7 @@ class CreateStatementRequest extends Request
|
||||
|
||||
public function client(): ?Client
|
||||
{
|
||||
return Client::with('company')->where('id', $this->client_id)->withTrashed()->first();
|
||||
// return Client::without('gateway_tokens','documents','contacts.company',)->where('id', $this->client_id)->withTrashed()->first();
|
||||
return Client::without('company',)->where('id', $this->client_id)->withTrashed()->first();
|
||||
}
|
||||
}
|
||||
|
@ -105,18 +105,18 @@ class CompanyExport implements ShouldQueue
|
||||
|
||||
})->makeHidden(['id'])->all();
|
||||
|
||||
$this->export_data['backups'] = $this->company->all_activities()->with('backup')->cursor()->map(function ($activity){
|
||||
// $this->export_data['backups'] = $this->company->all_activities()->with('backup')->cursor()->map(function ($activity){
|
||||
|
||||
$backup = $activity->backup;
|
||||
// $backup = $activity->backup;
|
||||
|
||||
if(!$backup)
|
||||
return;
|
||||
// if(!$backup)
|
||||
// return;
|
||||
|
||||
$backup->activity_id = $this->encodePrimaryKey($backup->activity_id);
|
||||
// $backup->activity_id = $this->encodePrimaryKey($backup->activity_id);
|
||||
|
||||
return $backup;
|
||||
// return $backup;
|
||||
|
||||
})->all();
|
||||
// })->all();
|
||||
|
||||
$this->export_data['users'] = $this->company->users()->withTrashed()->cursor()->map(function ($user){
|
||||
|
||||
|
@ -143,7 +143,7 @@ class CompanyImport implements ShouldQueue
|
||||
'tasks',
|
||||
'payments',
|
||||
'activities',
|
||||
'backups',
|
||||
// 'backups',
|
||||
'company_ledger',
|
||||
'designs',
|
||||
'documents',
|
||||
@ -874,20 +874,13 @@ class CompanyImport implements ShouldQueue
|
||||
|
||||
$activities = [];
|
||||
|
||||
// foreach($this->backup_file->activities as $activity)
|
||||
// foreach((object)$this->getObject("activities") as $obj)
|
||||
// {
|
||||
// $activity->account_id = $this->account->id;
|
||||
// $activities[] = $activity;
|
||||
// }
|
||||
|
||||
// $this->backup_file->activities = $activities;
|
||||
|
||||
$this->genericNewClassImport(Activity::class,
|
||||
[
|
||||
'hashed_id',
|
||||
'company_id',
|
||||
'backup',
|
||||
'invitation_id',
|
||||
],
|
||||
[
|
||||
['users' => 'user_id'],
|
||||
@ -903,7 +896,7 @@ class CompanyImport implements ShouldQueue
|
||||
['quotes' => 'quote_id'],
|
||||
['subscriptions' => 'subscription_id'],
|
||||
['recurring_invoices' => 'recurring_invoice_id'],
|
||||
['invitations' => 'invitation_id'],
|
||||
// ['invitations' => 'invitation_id'],
|
||||
],
|
||||
'activities');
|
||||
|
||||
@ -1438,7 +1431,9 @@ class CompanyImport implements ShouldQueue
|
||||
}
|
||||
|
||||
if (! array_key_exists($resource, $this->ids)) {
|
||||
// nlog($this->ids);
|
||||
nlog($resource);
|
||||
|
||||
nlog($this->ids);
|
||||
|
||||
$this->sendImportMail("The Import failed due to missing data in the import file. Resource {$resource} not available.");
|
||||
throw new \Exception("Resource {$resource} not available.");
|
||||
|
@ -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');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user