diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index d1fc8f65edb..1c188792a09 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -700,8 +700,18 @@ class FormCompany extends Form return $socid; } else { // Search to list thirdparties - $sql = "SELECT s.rowid, s.nom as name FROM"; - $sql .= " ".MAIN_DB_PREFIX."societe as s"; + $sql = "SELECT s.rowid, s.nom as name "; + if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) { + $sql .= ", s.code_client, s.code_fournisseur"; + } + if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { + $sql .= ", s.address, s.zip, s.town"; + $sql .= ", dictp.code as country_code"; + } + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid = s.fk_pays"; + } $sql .= " WHERE s.entity IN (".getEntity('societe').")"; // For ajax search we limit here. For combo list, we limit later if (is_array($limitto) && count($limitto)) { diff --git a/htdocs/societe/ajax/ajaxcompanies.php b/htdocs/societe/ajax/ajaxcompanies.php index 9295c363206..89aa4f524b6 100644 --- a/htdocs/societe/ajax/ajaxcompanies.php +++ b/htdocs/societe/ajax/ajaxcompanies.php @@ -87,8 +87,18 @@ if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn', 'int $socid = GETPOST('id_fourn', 'int'); } - $sql = "SELECT rowid, nom"; + $sql = "SELECT s.rowid, s.nom"; + if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) { + $sql .= ", s.client, s.fournisseur, s.code_client, s.code_fournisseur"; + } + if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { + $sql .= ", s.address, s.zip, s.town"; + $sql .= ", dictp.code as country_code"; + } $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid = s.fk_pays"; + } $sql .= " WHERE s.entity IN (".getEntity('societe').")"; if ($socid) { $sql .= " AND ("; @@ -114,7 +124,22 @@ if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn', 'int $resql = $db->query($sql); if ($resql) { while ($row = $db->fetch_array($resql)) { - $label = $row['nom']; + $label = ''; + if ($conf->global->SOCIETE_ADD_REF_IN_LIST) { + if (($row['client']) && (!empty($row['code_client']))) { + $label = $row['code_client'].' - '; + } + if (($row['fournisseur']) && (!empty($row['code_fournisseur']))) { + $label .= $row['code_fournisseur'].' - '; + } + $label .= ' '.$row['name']; + } + if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { + $label .= ($row['address'] ? ' - '.$row['address'] : '').($row['zip'] ? ' - '.$row['zip'] : '').($row['town'] ? ' '.$row['town'] : ''); + if (!empty($row['country_code'])) { + $label .= ', '.$langs->trans('Country'.$row['country_code']); + } + } if ($socid) { $label = preg_replace('/('.preg_quote($socid, '/').')/i', '$1', $label, 1); }