diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php
index 8d1052be02c9..93c695bfe5ed 100644
--- a/app/Services/PdfMaker/Design.php
+++ b/app/Services/PdfMaker/Design.php
@@ -125,7 +125,7 @@ class Design extends BaseDesign
$elements = [];
foreach ($variables as $variable) {
- $elements[] = ['element' => 'p', 'content' => $variable];
+ $elements[] = ['element' => 'p', 'content' => $variable, 'show_empty' => false];
}
return $elements;
@@ -138,7 +138,7 @@ class Design extends BaseDesign
$elements = [];
foreach ($variables as $variable) {
- $elements[] = ['element' => 'p', 'content' => $variable];
+ $elements[] = ['element' => 'p', 'content' => $variable, 'show_empty' => false];
}
return $elements;
@@ -151,7 +151,7 @@ class Design extends BaseDesign
$elements = [];
foreach ($variables as $variable) {
- $elements[] = ['element' => 'p', 'content' => $variable];
+ $elements[] = ['element' => 'p', 'content' => $variable, 'show_empty' => false];
}
return $elements;
@@ -170,7 +170,7 @@ class Design extends BaseDesign
foreach ($variables as $variable) {
$_variable = explode('.', $variable)[1];
$_customs = ['custom1', 'custom2', 'custom3', 'custom4'];
-
+
if (in_array($_variable, $_customs)) {
$elements[] = ['element' => 'tr', 'elements' => [
['element' => 'th', 'content' => $variable . '_label'],
diff --git a/app/Services/PdfMaker/PdfMaker.php b/app/Services/PdfMaker/PdfMaker.php
index df9c97eb57d0..cd288766f65f 100644
--- a/app/Services/PdfMaker/PdfMaker.php
+++ b/app/Services/PdfMaker/PdfMaker.php
@@ -56,6 +56,10 @@ class PdfMaker
public function build()
{
+ if (isset($this->data['template']) && isset($this->data['variables'])) {
+ $this->getEmptyElements($this->data['template'], $this->data['variables']);
+ }
+
if (isset($this->data['template'])) {
$this->updateElementProperties($this->data['template']);
}
@@ -72,7 +76,7 @@ class PdfMaker
public function getCompiledHTML($final = false)
{
$html = $this->document->saveHTML();
-
+
return str_replace('%24', '$', $html);
}
}
diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php
index 17c23d2c737f..02664812d1ed 100644
--- a/app/Services/PdfMaker/PdfMakerUtilities.php
+++ b/app/Services/PdfMaker/PdfMakerUtilities.php
@@ -117,8 +117,12 @@ trait PdfMakerUtilities
// => true
// => false
- if (isset($child['content'])) {
- $contains_html = preg_match("/\/[a-z]*>/i", $child['content'],$m) != 0;
+ if (isset($child['content'])) {
+ if (isset($child['is_empty']) && $child['is_empty'] === true) {
+ continue;
+ }
+
+ $contains_html = preg_match("/\/[a-z]*>/i", $child['content'], $m) != 0;
}
if ($contains_html) {
@@ -319,4 +323,27 @@ trait PdfMakerUtilities
$this->document->getElementById('repeat-footer')->appendChild($clone);
}
}
+
+ public function getEmptyElements(array &$elements, array $variables) {
+ foreach ($elements as &$element) {
+ if (isset($element['elements'])) {
+ $this->getEmptyChildrens($element['elements'], $variables);
+ }
+ }
+ }
+
+ public function getEmptyChildrens(array &$children, array $variables) {
+ foreach ($children as $key => &$child) {
+ if (isset($child['content']) && isset($child['show_empty']) && $child['show_empty'] === false) {
+ $value = strtr($child['content'], $variables['values']);
+ if ($value === '' || $value === ' ') {
+ $child['is_empty'] = true;
+ }
+ }
+
+ if (isset($child['elements'])) {
+ $this->getEmptyChildrens($child['elements'], $variables);
+ }
+ }
+ }
}