| '.$langs->trans("SalesRepresentatives").' | ';
print '';
- $sql = "SELECT u.rowid, u.lastname, u.firstname";
+ $sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode))
+ {
+ $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
+ }
$sql .= " WHERE sc.fk_soc =".$object->id;
$sql .= " AND sc.fk_user = u.rowid";
+ if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode))
+ {
+ $sql.= " AND ((ug.fk_user = sc.fk_user";
+ $sql.= " AND ug.entity = ".$conf->entity.")";
+ $sql.= " OR u.admin = 1)";
+ }
+ else
+ $sql.= " AND u.entity IN (0,".$conf->entity.")";
+
$sql .= " ORDER BY u.lastname ASC ";
+
dol_syslog('societe/commerciaux.php::list salesman sql = '.$sql,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
@@ -206,9 +220,9 @@ if (! empty($socid))
if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode))
{
$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
- $sql.= " WHERE (ug.fk_user = u.rowid";
+ $sql.= " WHERE ((ug.fk_user = u.rowid";
$sql.= " AND ug.entity = ".$conf->entity.")";
- $sql.= " OR u.admin = 1";
+ $sql.= " OR u.admin = 1)";
}
else
$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index c4fb84fa30f..b492bc3725f 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -2303,7 +2303,18 @@ else
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
- if (! empty($object->email))
+ $at_least_one_email_contact = false;
+ $TContact = $object->contact_array_objects();
+ foreach ($TContact as &$contact)
+ {
+ if (!empty($contact->email))
+ {
+ $at_least_one_email_contact = true;
+ break;
+ }
+ }
+
+ if (! empty($object->email) || $at_least_one_email_contact)
{
$langs->load("mails");
print '';
|