NEW: API GET endpoint for thirdparties types listing (c_typent) (#34751)

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Jyhere
2025-07-18 00:56:10 +02:00
committed by GitHub
parent e59f2447e7
commit 91dd2e87ee

View File

@@ -2260,6 +2260,71 @@ class Setup extends DolibarrApi
return $list;
}
/**
* Get the list of thirdparties types.
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number (starting from zero)
* @param int $active Type is active or not {@min 0} {@max 1}
* @param string $lang Code of the language the label of the type must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of thirdparties types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/thirdparty_types
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 503 Error when retrieving list of thirdparties types
*/
public function getThirdpartiesTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
{
$list = array();
$sql = "SELECT id, code, libelle as label, fk_country, module, position";
$sql .= " FROM ".MAIN_DB_PREFIX."c_typent as t";
$sql .= " WHERE t.active = ".((int) $active);
// Add sql filters
if ($sqlfilters) {
$errormessage = '';
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
if ($errormessage) {
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
}
}
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
$sql .= $this->db->plimit($limit, $offset);
}
$result = $this->db->query($sql);
if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
for ($i = 0; $i < $min; $i++) {
$type = $this->db->fetch_object($result);
$this->translateLabel($type, $lang, '', array('companies'));
$list[] = $type;
}
} else {
throw new RestException(503, 'Error when retrieving list of thirdparty types : '.$this->db->lasterror());
}
return $list;
}
/**
* Get the list of incoterms.
*