New: REST Api - GET /setup/dictionary/incoterms
This commit is contained in:
parent
9a5f19984b
commit
439f8d4bb4
@ -1682,6 +1682,68 @@ class Setup extends DolibarrApi
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of incoterms.
|
||||||
|
*
|
||||||
|
* @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 Payment term 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 ticket types
|
||||||
|
*
|
||||||
|
* @url GET dictionary/incoterms
|
||||||
|
*
|
||||||
|
* @throws RestException
|
||||||
|
*/
|
||||||
|
public function getListOfIncoterms($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
|
||||||
|
{
|
||||||
|
$list = array();
|
||||||
|
|
||||||
|
$sql = "SELECT rowid, code, active";
|
||||||
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms as t";
|
||||||
|
$sql .= " WHERE 1=1";
|
||||||
|
|
||||||
|
// Add sql filters
|
||||||
|
if ($sqlfilters) {
|
||||||
|
$errormessage = '';
|
||||||
|
if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
|
||||||
|
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
|
||||||
|
}
|
||||||
|
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
|
||||||
|
$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$list[] = $type;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new RestException(503, 'Error when retrieving list of incoterm types : '.$this->db->lasterror());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get properties of company
|
* Get properties of company
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user