- Add new "product" key to $context of Design

- Add custom products table body handling in Design.php
This commit is contained in:
Benjamin Beganović 2020-10-06 12:49:00 +02:00
parent 92eb842357
commit 76695b8462
4 changed files with 32 additions and 2 deletions

View File

@ -113,6 +113,7 @@ class PreviewController extends BaseController
'client' => $entity_obj->client,
'entity' => $entity_obj,
'pdf_variables' => (array) $entity_obj->company->settings->pdf_variables,
'products' => request()->design['design']['product'],
]),
'variables' => $html->generateLabelsAndValues(),
];
@ -184,6 +185,7 @@ class PreviewController extends BaseController
'client' => $invoice->client,
'entity' => $invoice,
'pdf_variables' => (array) $invoice->company->settings->pdf_variables,
'products' => request()->design['design']['product'],
]),
'variables' => $html->generateLabelsAndValues(),
];

View File

@ -94,6 +94,7 @@ class CreateInvoicePdf implements ShouldQueue
'client' => $this->invoice->client,
'entity' => $this->invoice,
'pdf_variables' => (array) $this->invoice->company->settings->pdf_variables,
'products' => $design->design->product,
]),
'variables' => $html->generateLabelsAndValues(),
'options' => [

View File

@ -92,6 +92,7 @@ class CreateQuotePdf implements ShouldQueue
'client' => $this->quote->client,
'entity' => $this->quote,
'pdf_variables' => (array) $this->quote->company->settings->pdf_variables,
'products' => $design->design->product,
]),
'variables' => $html->generateLabelsAndValues(),
'options' => [

View File

@ -16,6 +16,7 @@ use App\Services\PdfMaker\Designs\Utilities\BaseDesign;
use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
use App\Utils\Number;
use App\Utils\Traits\MakesInvoiceValues;
use DOMDocument;
use Illuminate\Support\Str;
class Design extends BaseDesign
@ -210,8 +211,33 @@ class Design extends BaseDesign
foreach ($items as $row) {
$element = ['element' => 'tr', 'elements' => []];
foreach ($this->context['pdf_variables']["{$this->type}_columns"] as $key => $cell) {
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell]];
if (
isset($this->context['products']) &&
!empty($this->context['products']) &&
!is_null($this->context['products'])
) {
$document = new DOMDocument();
$document->loadHTML($this->context['products'], LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$td = $document->getElementsByTagName('tr')->item(0);
if ($td) {
foreach ($td->childNodes as $child) {
if ($child->nodeType !== 1) {
continue;
}
if ($child->tagName !== 'td') {
continue;
}
$element['elements'][] = ['element' => 'td', 'content' => strtr($child->nodeValue, $row)];
}
}
} else {
foreach ($this->context['pdf_variables']["{$this->type}_columns"] as $key => $cell) {
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell]];
}
}
$elements[] = $element;