From 0c106cbc1211bbdc2b364c3ee4b2553b9f791c28 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 18:40:01 +0200 Subject: [PATCH 1/2] NEW API filter warehouses by categorie --- htdocs/product/stock/class/api_warehouses.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index f4df99e131e..fc1c43e343e 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -87,12 +87,13 @@ class Warehouses extends DolibarrApi * @param string $sortorder Sort order * @param int $limit Limit for list * @param int $page Page number + * @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.label:like:'WH-%') and (t.date_creation:<:'20160101')" * @return array Array of warehouse objects * * @throws RestException */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $category = 0, $sqlfilters = '') { global $db, $conf; @@ -104,7 +105,15 @@ class Warehouses extends DolibarrApi $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as t"; + if ($category > 0) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + } $sql .= ' WHERE t.entity IN ('.getEntity('stock').')'; + // Select warehouses of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category); + $sql .= " AND c.fk_warehouse = t.rowid "; + } // Add sql filters if ($sqlfilters) { From 7a8db9c7d96dac71b085de07f8b0adef62bed394 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 15 Apr 2020 16:41:42 +0000 Subject: [PATCH 2/2] Fixing style errors. --- htdocs/product/stock/class/api_warehouses.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index fc1c43e343e..0d244785479 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -106,13 +106,13 @@ class Warehouses extends DolibarrApi $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; } $sql .= ' WHERE t.entity IN ('.getEntity('stock').')'; // Select warehouses of given category if ($category > 0) { - $sql .= " AND c.fk_categorie = ".$db->escape($category); - $sql .= " AND c.fk_warehouse = t.rowid "; + $sql .= " AND c.fk_categorie = ".$db->escape($category); + $sql .= " AND c.fk_warehouse = t.rowid "; } // Add sql filters if ($sqlfilters)