2
0
forked from Wavyzz/dolibarr

Integrate 'sqlfilterlines' in API for commande. (#26612)

Co-authored-by: christian.humpel <christian.humpel@gmail.com>
This commit is contained in:
Christian Humpel
2023-11-16 15:05:32 +01:00
committed by GitHub
parent d567bdaa53
commit df31421e86

View File

@@ -156,12 +156,13 @@ class Orders extends DolibarrApi
* @param int $page Page number
* @param string $thirdparty_ids Thirdparty ids to filter orders 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 $sqlfilterlines Other criteria to filter answers separated by a comma. Syntax example "(tl.fk_product:=:'17') and (tl.price:<:'250')"
* @return array Array of order objects
*
* @throws RestException 404 Not found
* @throws RestException 503 Error
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '')
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $sqlfilterlines = '')
{
global $db, $conf;
@@ -212,7 +213,16 @@ class Orders extends DolibarrApi
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
}
}
// Add sql filters for lines
if ($sqlfilterlines) {
$errormessage = '';
$sql .= " AND EXISTS (SELECT tl.rowid FROM ".MAIN_DB_PREFIX."commandedet AS tl WHERE tl.fk_commande = t.rowid";
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilterlines, $errormessage);
$sql .= ")";
if ($errormessage) {
throw new RestException(400, 'Error when validating parameter sqlfilterlines -> '.$errormessage);
}
}
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {