diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 54a9983a6d9..080cc4d5f95 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1298,6 +1298,18 @@ class Contact extends CommonObject } } + if (!$error) { + // Remove Notifications + $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def WHERE fk_contact = ".((int) $this->id); + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->error .= $this->db->lasterror(); + $errorflag = -1; + } + } + if (!$error) { // Remove category $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".((int) $this->id); diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2a4a830d124..99133109c0b 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -321,9 +321,12 @@ function societe_prepare_head(Societe $object) if (!is_null($dataretrieved)) { $nbNotif = $dataretrieved; } else { + // List of notifications enabled for contacts $sql = "SELECT COUNT(n.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n"; - $sql .= " WHERE fk_soc = ".((int) $object->id); + $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; + $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; + $sql .= " WHERE a.rowid = n.fk_action"; + $sql .= " AND n.fk_soc = ".((int) $object->id); $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php index 0e0031e6f9c..69d8ce43b50 100644 --- a/htdocs/societe/notify/card.php +++ b/htdocs/societe/notify/card.php @@ -233,7 +233,7 @@ if ($result > 0) { $sql .= " c.rowid as contactid, c.lastname, c.firstname, c.email"; $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; - $sql .= " ".MAIN_DB_PREFIX."socpeople c"; + $sql .= " ".MAIN_DB_PREFIX."socpeople as c"; $sql .= " WHERE a.rowid = n.fk_action"; $sql .= " AND c.rowid = n.fk_contact"; $sql .= " AND c.fk_soc = ".((int) $object->id);