From c57fcdb7ece57104d9d8b189d900bc439433cb3a Mon Sep 17 00:00:00 2001 From: vmaury Date: Fri, 23 Jun 2023 02:50:21 +0200 Subject: [PATCH 1/3] Fix #25171 : add a function in Societe class to retrieve contacts of a societe --- htdocs/societe/class/societe.class.php | 94 ++++++++++++++++++++++++++ htdocs/theme/eldy/global.inc.php | 2 +- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index d6197639d76..0d88c4f570d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -5276,4 +5276,98 @@ class Societe extends CommonObject $return .= ''; return $return; } + + /** + * Get array of all contacts for a society (stored in societe_contacts instead of element_contacts for all other objects) + * + * @param int socid id of societe + * @param int $list 0:Return array contains all properties, 1:Return array contains just id + * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) + * @param string $element Filter on this element of default contact type ('facture', 'propal', 'commande' ...) + * @return array|int Array of contacts, -1 if error + * + * + * + */ + function liste_contact_societe($list = 0, $code = '', $element = '') + { + // phpcs:enable + global $langs, $db; + + $tab = array(); + + $sql = "SELECT sc.rowid, sc.fk_socpeople as id, sc.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user + + $sql .= ", t.fk_soc as socid, t.statut as statuscontact"; + + $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; + $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; + $sql .= " FROM ".$db->prefix()."c_type_contact tc"; + $sql .= ", ".$db->prefix()."societe_contacts sc"; + +// fk_soc ↓ = +// fk_c_type_contact fk_socpeople tms import_key + + $sql .= " LEFT JOIN ".$db->prefix()."socpeople t on sc.fk_socpeople = t.rowid"; + + $sql .= " WHERE sc.fk_soc = ".((int) $this->id); + $sql .= " AND sc.fk_c_type_contact = tc.rowid"; + if (!empty($element)) { + $sql .= " AND tc.element = '".$db->escape($element)."'"; + } + if ($code) { + $sql .= " AND tc.code = '".$db->escape($code)."'"; + } + $sql .= " AND sc.entity = ".getEntity($this->element); + + $sql .= " AND tc.source = 'external'"; + + $sql .= " AND tc.active=1"; + + $sql .= " ORDER BY t.lastname ASC"; + + dol_syslog(get_class($this)."::liste_contact_societe", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) { + $obj = $db->fetch_object($resql); + + if (!$list) { + $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); + $tab[$i] = array( + 'source' => $obj->source, + 'socid' => $obj->socid, + 'id' => $obj->id, + 'nom' => $obj->lastname, // For backward compatibility + 'civility' => $obj->civility, + 'lastname' => $obj->lastname, + 'firstname' => $obj->firstname, + 'email'=>$obj->email, + 'login'=> (empty($obj->login) ? '' : $obj->login), + 'photo' => (empty($obj->photo) ? '' : $obj->photo), + 'statuscontact' => $obj->statuscontact, + 'rowid' => $obj->rowid, + 'code' => $obj->code, + 'element' => $obj->element, + 'libelle' => $libelle_type, + 'status' => $obj->statuslink, + 'fk_c_type_contact' => $obj->fk_c_type_contact + ); + } else { + $tab[$i] = $obj->id; + } + + $i++; + } + + return $tab; + } else { + $error = $db->lasterror(); + dol_print_error($db); + return -1; + } + } } diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index cf7b4d5d912..f4d3eb5966c 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -4504,7 +4504,7 @@ ul.noborder li:nth-child(even):not(.liste_titre) { border: 1px solid var(--colorboxstatsborder); border-left: 6px solid var(--colorboxstatsborder); /* box-shadow: 1px 1px 8px var(--colorboxstatsborder); */ - border-radius: 0px; + border-radius: 4px; } .boxstats, .boxstats130, .boxstatscontent { white-space: nowrap; From 58e6ce7f637a3eb0afeb25b69c61e0582425dd89 Mon Sep 17 00:00:00 2001 From: vmaury Date: Fri, 23 Jun 2023 09:53:40 +0200 Subject: [PATCH 2/3] Fix #25171 : add a function in Societe class to retrieve contacts of a societe --- htdocs/societe/class/societe.class.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 0d88c4f570d..92aa59e8600 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -5292,7 +5292,7 @@ class Societe extends CommonObject function liste_contact_societe($list = 0, $code = '', $element = '') { // phpcs:enable - global $langs, $db; + global $langs; $tab = array(); @@ -5302,21 +5302,21 @@ class Societe extends CommonObject $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; - $sql .= " FROM ".$db->prefix()."c_type_contact tc"; - $sql .= ", ".$db->prefix()."societe_contacts sc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact tc"; + $sql .= ", ".$this->db->prefix()."societe_contacts sc"; // fk_soc ↓ = // fk_c_type_contact fk_socpeople tms import_key - $sql .= " LEFT JOIN ".$db->prefix()."socpeople t on sc.fk_socpeople = t.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."socpeople t on sc.fk_socpeople = t.rowid"; $sql .= " WHERE sc.fk_soc = ".((int) $this->id); $sql .= " AND sc.fk_c_type_contact = tc.rowid"; if (!empty($element)) { - $sql .= " AND tc.element = '".$db->escape($element)."'"; + $sql .= " AND tc.element = '".$this->db->escape($element)."'"; } if ($code) { - $sql .= " AND tc.code = '".$db->escape($code)."'"; + $sql .= " AND tc.code = '".$this->db->escape($code)."'"; } $sql .= " AND sc.entity = ".getEntity($this->element); @@ -5327,12 +5327,12 @@ class Societe extends CommonObject $sql .= " ORDER BY t.lastname ASC"; dol_syslog(get_class($this)."::liste_contact_societe", LOG_DEBUG); - $resql = $db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { - $obj = $db->fetch_object($resql); + $obj = $this->db->fetch_object($resql); if (!$list) { $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; @@ -5365,8 +5365,8 @@ class Societe extends CommonObject return $tab; } else { - $error = $db->lasterror(); - dol_print_error($db); + $this->error = $this->db->lasterror(); + dol_print_error($this->db); return -1; } } From 3e9af3ad8bd5e87efcda33b13d4f2fa0b4760c20 Mon Sep 17 00:00:00 2001 From: vmaury Date: Fri, 23 Jun 2023 09:53:40 +0200 Subject: [PATCH 3/3] Fix #25171 : add method getContacts in Societe class to retrieve contacts of a societe --- htdocs/societe/class/societe.class.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 92aa59e8600..7d438ec1d4e 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -5285,11 +5285,9 @@ class Societe extends CommonObject * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) * @param string $element Filter on this element of default contact type ('facture', 'propal', 'commande' ...) * @return array|int Array of contacts, -1 if error - * * - * */ - function liste_contact_societe($list = 0, $code = '', $element = '') + function getContacts($list = 0, $code = '', $element = '') { // phpcs:enable global $langs; @@ -5305,9 +5303,6 @@ class Societe extends CommonObject $sql .= " FROM ".$this->db->prefix()."c_type_contact tc"; $sql .= ", ".$this->db->prefix()."societe_contacts sc"; -// fk_soc ↓ = -// fk_c_type_contact fk_socpeople tms import_key - $sql .= " LEFT JOIN ".$this->db->prefix()."socpeople t on sc.fk_socpeople = t.rowid"; $sql .= " WHERE sc.fk_soc = ".((int) $this->id); @@ -5318,15 +5313,13 @@ class Societe extends CommonObject if ($code) { $sql .= " AND tc.code = '".$this->db->escape($code)."'"; } - $sql .= " AND sc.entity = ".getEntity($this->element); - - $sql .= " AND tc.source = 'external'"; - + $sql .= " AND sc.entity = ".getEntity($this->element); + $sql .= " AND tc.source = 'external'"; $sql .= " AND tc.active=1"; $sql .= " ORDER BY t.lastname ASC"; - dol_syslog(get_class($this)."::liste_contact_societe", LOG_DEBUG); + dol_syslog(get_class($this)."::getContacts", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql);