From a3f0ce90630c158f8b51f514cef641d9dac2503d Mon Sep 17 00:00:00 2001 From: "cam.lafit" Date: Wed, 31 Oct 2012 14:44:44 +0100 Subject: [PATCH] Merge all substitutions on same loop (Invoicing with odt) * It's not necessary to have a redondant loop to substitute all variables --- .../doc/doc_generic_invoice_odt.modules.php | 69 +++---------------- 1 file changed, 8 insertions(+), 61 deletions(-) diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index fcb942784ee..807eaef314b 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -381,7 +381,14 @@ class doc_generic_invoice_odt extends ModelePDFFactures } // Make substitutions into odt of user info - $tmparray=$this->get_substitutionarray_user($user,$outputlangs); + $array_user=$this->get_substitutionarray_user($user,$outputlangs); + $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); + $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); + $array_objet=$this->get_substitutionarray_object($object,$outputlangs); + + $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet); + complete_substitutions_array($tmparray, $outputlangs, $object); + //var_dump($tmparray); exit; foreach($tmparray as $key=>$value) { @@ -400,66 +407,6 @@ class doc_generic_invoice_odt extends ModelePDFFactures catch(OdfException $e) { } - } - // Make substitutions into odt of mysoc - $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } - } - // Make substitutions into odt of thirdparty - $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } - } - // Replace tags of object + external modules - $tmparray=$this->get_substitutionarray_object($object,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $object); - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } } // Replace tags of lines try