mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improvements for twig
This commit is contained in:
parent
89e58b7693
commit
d5339d0864
@ -90,6 +90,17 @@ class CreateRawPdf implements ShouldQueue
|
|||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
/** Testing this override to improve PDF generation performance */
|
||||||
|
$ps = new PdfService($this->invitation, 'product', [
|
||||||
|
'client' => $this->entity->client,
|
||||||
|
"{$this->entity_string}s" => [$this->entity],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$pdf = $ps->boot()->getPdf();
|
||||||
|
nlog("pdf timer = ". $ps->execution_time);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Forget the singleton*/
|
/* Forget the singleton*/
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
|
|
||||||
@ -124,96 +135,87 @@ class CreateRawPdf implements ShouldQueue
|
|||||||
|
|
||||||
$file_path = $path.$this->entity->numberFormatter().'.pdf';
|
$file_path = $path.$this->entity->numberFormatter().'.pdf';
|
||||||
|
|
||||||
|
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
|
||||||
|
|
||||||
$ps = new PdfService($this->invitation, 'product', [
|
$design = Design::query()->withTrashed()->find($entity_design_id);
|
||||||
|
|
||||||
|
/* Catch all in case migration doesn't pass back a valid design */
|
||||||
|
if (! $design) {
|
||||||
|
$design = Design::query()->find(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = new HtmlEngine($this->invitation);
|
||||||
|
|
||||||
|
if ($design->is_custom) {
|
||||||
|
$options = [
|
||||||
|
'custom_partials' => json_decode(json_encode($design->design), true),
|
||||||
|
];
|
||||||
|
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
||||||
|
} else {
|
||||||
|
$template = new PdfMakerDesign(strtolower($design->name));
|
||||||
|
}
|
||||||
|
|
||||||
|
$variables = $html->generateLabelsAndValues();
|
||||||
|
|
||||||
|
$state = [
|
||||||
|
'template' => $template->elements([
|
||||||
'client' => $this->entity->client,
|
'client' => $this->entity->client,
|
||||||
"{$this->entity_string}s" => [$this->entity],
|
'entity' => $this->entity,
|
||||||
]);
|
'pdf_variables' => (array) $this->entity->company->settings->pdf_variables,
|
||||||
|
'$product' => $design->design->product,
|
||||||
|
'variables' => $variables,
|
||||||
|
]),
|
||||||
|
'variables' => $variables,
|
||||||
|
'options' => [
|
||||||
|
'all_pages_header' => $this->entity->client->getSetting('all_pages_header'),
|
||||||
|
'all_pages_footer' => $this->entity->client->getSetting('all_pages_footer'),
|
||||||
|
'client' => $this->entity->client,
|
||||||
|
'entity' => $this->entity,
|
||||||
|
'variables' => $variables,
|
||||||
|
],
|
||||||
|
'process_markdown' => $this->entity->client->company->markdown_enabled,
|
||||||
|
];
|
||||||
|
|
||||||
$pdf = $ps->boot()->getPdf();
|
$maker = new PdfMakerService($state);
|
||||||
|
|
||||||
|
$maker
|
||||||
|
->design($template)
|
||||||
|
->build();
|
||||||
|
|
||||||
// $entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
|
$pdf = null;
|
||||||
|
|
||||||
// $design = Design::query()->withTrashed()->find($entity_design_id);
|
try {
|
||||||
|
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
||||||
|
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
// /* Catch all in case migration doesn't pass back a valid design */
|
$finfo = new \finfo(FILEINFO_MIME);
|
||||||
// if (! $design) {
|
|
||||||
// $design = Design::query()->find(2);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $html = new HtmlEngine($this->invitation);
|
//fallback in case hosted PDF fails.
|
||||||
|
if ($finfo->buffer($pdf) != 'application/pdf; charset=binary') {
|
||||||
|
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||||
|
|
||||||
// if ($design->is_custom) {
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
// $options = [
|
|
||||||
// 'custom_partials' => json_decode(json_encode($design->design), true),
|
|
||||||
// ];
|
|
||||||
// $template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
|
||||||
// } else {
|
|
||||||
// $template = new PdfMakerDesign(strtolower($design->name));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $variables = $html->generateLabelsAndValues();
|
if ($numbered_pdf) {
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||||
|
|
||||||
// $state = [
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
// 'template' => $template->elements([
|
|
||||||
// 'client' => $this->entity->client,
|
|
||||||
// 'entity' => $this->entity,
|
|
||||||
// 'pdf_variables' => (array) $this->entity->company->settings->pdf_variables,
|
|
||||||
// '$product' => $design->design->product,
|
|
||||||
// 'variables' => $variables,
|
|
||||||
// ]),
|
|
||||||
// 'variables' => $variables,
|
|
||||||
// 'options' => [
|
|
||||||
// 'all_pages_header' => $this->entity->client->getSetting('all_pages_header'),
|
|
||||||
// 'all_pages_footer' => $this->entity->client->getSetting('all_pages_footer'),
|
|
||||||
// 'client' => $this->entity->client,
|
|
||||||
// 'entity' => $this->entity,
|
|
||||||
// 'variables' => $variables,
|
|
||||||
// ],
|
|
||||||
// 'process_markdown' => $this->entity->client->company->markdown_enabled,
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $maker = new PdfMakerService($state);
|
if ($numbered_pdf) {
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
nlog(print_r($e->getMessage(), 1));
|
||||||
|
}
|
||||||
|
|
||||||
// $maker
|
if (config('ninja.log_pdf_html')) {
|
||||||
// ->design($template)
|
info($maker->getCompiledHTML());
|
||||||
// ->build();
|
}
|
||||||
|
|
||||||
// $pdf = null;
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
|
||||||
// $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
|
||||||
|
|
||||||
// $finfo = new \finfo(FILEINFO_MIME);
|
|
||||||
|
|
||||||
// //fallback in case hosted PDF fails.
|
|
||||||
// if ($finfo->buffer($pdf) != 'application/pdf; charset=binary') {
|
|
||||||
// $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
|
||||||
|
|
||||||
// $numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
|
||||||
|
|
||||||
// if ($numbered_pdf) {
|
|
||||||
// $pdf = $numbered_pdf;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
|
||||||
|
|
||||||
// $numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
|
||||||
|
|
||||||
// if ($numbered_pdf) {
|
|
||||||
// $pdf = $numbered_pdf;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (\Exception $e) {
|
|
||||||
// nlog(print_r($e->getMessage(), 1));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (config('ninja.log_pdf_html')) {
|
|
||||||
// info($maker->getCompiledHTML());
|
|
||||||
// }
|
|
||||||
|
|
||||||
if ($pdf) {
|
if ($pdf) {
|
||||||
$maker =null;
|
$maker =null;
|
||||||
|
@ -44,6 +44,10 @@ class PdfService
|
|||||||
|
|
||||||
public array $options;
|
public array $options;
|
||||||
|
|
||||||
|
private float $start_time;
|
||||||
|
|
||||||
|
public float $execution_time;
|
||||||
|
|
||||||
const DELIVERY_NOTE = 'delivery_note';
|
const DELIVERY_NOTE = 'delivery_note';
|
||||||
const STATEMENT = 'statement';
|
const STATEMENT = 'statement';
|
||||||
const PURCHASE_ORDER = 'purchase_order';
|
const PURCHASE_ORDER = 'purchase_order';
|
||||||
@ -61,7 +65,9 @@ class PdfService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function boot(): self
|
public function boot(): self
|
||||||
{nlog("booties");
|
{
|
||||||
|
$this->start_time = microtime(true);
|
||||||
|
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -90,6 +96,8 @@ class PdfService
|
|||||||
throw new \Exception($e->getMessage(), $e->getCode());
|
throw new \Exception($e->getMessage(), $e->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->execution_time = microtime(true) - $this->start_time;
|
||||||
|
|
||||||
return $pdf;
|
return $pdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +115,8 @@ class PdfService
|
|||||||
nlog($html);
|
nlog($html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->execution_time = microtime(true) - $this->start_time;
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user