From 2d67444f977f926c08f8759615f330db1c7ce9f9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 23 Feb 2023 21:24:39 +1100 Subject: [PATCH] Roll back entity designer --- app/Services/Invoice/GenerateDeliveryNote.php | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php index 108f69e01e7e..2e16dfd551da 100644 --- a/app/Services/Invoice/GenerateDeliveryNote.php +++ b/app/Services/Invoice/GenerateDeliveryNote.php @@ -5,7 +5,7 @@ * * @link https://github.com/invoiceninja/invoiceninja source repository * - * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) + * @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */ @@ -15,7 +15,6 @@ namespace App\Services\Invoice; use App\Models\ClientContact; use App\Models\Design; use App\Models\Invoice; -use App\Services\Pdf\PdfService; use App\Services\PdfMaker\Design as PdfMakerDesign; use App\Services\PdfMaker\PdfMaker as PdfMakerService; use App\Utils\HostedPDF\NinjaPdf; @@ -55,16 +54,62 @@ class GenerateDeliveryNote public function run() { + $design_id = $this->invoice->design_id + ? $this->invoice->design_id + : $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')); $invitation = $this->invoice->invitations->first(); - + // $file_path = sprintf('%s%s_delivery_note.pdf', $this->invoice->client->invoice_filepath($invitation), $this->invoice->number); $file_path = sprintf('%sdelivery_note.pdf', $this->invoice->client->invoice_filepath($invitation)); - $pdf = (new PdfService($invitation, 'delivery_note'))->getPdf(); + if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { + return (new Phantom)->generate($this->invoice->invitations->first()); + } + + $design = Design::find($design_id); + $html = new HtmlEngine($invitation); + + 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(), + 'process_markdown' => $this->invoice->client->company->markdown_enabled, + ]; + + $maker = new PdfMakerService($state); + + $maker + ->design($template) + ->build(); + + // Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775); + + if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') { + $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true)); + } else { + $pdf = $this->makePdf(null, null, $maker->getCompiledHTML()); + } + + if (config('ninja.log_pdf_html')) { + info($maker->getCompiledHTML()); + } Storage::disk($this->disk)->put($file_path, $pdf); + + $maker = null; + $state = null; return $file_path; - } }