From 7ffa8a14abd87b8e56a0e661818c9ed9e91dcd8b Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 8 Oct 2021 13:10:44 +0200 Subject: [PATCH 1/3] fix: option COMPANY_SHOW_ADDRESS_SELECTLIST and SOCIETE_ADD_REF_IN_LIST work in ajaxcompanies --- htdocs/societe/ajax/ajaxcompanies.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/ajax/ajaxcompanies.php b/htdocs/societe/ajax/ajaxcompanies.php index 9295c363206..60448dbd875 100644 --- a/htdocs/societe/ajax/ajaxcompanies.php +++ b/htdocs/societe/ajax/ajaxcompanies.php @@ -88,7 +88,17 @@ if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn', 'int } $sql = "SELECT rowid, 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); } From 0d47797be7015d1254aff23df1a2d402759f5a1a Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 8 Oct 2021 13:14:08 +0200 Subject: [PATCH 2/3] fix sql --- htdocs/societe/ajax/ajaxcompanies.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/ajax/ajaxcompanies.php b/htdocs/societe/ajax/ajaxcompanies.php index 60448dbd875..89aa4f524b6 100644 --- a/htdocs/societe/ajax/ajaxcompanies.php +++ b/htdocs/societe/ajax/ajaxcompanies.php @@ -87,9 +87,9 @@ 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"; + $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"; From 5d393f201c80720d0e01e58ff3439c91115d4d05 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 8 Oct 2021 13:17:09 +0200 Subject: [PATCH 3/3] fix sql --- htdocs/core/class/html.formcompany.class.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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)) {