diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index b47bfbc79e6..66caf2ea23a 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -433,14 +433,16 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target if (!empty($targetcontact->address)) { $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact))."\n"; } else { - $companytouse = $targetcompany; + $companytouseforaddress = $targetcompany; - if($targetcontact->socid > 0 && $targetcontact->socid != $targetcompany->id) { // Contact thirdparty different from document thirdparty + // Contact on a thirdparty that is a different thirdparty than the thirdparty of object + if ($targetcontact->socid > 0 && $targetcontact->socid != $targetcompany->id) + { $targetcontact->fetch_thirparty(); - $companytouse = $targetcontact->thirdparty; + $companytouseforaddress = $targetcontact->thirdparty; } - $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($companytouse))."\n"; + $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress))."\n"; } // Country if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {