Fix use the getSalesRepresentative function instead of get_users

This commit is contained in:
Laurent Destailleur 2018-03-22 16:05:50 +01:00
parent aa859f980d
commit d6f3fc9fe7
2 changed files with 26 additions and 37 deletions

View File

@ -1956,7 +1956,7 @@ else
print '<td colspan="3" class="maxwidthonsmartphone">'; print '<td colspan="3" class="maxwidthonsmartphone">';
$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1); $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, '', 0, '', '', 0, 1);
$arrayselected = GETPOST('commercial', 'array'); $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 $form->multiselectarray('commercial', $userlist, $arrayselected, null, null, null, null, "90%");
print '</td></tr>'; print '</td></tr>';

View File

@ -1819,9 +1819,10 @@ class Societe extends CommonObject
* Return array of sales representatives * Return array of sales representatives
* *
* @param User $user Object user * @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 * @return array Array of sales representatives of third party
*/ */
function getSalesRepresentatives(User $user) function getSalesRepresentatives(User $user, $mode=0)
{ {
global $conf; global $conf;
@ -1849,14 +1850,22 @@ class Societe extends CommonObject
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$reparray[$i]['id']=$obj->rowid;
$reparray[$i]['lastname']=$obj->lastname; if (empty($mode))
$reparray[$i]['firstname']=$obj->firstname; {
$reparray[$i]['email']=$obj->email; $reparray[$i]['id']=$obj->rowid;
$reparray[$i]['statut']=$obj->statut; $reparray[$i]['lastname']=$obj->lastname;
$reparray[$i]['entity']=$obj->entity; $reparray[$i]['firstname']=$obj->firstname;
$reparray[$i]['login']=$obj->login; $reparray[$i]['email']=$obj->email;
$reparray[$i]['photo']=$obj->photo; $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++; $i++;
} }
return $reparray; return $reparray;
@ -3921,9 +3930,9 @@ 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 * @return int <0 if KO, >0 if OK
*/ */
public function setSalesRep($salesrep) public function setSalesRep($salesrep)
@ -3936,7 +3945,7 @@ class Societe extends CommonObject
} }
// Get current users // Get current users
$existing = $this->get_users(); $existing = $this->getSalesRepresentatives($user, 1);
// Diff // Diff
if (is_array($existing)) { if (is_array($existing)) {
@ -3967,26 +3976,6 @@ class Societe extends CommonObject
return $error ? -1 : 1; 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;
}
/** /**
* Function used to replace a thirdparty id with another one. * Function used to replace a thirdparty id with another one.