From 0ba6a4351e13f4b96234e55e71030f850b3a0279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 12 Aug 2020 19:21:29 +0200 Subject: [PATCH] Integrate new PdfMaker for CreateQuotePdf --- app/Jobs/Invoice/CreateInvoicePdf.php | 4 ---- app/Jobs/Quote/CreateQuotePdf.php | 28 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index d014f1bc11e2..b15045ec7ed9 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -84,8 +84,6 @@ class CreateInvoicePdf implements ShouldQueue $design = Design::find($invoice_design_id); - info('Start: ' . now()); - $html = new HtmlEngine(null, $this->invitation, 'invoice'); $design_namespace = 'App\Services\PdfMaker\Designs\\' . $design->name; @@ -109,8 +107,6 @@ class CreateInvoicePdf implements ShouldQueue ->design($design_namespace) ->build(); - info($maker->getCompiledHTML()); - //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0755); diff --git a/app/Jobs/Quote/CreateQuotePdf.php b/app/Jobs/Quote/CreateQuotePdf.php index c3c9f9c298b7..1ce12e0063a6 100644 --- a/app/Jobs/Quote/CreateQuotePdf.php +++ b/app/Jobs/Quote/CreateQuotePdf.php @@ -19,6 +19,7 @@ use App\Models\ClientContact; use App\Models\Company; use App\Models\Design; use App\Models\Invoice; +use App\Services\PdfMaker\PdfMaker as PdfMakerService; use App\Utils\HtmlEngine; use App\Utils\PhantomJS\Phantom; use App\Utils\Traits\MakesHash; @@ -81,14 +82,33 @@ class CreateQuotePdf implements ShouldQueue $design = Design::find($quote_design_id); - $designer = new Designer($this->quote, $design, $this->quote->client->getSetting('pdf_variables'), 'quote'); + $html = new HtmlEngine(null, $this->invitation, 'quote'); + + $design_namespace = 'App\Services\PdfMaker\Designs\\' . $design->name; + + $design_class = new $design_namespace(); + + $pdf_variables = json_decode(json_encode($this->quote->company->settings->pdf_variables), 1); + + $state = [ + 'template' => $design_class->elements([ + 'client' => $this->quote->client, + 'entity' => $this->quote, + 'product-table-columns' => $pdf_variables['product_columns'], + ]), + 'variables' => $html->generateLabelsAndValues(), + ]; + + $maker = new PdfMakerService($state); + + $maker + ->design($design_namespace) + ->build(); //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0755); - $html = (new HtmlEngine($designer, $this->invitation, 'quote'))->build(); - - $pdf = $this->makePdf(null, null, $html); + $pdf = $this->makePdf(null, null, $maker->getCompiledHTML()); $file_path = $path . $this->quote->number . '.pdf';