diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 14c872a34447..5cdd222c6cef 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -298,6 +298,7 @@ class Design extends BaseDesign public function buildTableHeader(string $type): array { $this->processTaxColumns($type); + $this->processCustomColumns($type); $elements = []; diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index d80c6c4b1a4d..2ce308e25ccc 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -266,4 +266,23 @@ trait DesignHelpers return $logs; } + + public function processCustomColumns(string $type): void + { + $custom_columns = []; + + foreach ((array) $this->client->company->custom_fields as $field => $value) { + info($field); + + if (\Illuminate\Support\Str::startsWith($field, $type)) { + $custom_columns[] = '$' . $type . '.' . $field; + } + } + + $key = array_search(sprintf('%s%s.description', '$', $type), $this->context['pdf_variables']["{$type}_columns"], true); + + if ($key) { + array_splice($this->context['pdf_variables']["{$type}_columns"], $key + 1, 0, $custom_columns); + } + } }