Merge all substitutions on same loop (Invoicing with odt)

* It's not necessary to have a redondant loop to substitute all variables
This commit is contained in:
cam.lafit
2012-10-31 14:44:44 +01:00
parent 7b8b015569
commit a3f0ce9063

View File

@@ -381,74 +381,21 @@ class doc_generic_invoice_odt extends ModelePDFFactures
} }
// Make substitutions into odt of user info // Make substitutions into odt of user info
$tmparray=$this->get_substitutionarray_user($user,$outputlangs); $array_user=$this->get_substitutionarray_user($user,$outputlangs);
//var_dump($tmparray); exit; $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
foreach($tmparray as $key=>$value) $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
{ $array_objet=$this->get_substitutionarray_object($object,$outputlangs);
try {
if (preg_match('/logo$/',$key)) // Image $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet);
{
//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 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); complete_substitutions_array($tmparray, $outputlangs, $object);
//var_dump($tmparray); exit;
foreach($tmparray as $key=>$value) foreach($tmparray as $key=>$value)
{ {
try { try {
if (preg_match('/logo$/',$key)) // Image if (preg_match('/logo$/',$key)) // Image
{ {
//var_dump($value);exit;
if (file_exists($value)) $odfHandler->setImage($key, $value); if (file_exists($value)) $odfHandler->setImage($key, $value);
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
} }