invitation = $invitation; $this->invoice = $invitation->invoice; $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); } App::setLocale($this->contact->preferredLocale()); $path = $this->invoice->client->invoice_filepath(); $file_path = $path.$this->invoice->number.'.pdf'; $invoice_design_id = $this->invoice->design_id ? $this->invoice->design_id : $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')); $design = Design::find($invoice_design_id); $html = new HtmlEngine(null, $this->invitation, 'invoice'); $template = new PdfMakerDesign(strtolower($design->name)); $state = [ 'template' => $template->elements([ 'client' => $this->invoice->client, 'entity' => $this->invoice, 'pdf_variables' => (array) $this->invoice->company->settings->pdf_variables, ]), 'variables' => $html->generateLabelsAndValues(), 'options' => [ 'all_pages_header' => $this->invoice->client->getSetting('all_pages_header'), 'all_pages_footer' => $this->invoice->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); info($maker->getCompiledHTML(true)); $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); $instance = Storage::disk($this->disk)->put($file_path, $pdf); return $file_path; } }