invoice = $invoice; $this->contact = $contact; $this->disk = $disk ?? config('filesystems.default'); } public function run() { $design_id = $this->invoice->design_id ? $this->invoice->design_id : $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')); $file_path = sprintf('%s%s_delivery_note.pdf', $this->invoice->client->invoice_filepath(), $this->invoice->number); $design = Design::find($design_id); $html = new HtmlEngine($this->invoice->invitations->first()); if ($design->is_custom) { $options = ['custom_partials' => json_decode(json_encode($design->design), true)]; $template = new PdfMakerDesign(PdfMakerDesign::CUSTOM, $options); } else { $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, 'contact' => $this->contact, ], 'delivery_note'), 'variables' => $html->generateLabelsAndValues(), ]; $maker = new PdfMakerService($state); $maker ->design($template) ->build(); Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775); $pdf = $this->makePdf(null, null, $maker->getCompiledHTML()); Storage::disk($this->disk)->put($file_path, $pdf); return $file_path; } }