From 9268955256825d9059727b0f22409dcfb71828b7 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Wed, 26 Aug 2020 09:40:20 +0200 Subject: [PATCH 1/2] FIX set sales representatives on create company card --- htdocs/societe/card.php | 2 +- htdocs/societe/class/societe.class.php | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index d2f27419e76..401f7b2175b 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -539,7 +539,7 @@ if (empty($reshook)) // Links with users $salesreps = GETPOST('commercial', 'array'); - $result = $object->setSalesRep($salesreps); + $result = $object->setSalesRep($salesreps, true); if ($result < 0) { $error++; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 918674ba23a..30511855e91 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4133,9 +4133,10 @@ class Societe extends CommonObject * Sets sales representatives of the thirdparty * * @param int[]|int $salesrep User ID or array of user IDs + * @param bool $onlyAdd Only add (no delete before) * @return int <0 if KO, >0 if OK */ - public function setSalesRep($salesrep) + public function setSalesRep($salesrep, $onlyAdd = false) { global $user; @@ -4144,16 +4145,18 @@ class Societe extends CommonObject $salesrep = array($salesrep); } - // Get current users - $existing = $this->getSalesRepresentatives($user, 1); - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $salesrep); - $to_add = array_diff($salesrep, $existing); - } else { - $to_del = array(); // Nothing to delete - $to_add = $salesrep; + $to_del = array(); // Nothing to delete + $to_add = $salesrep; + if ($onlyAdd === false) { + // Get current users + $existing = $this->getSalesRepresentatives($user, 1); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $salesrep); + $to_add = array_diff($salesrep, $existing); + } } $error = 0; From 9b3f13458fc1d95e92d01142dbd0b4abe76e9bbe Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Wed, 26 Aug 2020 16:02:31 +0200 Subject: [PATCH 2/2] FIX: missing entity check --- htdocs/compta/prelevement/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/compta/prelevement/index.php b/htdocs/compta/prelevement/index.php index 936fbebcf6e..9b9e8e08ce5 100644 --- a/htdocs/compta/prelevement/index.php +++ b/htdocs/compta/prelevement/index.php @@ -180,6 +180,7 @@ print '
'; $limit=5; $sql = "SELECT p.rowid, p.ref, p.amount, p.datec, p.statut"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; +$sql.= " WHERE entity IN (" . getEntity('prelevement') . ")"; $sql.= " ORDER BY datec DESC"; $sql.= $db->plimit($limit);