FIX #7420
This commit is contained in:
parent
0c01c7ceba
commit
aba907d1a8
@ -24,7 +24,7 @@ class Segment implements IteratorAggregate, Countable
|
||||
protected $images = array();
|
||||
protected $odf;
|
||||
protected $file;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -86,15 +86,15 @@ class Segment implements IteratorAggregate, Countable
|
||||
*/
|
||||
public function merge()
|
||||
{
|
||||
// To provide debug information on line number processed
|
||||
// To provide debug information on line number processed
|
||||
global $count;
|
||||
if (empty($count)) $count=1;
|
||||
else $count++;
|
||||
|
||||
|
||||
if (empty($this->savxml)) $this->savxml = $this->xml; // Sav content of line at first line merged, so we will reuse original for next steps
|
||||
$this->xml = $this->savxml;
|
||||
$tmpvars = $this->vars; // Store into $tmpvars so we won't modify this->vars when completing data with empty values
|
||||
|
||||
|
||||
// Search all tags fou into condition to complete $tmpvars, so we will proceed all tests even if not defined
|
||||
$reg='@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU';
|
||||
preg_match_all($reg, $this->xml, $matches, PREG_SET_ORDER);
|
||||
@ -106,7 +106,7 @@ class Segment implements IteratorAggregate, Countable
|
||||
$tmpvars[$match[1]] = ''; // Not defined, so we set it to '', we just need entry into this->vars for next loop
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Conditionals substitution
|
||||
// Note: must be done before static substitution, else the variable will be replaced by its value and the conditional won't work anymore
|
||||
foreach($tmpvars as $key => $value)
|
||||
@ -133,7 +133,7 @@ class Segment implements IteratorAggregate, Countable
|
||||
$this->xml = preg_replace($reg, '', $this->xml);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->xmlParsed .= str_replace(array_keys($tmpvars), array_values($tmpvars), $this->xml);
|
||||
if ($this->hasChildren()) {
|
||||
foreach ($this->children as $child) {
|
||||
@ -143,7 +143,7 @@ class Segment implements IteratorAggregate, Countable
|
||||
}
|
||||
$reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/sm";
|
||||
$this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed);
|
||||
// Miguel Erill 09704/2017 - Add macro replacement to invoice lines
|
||||
// Miguel Erill 09704/2017 - Add macro replacement to invoice lines
|
||||
$this->xmlParsed = $this->macroReplace($this->xmlParsed);
|
||||
$this->file->open($this->odf->getTmpfile());
|
||||
foreach ($this->images as $imageKey => $imageValue) {
|
||||
@ -155,28 +155,28 @@ class Segment implements IteratorAggregate, Countable
|
||||
}
|
||||
}
|
||||
$this->file->close();
|
||||
|
||||
|
||||
return $this->xmlParsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to replace macros for invoice short and long month, invoice year
|
||||
*
|
||||
*
|
||||
* Substitution occur when the invoice is generated, not considering the invoice date
|
||||
* so do not (re)generate in a diferent date than the one that the invoice belongs to
|
||||
* Perhaps it would be better to use the invoice issued date but I still do not know
|
||||
* how to get it here
|
||||
*
|
||||
* Miguel Erill 09/04/2017
|
||||
*
|
||||
*
|
||||
* @param string $value String to convert
|
||||
*/
|
||||
public function macroReplace($text)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$patterns=array( '__CURRENTDAY__','__CURRENTDAYTEXT__','__CURRENTMONTHSHORT__','__CURRENTMONTH__','__CURRENTYEAR__' );
|
||||
$values=array( date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y') );
|
||||
$patterns=array('/__CURRENTDAY__/','/__CURRENTDAYTEXT__/','/__CURRENTMONTHSHORT__/','/__CURRENTMONTH__/','/__CURRENTYEAR__/');
|
||||
$values=array(date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y'));
|
||||
|
||||
$text=preg_replace($patterns, $values, $text);
|
||||
|
||||
@ -203,7 +203,7 @@ class Segment implements IteratorAggregate, Countable
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assign a template variable to replace
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user