Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2020-09-16 02:50:36 +02:00
commit ffa91451eb
3 changed files with 137 additions and 8 deletions

View File

@ -147,11 +147,13 @@ $sql .= " c.rowid as crowid, c.fk_type, c.subscription,";
$sql .= " c.dateadh, c.datef, c.datec as date_creation, c.tms as date_update,";
$sql .= " c.fk_bank as bank, c.note,";
$sql .= " b.fk_account";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
$sql .= " JOIN ".MAIN_DB_PREFIX."subscription as c on d.rowid = c.fk_adherent";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank=b.rowid";
$sql .= " WHERE d.rowid = c.fk_adherent";
$sql .= " AND d.entity IN (".getEntity('adherent').")";
if (isset($date_select) && $date_select != '') {
$sql .= " WHERE d.entity IN (".getEntity('adherent').")";
if (isset($date_select) && $date_select != '')
{
$sql .= " AND c.dateadh >= '".$date_select."-01-01 00:00:00'";
$sql .= " AND c.dateadh < '".($date_select + 1)."-01-01 00:00:00'";
}

View File

@ -4,7 +4,7 @@
* Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Neil Orley <neil.orley@oeris.fr>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018-2019 Thibault FOUCART <support@ptibogxiv.net>
* Copyright (C) 2018-2020 Thibault FOUCART <support@ptibogxiv.net>
*
*
* This program is free software; you can redistribute it and/or modify
@ -24,6 +24,7 @@
use Luracast\Restler\RestException;
require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/cstate.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
/**
@ -168,6 +169,107 @@ class Setup extends DolibarrApi
return $list;
}
/**
* Get the list of states/provinces.
*
* The names of the states will be translated to the given language if
* the $lang parameter is provided. The value of $lang must be a language
* code supported by Dolibarr, for example 'en_US' or 'fr_FR'.
* The returned list is sorted by state ID.
*
* @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 string $filter To filter the countries by name
* @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 countries
*
* @url GET dictionary/states
*
* @throws RestException
*/
public function getListOfStates($sortfield = "code_departement", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $sqlfilters = '')
{
$list = array();
// Note: The filter is not applied in the SQL request because it must
// be applied to the translated names, not to the names in database.
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_departements as t";
$sql .= " WHERE 1 = 1";
// Add sql filters
if ($sqlfilters)
{
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$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++) {
$obj = $this->db->fetch_object($result);
$state = new Cstate($this->db);
if ($state->fetch($obj->rowid) > 0) {
if (empty($filter) || stripos($state->label, $filter) !== false) {
$list[] = $this->_cleanObjectDatas($state);
}
}
}
} else {
throw new RestException(503, 'Error when retrieving list of states');
}
return $list;
}
/**
* Get state by ID.
*
* @param int $id ID of state
* @return array Array of cleaned object properties
*
* @url GET dictionary/states/{id}
*
* @throws RestException
*/
public function getStateByID($id)
{
return $this->_fetchCstate($id, '');
}
/**
* Get state by Code.
*
* @param string $code Code of state
* @return array Array of cleaned object properties
*
* @url GET dictionary/states/byCode/{code}
*
* @throws RestException
*/
public function getStateByCode($code)
{
return $this->_fetchCstate('', $code);
}
/**
* Get the list of countries.
*
@ -295,6 +397,29 @@ class Setup extends DolibarrApi
return $this->_fetchCcountry('', '', $iso, $lang);
}
/**
* Get state.
*
* @param int $id ID of state
* @param string $code Code of state
* @return array Array of cleaned object properties
*
* @throws RestException
*/
private function _fetchCstate($id, $code = '')
{
$state = new Cstate($this->db);
$result = $state->fetch($id, $code);
if ($result < 0) {
throw new RestException(503, 'Error when retrieving state : '.$state->error);
} elseif ($result == 0) {
throw new RestException(404, 'State not found');
}
return $this->_cleanObjectDatas($state);
}
/**
* Get country.
*

View File

@ -50,7 +50,7 @@ class Cstate // extends CommonObject
public $id;
public $code_departement;
public $code;
/**
* @var string
* @deprecated
@ -167,8 +167,10 @@ class Cstate // extends CommonObject
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->code_departement = $obj->code_departement;
$this->nom = $obj->nom;
$this->code_departement = $obj->code_departement; //deprecated
$this->code = $obj->code_departement;
$this->nom = $obj->nom; //deprecated
$this->name = $obj->nom;
$this->active = $obj->active;
}
$this->db->free($resql);