From f460d2e705ede1ee91420f48fb0a92606f01ee78 Mon Sep 17 00:00:00 2001 From: mikee2 Date: Sun, 9 Apr 2017 21:39:15 +0200 Subject: [PATCH 1/2] Update Segment.php --- htdocs/includes/odtphp/Segment.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index 39761aa4d04..2ef40b2cd66 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -139,6 +139,8 @@ 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 + $this->xmlParsed = $this->macroReplace($this->xmlParsed); $this->file->open($this->odf->getTmpfile()); foreach ($this->images as $imageKey => $imageValue) { if ($this->file->getFromName('Pictures/' . $imageValue) === false) { @@ -152,6 +154,29 @@ class Segment implements IteratorAggregate, Countable 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( '/\[%M\]/','/\[%F\]/','/\[%Y\]/' ); + $values=array( $langs->trans(date('M')), $langs->trans(date('F')), date('Y') ); + + $text=preg_replace($patterns, $values, $text); + + return $text; + } /** * Analyse the XML code in order to find children * From e6b20840a3d66db0bcf8053fcc2aa7540cd46b63 Mon Sep 17 00:00:00 2001 From: mikee2 Date: Fri, 14 Apr 2017 11:49:30 +0200 Subject: [PATCH 2/2] Update Segment.php --- htdocs/includes/odtphp/Segment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index 2ef40b2cd66..81e9dad9f97 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -170,8 +170,8 @@ class Segment implements IteratorAggregate, Countable { global $langs; - $patterns=array( '/\[%M\]/','/\[%F\]/','/\[%Y\]/' ); - $values=array( $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);