Fix use the getSalesRepresentative function instead of get_users
This commit is contained in:
parent
aa859f980d
commit
d6f3fc9fe7
@ -538,7 +538,7 @@ if (empty($reshook))
|
|||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Links with users
|
// Links with users
|
||||||
$salesreps = GETPOST('commercial', 'array');
|
$salesreps = GETPOST('commercial', 'array');
|
||||||
$result = $object->setSalesRep($salesreps);
|
$result = $object->setSalesRep($salesreps);
|
||||||
@ -676,7 +676,7 @@ if (empty($reshook))
|
|||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Links with users
|
// Links with users
|
||||||
$salesreps = GETPOST('commercial', 'array');
|
$salesreps = GETPOST('commercial', 'array');
|
||||||
$result = $object->setSalesRep($salesreps);
|
$result = $object->setSalesRep($salesreps);
|
||||||
@ -1949,14 +1949,14 @@ else
|
|||||||
// Capital
|
// Capital
|
||||||
print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
|
print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
|
||||||
print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
|
print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
|
||||||
|
|
||||||
// Assign a Name
|
// Assign a Name
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>'.fieldLabel('AllocateCommercial','commercial_id').'</td>';
|
print '<td>'.fieldLabel('AllocateCommercial','commercial_id').'</td>';
|
||||||
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>';
|
||||||
|
|
||||||
|
|||||||
@ -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,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
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function setSalesRep($salesrep)
|
public function setSalesRep($salesrep)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
// Handle single user
|
// Handle single user
|
||||||
if (!is_array($salesrep)) {
|
if (!is_array($salesrep)) {
|
||||||
$salesrep = array($salesrep);
|
$salesrep = array($salesrep);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)) {
|
||||||
@ -3966,26 +3975,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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user