diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index c800d3a02f84..750a76476ea7 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -18,6 +18,7 @@ use App\Jobs\Invoice\CreateInvoicePdf; use App\Jobs\Util\PreviewPdf; use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesInvoiceHtml; +use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\Storage; class PreviewController extends BaseController @@ -155,7 +156,7 @@ class PreviewController extends BaseController return response()->json(['message' => 'Invalid custom design object'], 400); } - $designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity'))); + $designer = new Designer($invoice, $design_object, auth()->user()->company()->settings->pdf_variables, lcfirst(request()->has('entity'))); $html = $this->generateEntityHtml($designer, $invoice, $contact); @@ -165,6 +166,9 @@ class PreviewController extends BaseController $contact->forceDelete(); $client->forceDelete(); - return response()->file($file_path, array('content-type' => 'application/pdf')); + $response = Response::make($file_path, 200); + $response->header('Content-Type', 'application/pdf'); + return $response; + } } diff --git a/app/Jobs/Util/PreviewPdf.php b/app/Jobs/Util/PreviewPdf.php index ebd57aa71b72..298bb61ca5ea 100644 --- a/app/Jobs/Util/PreviewPdf.php +++ b/app/Jobs/Util/PreviewPdf.php @@ -33,14 +33,10 @@ use Spatie\Browsershot\Browsershot; class PreviewPdf implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker; - - public $invoice; + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PdfMaker; public $company; - public $contact; - private $disk; public $design_string; @@ -61,16 +57,8 @@ class PreviewPdf implements ShouldQueue public function handle() { - $path = $this->company->company_key; - //Storage::makeDirectory($path, 0755); + return $this->makePdf(null, null, $this->design_string); - $file_path = $path . '/stream.pdf'; - - $pdf = $this->makePdf(null, null, $this->design_string); - - $instance = Storage::disk('local')->put($file_path, $pdf); - - return storage_path('app') .'/'. $file_path; } }