From 4bd1895fa7276a8cb258b91d7b003c0e418cf4a1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 15 Mar 2023 12:03:39 +1100 Subject: [PATCH] Updates for PDF designer with custom columns --- app/Services/PdfMaker/Design.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index c10c96b15766..2dba44efc7cb 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -679,7 +679,14 @@ class Design extends BaseDesign '$task.rate' => '$task.cost', ]; - foreach ($this->context['pdf_variables']["{$type}_columns"] as $column) { + $table_type = "{$type}_columns"; + + nlog($table_type); + + if($type == 'product' && $this->entity instanceof Quote && !$this->settings_object->getSetting('sync_invoice_quote_columns')) + $table_type = "product_quote_columns"; + + foreach ($this->context['pdf_variables'][$table_type] as $column) { if (array_key_exists($column, $aliases)) { $elements[] = ['element' => 'th', 'content' => $aliases[$column] . '_label', 'properties' => ['data-ref' => "{$type}_table-" . substr($aliases[$column], 1) . '-th', 'hidden' => $this->settings_object->getSetting('hide_empty_columns_on_pdf')]]; } elseif ($column == '$product.discount' && !$this->company->enable_product_discount) { @@ -748,6 +755,14 @@ class Design extends BaseDesign return $elements; } + $_type = Str::startsWith($type, '$') ? ltrim($type, '$') : $type; + $table_type = "{$_type}_columns"; + + if ($_type == 'product' && $this->entity instanceof Quote && !$this->settings_object->getSetting('sync_invoice_quote_columns')) { + $table_type = "product_quote_columns"; + } + + foreach ($items as $row) { $element = ['element' => 'tr', 'elements' => []]; @@ -775,9 +790,8 @@ class Design extends BaseDesign } } } else { - $_type = Str::startsWith($type, '$') ? ltrim($type, '$') : $type; - foreach ($this->context['pdf_variables']["{$_type}_columns"] as $key => $cell) { + foreach ($this->context['pdf_variables'][$table_type] as $key => $cell) { // We want to keep aliases like these: // $task.cost => $task.rate // $task.quantity => $task.hours