diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index b58a74ae67a..b0c257172a4 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2991,7 +2991,7 @@ if ($action == 'create' && $usercancreate) { // Presend form $modelmail = 'order_send'; $defaulttopic = 'SendOrderRef'; - $diroutput = $conf->commande->multidir_output[$object->entity]; + $diroutput = getMultidirOutput($object); $trackid = 'ord'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 026d931a89a..2b11588b854 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3978,6 +3978,7 @@ class Commande extends CommonOrder $this->id = 0; $this->ref = 'SPECIMEN'; $this->specimen = 1; + $this->entity = $conf->entity; $this->socid = 1; $this->date = time(); $this->date_lim_reglement = $this->date + 3600 * 24 * 30; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 36470668f43..69b437ab650 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -71,6 +71,27 @@ if (!function_exists('utf8_decode')) { } } +/** + * Return the full path of the directory where a module (or an object of a module) stores its files. Path may depends on the entity if a multicompany module is enabled. + * + * @param CommonObject $object Dolibarr common object + * @param string $module Override object element, for example to use 'mycompany' instead of 'societe' + * @return string|void The path of the relative directory of the module + * @since Dolibarr V18 + */ +function getMultidirOutput($object, $module = '') +{ + global $conf; + if (!is_object($object)) { + return null; + } + if (empty($module) && !empty($object->element)) { + $module = $object->element; + } else { + return null; + } + return $conf->$module->multidir_output[$object->entity]; +} /** * Return dolibarr global constant string value diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 78b3fa24a33..cb460cff14a 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -296,18 +296,18 @@ class pdf_eratosthene extends ModelePDFCommandes - if ($conf->commande->multidir_output[$conf->entity]) { + if (getMultidirOutput($object)) { $object->fetch_thirdparty(); $deja_regle = 0; // Definition of $dir and $file if ($object->specimen) { - $dir = $conf->commande->multidir_output[$conf->entity]; + $dir = getMultidirOutput($object); $file = $dir."/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); - $dir = $conf->commande->multidir_output[$object->entity]."/".$objectref; + $dir = getMultidirOutput($object)."/".$objectref; $file = $dir."/".$objectref.".pdf"; } @@ -1447,7 +1447,7 @@ class pdf_eratosthene extends ModelePDFCommandes protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle") { // phpcs:enable - global $conf, $langs, $hookmanager; + global $conf, $langs, $hookmanager, $mysoc; $ltrdirection = 'L'; if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R'; @@ -1473,8 +1473,8 @@ class pdf_eratosthene extends ModelePDFCommandes if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) { if ($this->emetteur->logo) { $logodir = $conf->mycompany->dir_output; - if (!empty($conf->mycompany->multidir_output[$object->entity])) { - $logodir = $conf->mycompany->multidir_output[$object->entity]; + if (!empty(getMultidirOutput($mysoc, 'mycompany'))) { + $logodir = getMultidirOutput($mysoc, 'mycompany'); } if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) { $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1912bd74521..a56fad2c086 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4358,7 +4358,9 @@ class Societe extends CommonObject global $langs; $this->id = 0; + $this->entity = $conf->entity; $this->name = getDolGlobalString('MAIN_INFO_SOCIETE_NOM'); + $this->nom = $this->name; // deprecated $this->address = getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS'); $this->zip = getDolGlobalString('MAIN_INFO_SOCIETE_ZIP'); $this->town = getDolGlobalString('MAIN_INFO_SOCIETE_TOWN'); @@ -4368,8 +4370,6 @@ class Societe extends CommonObject $this->note_private = getDolGlobalString('MAIN_INFO_SOCIETE_NOTE'); - $this->nom = $this->name; // deprecated - // We define country_id, country_code and country $country_id = $country_code = $country_label = ''; if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {