From 7faab635c46cf78588a827ff295bb3916d737b09 Mon Sep 17 00:00:00 2001 From: Fabian Volkers <33686912+FabianVolkers@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:36:22 +0200 Subject: [PATCH] Enable filtering by supplier order in `/receptions` API endpoint (#35601) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 Use reception email templates for receptions * ✨ LEFT JOIN reception with element_elemnt to allow filtering by supplier_order * 📝 Document supplier order filter for receptions endpoint * 🐛 Check for presence of el filter using regex to avoid duplicate lines * Update api_receptions.class.php --------- Co-authored-by: Laurent Destailleur --- htdocs/reception/class/api_receptions.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/reception/class/api_receptions.class.php b/htdocs/reception/class/api_receptions.class.php index e4ab8d369dc..b6f6b233d07 100644 --- a/htdocs/reception/class/api_receptions.class.php +++ b/htdocs/reception/class/api_receptions.class.php @@ -94,7 +94,7 @@ class Receptions extends DolibarrApi * @param int $limit Limit for list * @param int $page Page number * @param string $thirdparty_ids Thirdparty ids to filter receptions of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101'). (el.fk_source:=:123) allows filtering by supplier order id" * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names * @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0* * @return array Array of reception objects @@ -123,6 +123,9 @@ class Receptions extends DolibarrApi $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."reception AS t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields + if (preg_match("/el\.fk_source:=:\d+/", $sqlfilters)) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = t.rowid AND el.targettype = 'reception' AND el.sourcetype = 'order_supplier'"; + } $sql .= ' WHERE t.entity IN ('.getEntity('reception').')'; if ($socids) { $sql .= " AND t.fk_soc IN (".$this->db->sanitize($socids).")";