mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 04:07:32 -05:00 
			
		
		
		
	🐛 Remove blank lines from pdf content when designated pdf variables are empty
This commit is contained in:
		
							parent
							
								
									29af218a01
								
							
						
					
					
						commit
						ed3ba8020a
					
				@ -125,7 +125,7 @@ class Design extends BaseDesign
 | 
				
			|||||||
        $elements = [];
 | 
					        $elements = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($variables as $variable) {
 | 
					        foreach ($variables as $variable) {
 | 
				
			||||||
            $elements[] = ['element' => 'p', 'content' => $variable];
 | 
					            $elements[] = ['element' => 'p', 'content' => $variable, 'show_empty' => false];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $elements;
 | 
					        return $elements;
 | 
				
			||||||
@ -138,7 +138,7 @@ class Design extends BaseDesign
 | 
				
			|||||||
        $elements = [];
 | 
					        $elements = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($variables as $variable) {
 | 
					        foreach ($variables as $variable) {
 | 
				
			||||||
            $elements[] = ['element' => 'p', 'content' => $variable];
 | 
					            $elements[] = ['element' => 'p', 'content' => $variable, 'show_empty' => false];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $elements;
 | 
					        return $elements;
 | 
				
			||||||
@ -151,7 +151,7 @@ class Design extends BaseDesign
 | 
				
			|||||||
        $elements = [];
 | 
					        $elements = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($variables as $variable) {
 | 
					        foreach ($variables as $variable) {
 | 
				
			||||||
            $elements[] = ['element' => 'p', 'content' => $variable];
 | 
					            $elements[] = ['element' => 'p', 'content' => $variable, 'show_empty' => false];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $elements;
 | 
					        return $elements;
 | 
				
			||||||
 | 
				
			|||||||
@ -56,6 +56,10 @@ class PdfMaker
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function build()
 | 
					    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'])) {
 | 
					        if (isset($this->data['template'])) {
 | 
				
			||||||
            $this->updateElementProperties($this->data['template']);
 | 
					            $this->updateElementProperties($this->data['template']);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -118,6 +118,10 @@ trait PdfMakerUtilities
 | 
				
			|||||||
            // <my-tag> => false
 | 
					            // <my-tag> => false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (isset($child['content'])) {
 | 
					            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;
 | 
					                $contains_html = preg_match("/\/[a-z]*>/i", $child['content'], $m) != 0;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -319,4 +323,27 @@ trait PdfMakerUtilities
 | 
				
			|||||||
            $this->document->getElementById('repeat-footer')->appendChild($clone);
 | 
					            $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);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user