1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

wip - CreateInvoicePdf

This commit is contained in:
Benjamin Beganović 2020-08-11 18:50:24 +02:00
parent 2de19a4bb1
commit caa704af96

View File

@ -1,4 +1,5 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
@ -19,6 +20,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;
@ -68,8 +70,9 @@ class CreateInvoicePdf implements ShouldQueue
public function handle()
{
if(config('ninja.phantomjs_key'))
if (config('ninja.phantomjs_key')) {
return (new Phantom)->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);