diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 3d5e4e87aa5f..0d46c509b0c6 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -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(), ]; diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 124ed7e3117a..6695c3a429dd 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -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' => [ diff --git a/app/Jobs/Quote/CreateQuotePdf.php b/app/Jobs/Quote/CreateQuotePdf.php index c7493e77a081..4a3bad8e29ce 100644 --- a/app/Jobs/Quote/CreateQuotePdf.php +++ b/app/Jobs/Quote/CreateQuotePdf.php @@ -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' => [ diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 1a64d205ed36..267c3555e75f 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -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;