From d6f3fc9fe7dcf1ec2cb13b75b04eda2dc889c0b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 22 Mar 2018 16:05:50 +0100 Subject: [PATCH] Fix use the getSalesRepresentative function instead of get_users --- htdocs/societe/card.php | 8 ++-- htdocs/societe/class/societe.class.php | 55 +++++++++++--------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index f93a27bdb0f..920dee364c7 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -538,7 +538,7 @@ if (empty($reshook)) $error++; } } - + // Links with users $salesreps = GETPOST('commercial', 'array'); $result = $object->setSalesRep($salesreps); @@ -676,7 +676,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); $error++; } - + // Links with users $salesreps = GETPOST('commercial', 'array'); $result = $object->setSalesRep($salesreps); @@ -1949,14 +1949,14 @@ else // Capital print ''.fieldLabel('Capital','capital').''; print ' '.$langs->trans("Currency".$conf->currency).''; - + // Assign a Name print ''; print ''.fieldLabel('AllocateCommercial','commercial_id').''; print ''; $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1); $arrayselected = GETPOST('commercial', 'array'); - if(empty($arrayselected)) $arrayselected = $object->get_users(); + if (empty($arrayselected)) $arrayselected = $object->getSalesRepresentatives($user, 1); print $form->multiselectarray('commercial', $userlist, $arrayselected, null, null, null, null, "90%"); print ''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 931ee953a86..62834b1271c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1819,9 +1819,10 @@ class Societe extends CommonObject * Return array of sales representatives * * @param User $user Object user + * @param int $mode 0=Array with properties, 1=Array of id. * @return array Array of sales representatives of third party */ - function getSalesRepresentatives(User $user) + function getSalesRepresentatives(User $user, $mode=0) { global $conf; @@ -1849,14 +1850,22 @@ class Societe extends CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - $reparray[$i]['id']=$obj->rowid; - $reparray[$i]['lastname']=$obj->lastname; - $reparray[$i]['firstname']=$obj->firstname; - $reparray[$i]['email']=$obj->email; - $reparray[$i]['statut']=$obj->statut; - $reparray[$i]['entity']=$obj->entity; - $reparray[$i]['login']=$obj->login; - $reparray[$i]['photo']=$obj->photo; + + if (empty($mode)) + { + $reparray[$i]['id']=$obj->rowid; + $reparray[$i]['lastname']=$obj->lastname; + $reparray[$i]['firstname']=$obj->firstname; + $reparray[$i]['email']=$obj->email; + $reparray[$i]['statut']=$obj->statut; + $reparray[$i]['entity']=$obj->entity; + $reparray[$i]['login']=$obj->login; + $reparray[$i]['photo']=$obj->photo; + } + else + { + $reparray[]=$obj->rowid; + } $i++; } return $reparray; @@ -3921,22 +3930,22 @@ class Societe extends CommonObject } /** - * Sets company to supplied users. + * Sets sales representatives of the thirdparty * - * @param int[]|int $users User ID or array of user IDs + * @param int[]|int $salesrep User ID or array of user IDs * @return int <0 if KO, >0 if OK */ public function setSalesRep($salesrep) { global $user; - + // Handle single user if (!is_array($salesrep)) { $salesrep = array($salesrep); } // Get current users - $existing = $this->get_users(); + $existing = $this->getSalesRepresentatives($user, 1); // Diff if (is_array($existing)) { @@ -3966,26 +3975,6 @@ class Societe extends CommonObject return $error ? -1 : 1; } - - /** - * Get all linked user to company - * - * @return Array - */ - public function get_users() { - $sql = 'SELECT fk_user FROM '.MAIN_DB_PREFIX.'societe_commerciaux '; - $sql.= 'WHERE fk_soc = '.$this->id; - - $resql = $this->db->query($sql); - - $users = array(); - - while ($obj = $this->db->fetch_object($resql)) { - $users[] = $obj->fk_user; - } - - return $users; - } /**