diff --git a/htdocs/core/lib/invoice2.lib.php b/htdocs/core/lib/invoice2.lib.php index 288a1f5a014fc..72703a72fc4db 100644 --- a/htdocs/core/lib/invoice2.lib.php +++ b/htdocs/core/lib/invoice2.lib.php @@ -242,40 +242,38 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte $fac = new Expedition($db); } - if ($fac) { - $result = $fac->fetch($obj->rowid); - if ($result > 0) { - $outputlangs = $langs; - if (!empty($newlangid)) { - if ($outputlangs->defaultlang != $newlangid) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlangid); - } + $result = $fac->fetch($obj->rowid); + if ($result > 0) { + $outputlangs = $langs; + if (!empty($newlangid)) { + if ($outputlangs->defaultlang != $newlangid) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlangid); } - $filename = $dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf'; - if ($regenerate || !dol_is_file($filename)) { - if ($usestdout) { - print "Build PDF for document ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n"; - } - $result = $fac->generateDocument($regenerate ? $regenerate : $fac->model_pdf, $outputlangs); - } else { - if ($usestdout) { - print "PDF for document ".$obj->ref." already exists\n"; - } - } - - // Add file into files array - $files[] = $filename; } - - if ($result <= 0) { - $error++; + $filename = $dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf'; + if ($regenerate || !dol_is_file($filename)) { + if ($usestdout) { + print "Build PDF for document ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n"; + } + $result = $fac->generateDocument($regenerate ? $regenerate : $fac->model_pdf, $outputlangs); + } else { if ($usestdout) { - print "Error: Failed to build PDF for document ".($fac->ref ? $fac->ref : ' id '.$obj->rowid)."\n"; - } else { - dol_syslog("Failed to build PDF for document ".($fac->ref ? $fac->ref : ' id '.$obj->rowid), LOG_ERR); + print "PDF for document ".$obj->ref." already exists\n"; } } + + // Add file into files array + $files[] = $filename; + } + + if ($result <= 0) { + $error++; + if ($usestdout) { + print "Error: Failed to build PDF for document ".($fac->ref ? $fac->ref : ' id '.$obj->rowid)."\n"; + } else { + dol_syslog("Failed to build PDF for document ".($fac->ref ? $fac->ref : ' id '.$obj->rowid), LOG_ERR); + } } $cpt++;