1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 06:32:40 +01:00

Fixes for PDF paths

This commit is contained in:
David Bomba 2021-07-07 21:39:49 +10:00
parent 6e4c4fb458
commit 32036a8569
12 changed files with 84 additions and 30 deletions

View File

@ -19,6 +19,8 @@ class InvoiceItem
public $product_key = ''; public $product_key = '';
public $product_cost = 0;
public $notes = ''; public $notes = '';
public $discount = 0; public $discount = 0;
@ -57,6 +59,7 @@ class InvoiceItem
'type_id' => 'string', 'type_id' => 'string',
'quantity' => 'float', 'quantity' => 'float',
'cost' => 'float', 'cost' => 'float',
'product_cost' => 'float',
'product_key' => 'string', 'product_key' => 'string',
'notes' => 'string', 'notes' => 'string',
'discount' => 'float', 'discount' => 'float',

View File

@ -27,6 +27,7 @@ use Illuminate\View\View;
use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\BinaryFileResponse;
use ZipStream\Option\Archive; use ZipStream\Option\Archive;
use ZipStream\ZipStream; use ZipStream\ZipStream;
use Illuminate\Support\Facades\Storage;
class QuoteController extends Controller class QuoteController extends Controller
{ {
@ -89,8 +90,11 @@ class QuoteController extends Controller
if ($quotes->count() == 1) { if ($quotes->count() == 1) {
$file = $quotes->first()->pdf_file_path(); $file = $quotes->first()->service()->getQuotePdf();
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
} }
// enable output of HTTP headers // enable output of HTTP headers

View File

@ -37,6 +37,7 @@ use App\Utils\TempFile;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments; use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
/** /**
* Class CreditController. * Class CreditController.
@ -536,8 +537,14 @@ class CreditController extends BaseController
} }
break; break;
case 'download': case 'download':
$file = $credit->pdf_file_path(); // $file = $credit->pdf_file_path();
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); $file = $credit->service()->getCreditPdf($credit->invitations->first());
// return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
break; break;
case 'archive': case 'archive':
$this->credit_repository->archive($credit); $this->credit_repository->archive($credit);
@ -585,9 +592,12 @@ class CreditController extends BaseController
// $contact = $invitation->contact; // $contact = $invitation->contact;
$credit = $invitation->credit; $credit = $invitation->credit;
$file_path = $credit->service()->getCreditPdf($invitation); $file = $credit->service()->getCreditPdf($invitation);
return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
// return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
} }
/** /**

View File

@ -672,8 +672,17 @@ class InvoiceController extends BaseController
break; break;
case 'download': case 'download':
$file = $invoice->pdf_file_path(); // $file = $invoice->pdf_file_path();
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
$file = $invoice->service()->getInvoicePdf();
// return response()->download(Storage::get($file), basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
break; break;
case 'restore': case 'restore':
@ -722,7 +731,8 @@ class InvoiceController extends BaseController
} }
//touch reminder1,2,3_sent + last_sent here if the email is a reminder. //touch reminder1,2,3_sent + last_sent here if the email is a reminder.
$invoice->service()->touchReminder($this->reminder_template)->deletePdf()->save(); //$invoice->service()->touchReminder($this->reminder_template)->deletePdf()->save();
$invoice->service()->touchReminder($this->reminder_template)->markSent()->save();
$invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) { $invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) {
EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template)->delay(now()->addSeconds(30)); EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template)->delay(now()->addSeconds(30));
@ -795,8 +805,11 @@ class InvoiceController extends BaseController
$file = $invoice->service()->getInvoicePdf($contact); $file = $invoice->service()->getInvoicePdf($contact);
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); // return response()->download(Storage::get($file), basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
} }
/** /**
@ -848,7 +861,10 @@ class InvoiceController extends BaseController
$file = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact); $file = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact);
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
} }

View File

@ -39,6 +39,7 @@ use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments; use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
/** /**
* Class QuoteController. * Class QuoteController.
@ -676,8 +677,14 @@ class QuoteController extends BaseController
break; break;
case 'download': case 'download':
$file = $quote->pdf_file_path(); //$file = $quote->pdf_file_path();
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); $file = $quote->service()->getQuotePdf();
return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
//return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
break; break;
case 'restore': case 'restore':
@ -728,9 +735,14 @@ class QuoteController extends BaseController
$contact = $invitation->contact; $contact = $invitation->contact;
$quote = $invitation->quote; $quote = $invitation->quote;
$file_path = $quote->service()->getQuotePdf($contact); $file = $quote->service()->getQuotePdf($contact);
nlog($file);
return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); return response()->streamDownload(function () use($file) {
echo Storage::get($file);
}, basename($file));
// return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
} }
/** /**

View File

@ -67,7 +67,7 @@ class UpdateCompanyRequest extends Request
{ {
$input = $this->all(); $input = $this->all();
if(array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) if(Ninja::isHosted() && array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1)
$input['portal_domain'] = $this->addScheme($input['portal_domain']); $input['portal_domain'] = $this->addScheme($input['portal_domain']);
if (array_key_exists('settings', $input)) { if (array_key_exists('settings', $input)) {

View File

@ -86,9 +86,8 @@ class CreateEntityPdf implements ShouldQueue
$this->contact = $invitation->contact; $this->contact = $invitation->contact;
//$this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk; $this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk;
$this->disk = $disk;
// $this->disk = $disk ?? config('filesystems.default');
} }
public function handle() public function handle()

View File

@ -11,6 +11,7 @@
namespace App\Mail\Engine; namespace App\Mail\Engine;
use App\Models\Account;
use App\Utils\HtmlEngine; use App\Utils\HtmlEngine;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Number; use App\Utils\Number;

View File

@ -41,10 +41,13 @@ class GetCreditPdf extends AbstractService
$file_path = $path.$this->credit->numberFormatter().'.pdf'; $file_path = $path.$this->credit->numberFormatter().'.pdf';
$disk = 'public'; // $disk = 'public';
$disk = config('filesystems.default');
$file_path = CreateEntityPdf::dispatchNow($this->invitation); $file_path = CreateEntityPdf::dispatchNow($this->invitation);
return Storage::disk($disk)->path($file_path); nlog($file_path);
return $file_path;
// return Storage::disk($disk)->path($file_path);
} }
} }

View File

@ -49,9 +49,9 @@ class GenerateDeliveryNote
$this->contact = $contact; $this->contact = $contact;
$this->disk = 'public'; // $this->disk = 'public';
// $this->disk = $disk ?? config('filesystems.default'); $this->disk = $disk ?? config('filesystems.default');
} }
public function run() public function run()
@ -111,7 +111,8 @@ class GenerateDeliveryNote
Storage::disk($this->disk)->put($file_path, $pdf); Storage::disk($this->disk)->put($file_path, $pdf);
return Storage::disk($this->disk)->path($file_path); //return Storage::disk($this->disk)->path($file_path);
return $file_path;
} }
} }

View File

@ -39,7 +39,8 @@ class GetInvoicePdf extends AbstractService
$file_path = $path.$this->invoice->numberFormatter().'.pdf'; $file_path = $path.$this->invoice->numberFormatter().'.pdf';
$disk = 'public'; // $disk = 'public';
$disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path); $file = Storage::disk($disk)->exists($file_path);
@ -47,6 +48,8 @@ class GetInvoicePdf extends AbstractService
$file_path = CreateEntityPdf::dispatchNow($invitation); $file_path = CreateEntityPdf::dispatchNow($invitation);
} }
return Storage::disk($disk)->path($file_path); // return Storage::disk($disk)->path($file_path);
//
return $file_path;
} }
} }

View File

@ -39,10 +39,12 @@ class GetQuotePdf extends AbstractService
$file_path = $path.$this->quote->numberFormatter().'.pdf'; $file_path = $path.$this->quote->numberFormatter().'.pdf';
$disk = 'public'; // $disk = 'public';
$disk = config('filesystems.default');
$file_path = CreateEntityPdf::dispatchNow($invitation); $file_path = CreateEntityPdf::dispatchNow($invitation);
return Storage::disk($disk)->path($file_path); return $file_path;
//return Storage::disk($disk)->path($file_path);
} }
} }