invitation = $invitation; $this->quote = $invitation->quote; $this->company = $invitation->company; $this->contact = $invitation->contact; $this->disk = $disk ?? config('filesystems.default'); } public function handle() { if (config('ninja.phantomjs_key')) { return (new Phantom)->generate($this->invitation); } $this->quote->load('client'); App::setLocale($this->contact->preferredLocale()); $path = $this->quote->client->quote_filepath(); $quote_design_id = $this->quote->design_id ? $this->quote->design_id : $this->decodePrimaryKey($this->quote->client->getSetting('quote_design_id')); $design = Design::find($quote_design_id); $html = new HtmlEngine(null, $this->invitation, 'quote'); $template = new PdfMakerDesign(strtolower($design->name)); $state = [ 'template' => $template->elements([ 'client' => $this->quote->client, 'entity' => $this->quote, 'pdf_variables' => (array) $this->quote->company->settings->pdf_variables, 'products' => $design->design->product, ]), 'variables' => $html->generateLabelsAndValues(), 'options' => [ 'all_pages_header' => $this->quote->client->getSetting('all_pages_header'), 'all_pages_footer' => $this->quote->client->getSetting('all_pages_footer'), ], ]; $maker = new PdfMakerService($state); $maker ->design($template) ->build(); //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0775); $pdf = $this->makePdf(null, null, $maker->getCompiledHTML()); $file_path = $path.$this->quote->number.'.pdf'; $instance = Storage::disk($this->disk)->put($file_path, $pdf); return $file_path; } }