diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 67a68309bb91..791001100289 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -1,4 +1,5 @@ generate($this->invitation); + } App::setLocale($this->contact->preferredLocale()); @@ -81,14 +84,40 @@ class CreateInvoicePdf implements ShouldQueue $design = Design::find($invoice_design_id); - $designer = new Designer($this->invoice, $design, $this->invoice->client->getSetting('pdf_variables'), 'invoice'); + info('Start: ' . now()); - $html = (new HtmlEngine($designer, $this->invitation, 'invoice'))->build(); + $html = new HtmlEngine(null, $this->invitation, 'invoice'); + + $design_namespace = 'App\Services\PdfMaker\Designs\\' . $design->name; + + $design_class = new $design_namespace(); + + $product_table_columns = json_decode( + json_encode($this->invoice->company->settings->pdf_variables), + 1 + )['product_columns']; + + $state = [ + 'template' => $design_class->elements([ + 'client' => $this->invoice->client, + 'entity' => $this->invoice, + 'product-table-columns' => $product_table_columns, + ]), + 'variables' => $html->generateLabelsAndValues(), + ]; + + $maker = new PdfMakerService($state); + + $maker + ->design($design_namespace) + ->build(); + + info('Done: ' . now()); //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0755); - $pdf = $this->makePdf(null, null, $html); + $pdf = $this->makePdf(null, null, $maker->getCompiledHTML()); $instance = Storage::disk($this->disk)->put($file_path, $pdf);