From 864205771b24445e1a811ffbc54e62fc619b10ab Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 18:18:20 +0200 Subject: [PATCH 1/8] NEW API filter thirdparty by category --- htdocs/societe/class/api_thirdparties.class.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 5206e345193..cc4bc16ae47 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -107,10 +107,11 @@ class Thirdparties extends DolibarrApi * Set to 2 to show only prospects * Set to 3 to show only those are not customer neither prospect * Set to 4 to show only suppliers + * @param int $category Use this param to filter list by category * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')" * @return array Array of thirdparty objects */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $sqlfilters = '') + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '') { global $db; @@ -126,15 +127,25 @@ class Thirdparties extends DolibarrApi $sql = "SELECT t.rowid"; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; - + if ($category > 0) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; $sql .= " WHERE t.fk_stcomm = st.id"; + $sql .= ' AND t.entity IN ('.getEntity('societe').')'; + if ($mode == 1) $sql .= " AND t.client IN (1, 3)"; if ($mode == 2) $sql .= " AND t.client IN (2, 3)"; if ($mode == 3) $sql .= " AND t.client IN (0)"; if ($mode == 4) $sql .= " AND t.fournisseur IN (1)"; - $sql .= ' AND t.entity IN ('.getEntity('societe').')'; + + // Select products of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category); + $sql .= " AND c.fk_soc = t.rowid "; + } + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; if ($socids) $sql .= " AND t.rowid IN (".$socids.")"; From 78c5011a7113288ce63fa538feb22770f8204e90 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 15 Apr 2020 16:20:42 +0000 Subject: [PATCH 2/8] Fixing style errors. --- htdocs/societe/class/api_thirdparties.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index cc4bc16ae47..3bf0749ca4d 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -128,24 +128,24 @@ class Thirdparties extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; $sql .= " WHERE t.fk_stcomm = st.id"; $sql .= ' AND t.entity IN ('.getEntity('societe').')'; - + if ($mode == 1) $sql .= " AND t.client IN (1, 3)"; if ($mode == 2) $sql .= " AND t.client IN (2, 3)"; if ($mode == 3) $sql .= " AND t.client IN (0)"; if ($mode == 4) $sql .= " AND t.fournisseur IN (1)"; - + // Select products of given category if ($category > 0) { - $sql .= " AND c.fk_categorie = ".$db->escape($category); - $sql .= " AND c.fk_soc = t.rowid "; + $sql .= " AND c.fk_categorie = ".$db->escape($category); + $sql .= " AND c.fk_soc = t.rowid "; } - + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; if ($socids) $sql .= " AND t.rowid IN (".$socids.")"; From d1957e1a05f231c005d7f43ce0aff2e140e45d0f Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 18:31:20 +0200 Subject: [PATCH 3/8] Update api_thirdparties.class.php --- htdocs/societe/class/api_thirdparties.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 3bf0749ca4d..bb72a8d3e7f 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -140,7 +140,7 @@ class Thirdparties extends DolibarrApi if ($mode == 3) $sql .= " AND t.client IN (0)"; if ($mode == 4) $sql .= " AND t.fournisseur IN (1)"; - // Select products of given category + // Select thirdparties of given category if ($category > 0) { $sql .= " AND c.fk_categorie = ".$db->escape($category); $sql .= " AND c.fk_soc = t.rowid "; From d05a00bd0a093b609d15fff2e9e99232ad2582ba Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 19:03:40 +0200 Subject: [PATCH 4/8] Update api_thirdparties.class.php --- htdocs/societe/class/api_thirdparties.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index bb72a8d3e7f..63130b8b1da 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -128,7 +128,8 @@ class Thirdparties extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + if (!in_array($mode, array(1,2,3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; @@ -142,8 +143,9 @@ class Thirdparties extends DolibarrApi // Select thirdparties of given category if ($category > 0) { - $sql .= " AND c.fk_categorie = ".$db->escape($category); - $sql .= " AND c.fk_soc = t.rowid "; + if ($mode != 4) $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid "; + elseif (!in_array($mode, array(1,2,3))) $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid "; + else $sql .= " AND (c.fk_categorie = ".$db->escape($category)." OR cc.fk_categorie = ".$db->escape($category).") AND cc.fk_soc = t.rowid AND c.fk_soc = t.rowid "; } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; From ec84303e8cc5d6b6ff36bbf1c5268acb14ec98ae Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 15 Apr 2020 17:05:37 +0000 Subject: [PATCH 5/8] Fixing style errors. --- htdocs/societe/class/api_thirdparties.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 63130b8b1da..a2d524acb49 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -128,8 +128,8 @@ class Thirdparties extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; if ($category > 0) { - if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; - if (!in_array($mode, array(1,2,3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; + if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + if (!in_array($mode, array(1,2,3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; @@ -143,9 +143,9 @@ class Thirdparties extends DolibarrApi // Select thirdparties of given category if ($category > 0) { - if ($mode != 4) $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid "; - elseif (!in_array($mode, array(1,2,3))) $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid "; - else $sql .= " AND (c.fk_categorie = ".$db->escape($category)." OR cc.fk_categorie = ".$db->escape($category).") AND cc.fk_soc = t.rowid AND c.fk_soc = t.rowid "; + if ($mode != 4) $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid "; + elseif (!in_array($mode, array(1,2,3))) $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid "; + else $sql .= " AND (c.fk_categorie = ".$db->escape($category)." OR cc.fk_categorie = ".$db->escape($category).") AND cc.fk_soc = t.rowid AND c.fk_soc = t.rowid "; } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; From d56785e9dce0425dc1c45909c7b27e0d20aaf00f Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 19:23:04 +0200 Subject: [PATCH 6/8] Update api_thirdparties.class.php --- htdocs/societe/class/api_thirdparties.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index a2d524acb49..b907749ee6a 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -128,8 +128,8 @@ class Thirdparties extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; if ($category > 0) { - if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; - if (!in_array($mode, array(1,2,3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; + if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + if (!in_array($mode, array(1,2,3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; @@ -143,9 +143,9 @@ class Thirdparties extends DolibarrApi // Select thirdparties of given category if ($category > 0) { - if ($mode != 4) $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid "; - elseif (!in_array($mode, array(1,2,3))) $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid "; - else $sql .= " AND (c.fk_categorie = ".$db->escape($category)." OR cc.fk_categorie = ".$db->escape($category).") AND cc.fk_soc = t.rowid AND c.fk_soc = t.rowid "; + if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid "; } + elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid "; } + else { $sql .= " AND ((c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid)) "; } } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; From 47069a057589c4067b05f816ce18b774fe33598a Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 19:24:16 +0200 Subject: [PATCH 7/8] Update api_thirdparties.class.php --- htdocs/societe/class/api_thirdparties.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index b907749ee6a..08b68e50f2c 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -133,8 +133,8 @@ class Thirdparties extends DolibarrApi } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; - $sql .= " WHERE t.fk_stcomm = st.id"; - $sql .= ' AND t.entity IN ('.getEntity('societe').')'; + $sql .= " WHERE t.entity IN ('.getEntity('societe').')"; + $sql .= " AND t.fk_stcomm = st.id"; if ($mode == 1) $sql .= " AND t.client IN (1, 3)"; if ($mode == 2) $sql .= " AND t.client IN (2, 3)"; @@ -143,9 +143,9 @@ class Thirdparties extends DolibarrApi // Select thirdparties of given category if ($category > 0) { - if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid "; } - elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid "; } - else { $sql .= " AND ((c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid)) "; } + if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid"; } + elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid"; } + else { $sql .= " AND ((c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid))"; } } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; From 63fa83e0c66ff706307da74e1d54051713fcf209 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 15 Apr 2020 17:25:49 +0000 Subject: [PATCH 8/8] Fixing style errors. --- htdocs/societe/class/api_thirdparties.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 08b68e50f2c..1100432c854 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -128,8 +128,8 @@ class Thirdparties extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; if ($category > 0) { - if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; - if (!in_array($mode, array(1,2,3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; + if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + if (!in_array($mode, array(1,2,3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; @@ -143,9 +143,9 @@ class Thirdparties extends DolibarrApi // Select thirdparties of given category if ($category > 0) { - if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid"; } - elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid"; } - else { $sql .= " AND ((c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid))"; } + if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid"; } + elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid"; } + else { $sql .= " AND ((c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid))"; } } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc";