This commit is contained in:
Frédéric FRANCE 2020-10-31 15:59:33 +01:00
parent a51d135c7b
commit 8bf2b1797c
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
3 changed files with 317 additions and 317 deletions

View File

@ -30,206 +30,206 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
class DolibarrApi
{
/**
* @var DoliDb $db Database object
*/
protected $db;
/**
* @var DoliDb $db Database object
*/
protected $db;
/**
* @var Restler $r Restler object
*/
public $r;
/**
* @var Restler $r Restler object
*/
public $r;
/**
* Constructor
*
* @param DoliDb $db Database handler
* @param string $cachedir Cache dir
* @param boolean $refreshCache Update cache
*/
public function __construct($db, $cachedir = '', $refreshCache = false)
{
global $conf, $dolibarr_main_url_root;
/**
* Constructor
*
* @param DoliDb $db Database handler
* @param string $cachedir Cache dir
* @param boolean $refreshCache Update cache
*/
public function __construct($db, $cachedir = '', $refreshCache = false)
{
global $conf, $dolibarr_main_url_root;
if (empty($cachedir)) $cachedir = $conf->api->dir_temp;
Defaults::$cacheDirectory = $cachedir;
if (empty($cachedir)) $cachedir = $conf->api->dir_temp;
Defaults::$cacheDirectory = $cachedir;
$this->db = $db;
$production_mode = (empty($conf->global->API_PRODUCTION_MODE) ? false : true);
$this->r = new Restler($production_mode, $refreshCache);
$this->db = $db;
$production_mode = (empty($conf->global->API_PRODUCTION_MODE) ? false : true);
$this->r = new Restler($production_mode, $refreshCache);
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
$urlwithouturlrootautodetect = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim(DOL_MAIN_URL_ROOT));
$urlwithrootautodetect = $urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url
$urlwithouturlrootautodetect = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim(DOL_MAIN_URL_ROOT));
$urlwithrootautodetect = $urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url
$this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect);
$this->r->setAPIVersion(1);
//$this->r->setSupportedFormats('json');
//$this->r->setSupportedFormats('jsonFormat');
}
$this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect);
$this->r->setAPIVersion(1);
//$this->r->setSupportedFormats('json');
//$this->r->setSupportedFormats('jsonFormat');
}
/**
* Executed method when API is called without parameter
*
* Display a short message an return a http code 200
*
* @return array
*/
/* Disabled, most APIs does not share same signature for method index
function index()
{
return array(
'success' => array(
'code' => 200,
'message' => __class__.' is up and running!'
)
);
}*/
/**
* Executed method when API is called without parameter
*
* Display a short message an return a http code 200
*
* @return array
*/
/* Disabled, most APIs does not share same signature for method index
function index()
{
return array(
'success' => array(
'code' => 200,
'message' => __class__.' is up and running!'
)
);
}*/
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
*
* @param Object $object Object to clean
* @return Object Object with cleaned properties
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
// Remove $db object property for object
unset($object->db);
unset($object->isextrafieldmanaged);
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
*
* @param Object $object Object to clean
* @return Object Object with cleaned properties
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
// Remove $db object property for object
unset($object->db);
unset($object->isextrafieldmanaged);
unset($object->ismultientitymanaged);
unset($object->restrictiononfksoc);
unset($object->table_rowid);
// Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses
unset($object->linkedObjects);
// Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses
unset($object->linkedObjects);
unset($object->fields);
unset($object->oldline);
unset($object->fields);
unset($object->oldline);
unset($object->error);
unset($object->errors);
unset($object->error);
unset($object->errors);
unset($object->ref_previous);
unset($object->ref_next);
unset($object->ref_int);
unset($object->ref_previous);
unset($object->ref_next);
unset($object->ref_int);
unset($object->projet); // Should be fk_project
unset($object->project); // Should be fk_project
unset($object->author); // Should be fk_user_author
unset($object->timespent_old_duration);
unset($object->timespent_id);
unset($object->timespent_duration);
unset($object->timespent_date);
unset($object->timespent_datehour);
unset($object->timespent_withhour);
unset($object->timespent_fk_user);
unset($object->timespent_note);
unset($object->fk_delivery_address);
unset($object->projet); // Should be fk_project
unset($object->project); // Should be fk_project
unset($object->author); // Should be fk_user_author
unset($object->timespent_old_duration);
unset($object->timespent_id);
unset($object->timespent_duration);
unset($object->timespent_date);
unset($object->timespent_datehour);
unset($object->timespent_withhour);
unset($object->timespent_fk_user);
unset($object->timespent_note);
unset($object->fk_delivery_address);
unset($object->statuts);
unset($object->statuts_short);
unset($object->statuts_logo);
unset($object->statuts_long);
unset($object->labelStatus);
unset($object->labelStatusShort);
unset($object->statuts);
unset($object->statuts_short);
unset($object->statuts_logo);
unset($object->statuts_long);
unset($object->labelStatus);
unset($object->labelStatusShort);
unset($object->stats_propale);
unset($object->stats_commande);
unset($object->stats_contrat);
unset($object->stats_facture);
unset($object->stats_commande_fournisseur);
unset($object->stats_reception);
unset($object->stats_mrptoconsume);
unset($object->stats_mrptoproduce);
unset($object->stats_propale);
unset($object->stats_commande);
unset($object->stats_contrat);
unset($object->stats_facture);
unset($object->stats_commande_fournisseur);
unset($object->stats_reception);
unset($object->stats_mrptoconsume);
unset($object->stats_mrptoproduce);
unset($object->element);
unset($object->fk_element);
unset($object->table_element);
unset($object->table_element_line);
unset($object->class_element_line);
unset($object->picto);
unset($object->element);
unset($object->fk_element);
unset($object->table_element);
unset($object->table_element_line);
unset($object->class_element_line);
unset($object->picto);
unset($object->fieldsforcombobox);
unset($object->fieldsforcombobox);
unset($object->skip_update_total);
unset($object->context);
unset($object->next_prev_filter);
unset($object->skip_update_total);
unset($object->context);
unset($object->next_prev_filter);
unset($object->region);
unset($object->region_code);
unset($object->region);
unset($object->region_code);
unset($object->libelle_statut);
unset($object->libelle_paiement);
unset($object->libelle_statut);
unset($object->libelle_paiement);
if ($object->table_element != 'ticket') {
unset($object->comments);
}
if ($object->table_element != 'ticket') {
unset($object->comments);
}
// Remove the $oldcopy property because it is not supported by the JSON
// encoder. The following error is generated when trying to serialize
// it: "Error encoding/decoding JSON: Type is not supported"
// Note: Event if this property was correctly handled by the JSON
// encoder, it should be ignored because keeping it would let the API
// have a very strange behavior: calling PUT and then GET on the same
// resource would give different results:
// PUT /objects/{id} -> returns object with oldcopy = previous version of the object
// GET /objects/{id} -> returns object with oldcopy empty
unset($object->oldcopy);
// Remove the $oldcopy property because it is not supported by the JSON
// encoder. The following error is generated when trying to serialize
// it: "Error encoding/decoding JSON: Type is not supported"
// Note: Event if this property was correctly handled by the JSON
// encoder, it should be ignored because keeping it would let the API
// have a very strange behavior: calling PUT and then GET on the same
// resource would give different results:
// PUT /objects/{id} -> returns object with oldcopy = previous version of the object
// GET /objects/{id} -> returns object with oldcopy empty
unset($object->oldcopy);
// If object has lines, remove $db property
if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
$nboflines = count($object->lines);
for ($i = 0; $i < $nboflines; $i++)
{
$this->_cleanObjectDatas($object->lines[$i]);
// If object has lines, remove $db property
if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
$nboflines = count($object->lines);
for ($i = 0; $i < $nboflines; $i++)
{
$this->_cleanObjectDatas($object->lines[$i]);
unset($object->lines[$i]->contact);
unset($object->lines[$i]->contact_id);
unset($object->lines[$i]->country);
unset($object->lines[$i]->country_id);
unset($object->lines[$i]->country_code);
unset($object->lines[$i]->mode_reglement_id);
unset($object->lines[$i]->mode_reglement_code);
unset($object->lines[$i]->mode_reglement);
unset($object->lines[$i]->cond_reglement_id);
unset($object->lines[$i]->cond_reglement_code);
unset($object->lines[$i]->cond_reglement);
unset($object->lines[$i]->fk_delivery_address);
unset($object->lines[$i]->fk_projet);
unset($object->lines[$i]->fk_project);
unset($object->lines[$i]->thirdparty);
unset($object->lines[$i]->user);
unset($object->lines[$i]->model_pdf);
unset($object->lines[$i]->modelpdf);
unset($object->lines[$i]->note_public);
unset($object->lines[$i]->note_private);
unset($object->lines[$i]->fk_incoterms);
unset($object->lines[$i]->label_incoterms);
unset($object->lines[$i]->location_incoterms);
unset($object->lines[$i]->name);
unset($object->lines[$i]->lastname);
unset($object->lines[$i]->firstname);
unset($object->lines[$i]->civility_id);
unset($object->lines[$i]->fk_multicurrency);
unset($object->lines[$i]->multicurrency_code);
unset($object->lines[$i]->shipping_method_id);
}
}
unset($object->lines[$i]->contact);
unset($object->lines[$i]->contact_id);
unset($object->lines[$i]->country);
unset($object->lines[$i]->country_id);
unset($object->lines[$i]->country_code);
unset($object->lines[$i]->mode_reglement_id);
unset($object->lines[$i]->mode_reglement_code);
unset($object->lines[$i]->mode_reglement);
unset($object->lines[$i]->cond_reglement_id);
unset($object->lines[$i]->cond_reglement_code);
unset($object->lines[$i]->cond_reglement);
unset($object->lines[$i]->fk_delivery_address);
unset($object->lines[$i]->fk_projet);
unset($object->lines[$i]->fk_project);
unset($object->lines[$i]->thirdparty);
unset($object->lines[$i]->user);
unset($object->lines[$i]->model_pdf);
unset($object->lines[$i]->modelpdf);
unset($object->lines[$i]->note_public);
unset($object->lines[$i]->note_private);
unset($object->lines[$i]->fk_incoterms);
unset($object->lines[$i]->label_incoterms);
unset($object->lines[$i]->location_incoterms);
unset($object->lines[$i]->name);
unset($object->lines[$i]->lastname);
unset($object->lines[$i]->firstname);
unset($object->lines[$i]->civility_id);
unset($object->lines[$i]->fk_multicurrency);
unset($object->lines[$i]->multicurrency_code);
unset($object->lines[$i]->shipping_method_id);
}
}
if (!empty($object->thirdparty) && is_object($object->thirdparty))
{
$this->_cleanObjectDatas($object->thirdparty);
}
if (!empty($object->thirdparty) && is_object($object->thirdparty))
{
$this->_cleanObjectDatas($object->thirdparty);
}
dol_syslog(print_r($object, true), LOG_NOTICE);
return $object;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Check user access to a resource
*
@ -241,12 +241,12 @@ class DolibarrApi
* @param string $feature2 Feature to check, second level of permission (optional). Can be or check with 'level1|level2'.
* @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional)
* @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional)
* @return bool
* @return bool
* @throws RestException
*/
protected static function _checkAccessToResource($resource, $resource_id = 0, $dbtablename = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid')
{
// phpcs:enable
protected static function _checkAccessToResource($resource, $resource_id = 0, $dbtablename = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid')
{
// phpcs:enable
// Features/modules to check
$featuresarray = array($resource);
if (preg_match('/&/', $resource)) {
@ -261,9 +261,9 @@ class DolibarrApi
}
return checkUserAccessToObject(DolibarrApiAccess::$user, $featuresarray, $resource_id, $dbtablename, $feature2, $dbt_keyfield, $dbt_select);
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Return if a $sqlfilters parameter is valid
*
@ -272,30 +272,30 @@ class DolibarrApi
*/
protected function _checkFilters($sqlfilters)
{
// phpcs:enable
//$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
//$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters);
$tmp = $sqlfilters;
$ok = 0;
$i = 0; $nb = strlen($tmp);
$counter = 0;
while ($i < $nb)
{
if ($tmp[$i] == '(') $counter++;
if ($tmp[$i] == ')') $counter--;
if ($counter < 0)
{
$error = "Bad sqlfilters=".$sqlfilters;
dol_syslog($error, LOG_WARNING);
return false;
}
$i++;
}
return true;
// phpcs:enable
//$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
//$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters);
$tmp = $sqlfilters;
$ok = 0;
$i = 0; $nb = strlen($tmp);
$counter = 0;
while ($i < $nb)
{
if ($tmp[$i] == '(') $counter++;
if ($tmp[$i] == ')') $counter--;
if ($counter < 0)
{
$error = "Bad sqlfilters=".$sqlfilters;
dol_syslog($error, LOG_WARNING);
return false;
}
$i++;
}
return true;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Function to forge a SQL criteria
*
@ -304,22 +304,22 @@ class DolibarrApi
*/
protected static function _forge_criteria_callback($matches)
{
// phpcs:enable
global $db;
// phpcs:enable
global $db;
//dol_syslog("Convert matches ".$matches[1]);
if (empty($matches[1])) return '';
$tmp = explode(':', $matches[1]);
if (count($tmp) < 3) return '';
//dol_syslog("Convert matches ".$matches[1]);
if (empty($matches[1])) return '';
$tmp = explode(':', $matches[1]);
if (count($tmp) < 3) return '';
$tmpescaped = $tmp[2];
$regbis = array();
if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis))
{
$tmpescaped = "'".$db->escape($regbis[1])."'";
} else {
$tmpescaped = $db->escape($tmpescaped);
}
return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped;
$tmpescaped = $tmp[2];
$regbis = array();
if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis))
{
$tmpescaped = "'".$db->escape($regbis[1])."'";
} else {
$tmpescaped = $db->escape($tmpescaped);
}
return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped;
}
}

View File

@ -45,7 +45,7 @@ class Thirdparties extends DolibarrApi
/**
* Constructor
*/
public function __construct()
public function __construct()
{
global $db, $conf;
$this->db = $db;
@ -72,10 +72,10 @@ class Thirdparties extends DolibarrApi
*
* @throws RestException
*/
public function get($id)
public function get($id)
{
return $this->_fetch($id);
}
return $this->_fetch($id);
}
/**
* Get properties of a thirdparty object by email.
@ -91,7 +91,7 @@ class Thirdparties extends DolibarrApi
*/
public function getByEmail($email)
{
return $this->_fetch('', '', '', '', '', '', '', '', '', '', $email);
return $this->_fetch('', '', '', '', '', '', '', '', '', '', $email);
}
/**
@ -108,7 +108,7 @@ class Thirdparties extends DolibarrApi
*/
public function getByBarcode($barcode)
{
return $this->_fetch('', '', '', $barcode);
return $this->_fetch('', '', '', $barcode);
}
/**
@ -128,8 +128,8 @@ class Thirdparties extends DolibarrApi
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')"
* @return array Array of thirdparty objects
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '')
{
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '')
{
global $db;
$obj_ret = array();
@ -144,10 +144,10 @@ class Thirdparties extends DolibarrApi
$sql = "SELECT t.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql .= " FROM ".MAIN_DB_PREFIX."societe as t";
if ($category > 0) {
if ($category > 0) {
if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c";
if (!in_array($mode, array(1, 2, 3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc";
}
}
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
$sql .= " WHERE t.entity IN (".getEntity('societe').")";
@ -158,12 +158,12 @@ class Thirdparties extends DolibarrApi
if ($mode == 3) $sql .= " AND t.client IN (0)";
if ($mode == 4) $sql .= " AND t.fournisseur IN (1)";
// Select thirdparties of given category
if ($category > 0) {
if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_soc = t.rowid"; }
elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$this->db->escape($category)." AND cc.fk_soc = t.rowid"; }
else { $sql .= " AND ((c.fk_categorie = ".$this->db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$this->db->escape($category)." AND cc.fk_soc = t.rowid))"; }
}
// Select thirdparties of given category
if ($category > 0) {
if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_soc = t.rowid"; }
elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$this->db->escape($category)." AND cc.fk_soc = t.rowid"; }
else { $sql .= " AND ((c.fk_categorie = ".$this->db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$this->db->escape($category)." AND cc.fk_soc = t.rowid))"; }
}
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc";
//if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
@ -202,7 +202,7 @@ class Thirdparties extends DolibarrApi
{
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0;
$i = 0;
while ($i < $min)
{
$obj = $this->db->fetch_object($result);
@ -227,7 +227,7 @@ class Thirdparties extends DolibarrApi
* @param array $request_data Request datas
* @return int ID of thirdparty
*/
public function post($request_data = null)
public function post($request_data = null)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -251,7 +251,7 @@ class Thirdparties extends DolibarrApi
* @param array $request_data Datas
* @return int
*/
public function put($id, $request_data = null)
public function put($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -291,7 +291,7 @@ class Thirdparties extends DolibarrApi
*
* @url PUT {id}/merge/{idtodelete}
*/
public function merge($id, $idtodelete)
public function merge($id, $idtodelete)
{
global $db, $hookmanager;
@ -443,7 +443,7 @@ class Thirdparties extends DolibarrApi
// External modules should update their ones too
if (!$errors)
{
$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
'soc_origin' => $soc_origin->id,
'soc_dest' => $object->id
), $soc_dest, $action);
@ -499,7 +499,7 @@ class Thirdparties extends DolibarrApi
* @param int $id Thirparty ID
* @return integer
*/
public function delete($id)
public function delete($id)
{
if (!DolibarrApiAccess::$user->rights->societe->supprimer) {
throw new RestException(401);
@ -511,9 +511,9 @@ class Thirdparties extends DolibarrApi
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->company->oldcopy = clone $this->company;
$this->company->oldcopy = clone $this->company;
return $this->company->delete($id);
}
}
/**
* Set new price level for the given thirdparty
@ -588,7 +588,7 @@ class Thirdparties extends DolibarrApi
*
* @url GET {id}/categories
*/
public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
{
if (!DolibarrApiAccess::$user->rights->categorie->lire) {
throw new RestException(401);
@ -627,7 +627,7 @@ class Thirdparties extends DolibarrApi
*
* @url POST {id}/categories/{category_id}
*/
public function addCategory($id, $category_id)
public function addCategory($id, $category_id)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -665,7 +665,7 @@ class Thirdparties extends DolibarrApi
*
* @url DELETE {id}/categories/{category_id}
*/
public function deleteCategory($id, $category_id)
public function deleteCategory($id, $category_id)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -706,7 +706,7 @@ class Thirdparties extends DolibarrApi
*
* @url GET {id}/supplier_categories
*/
public function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
public function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
{
if (!DolibarrApiAccess::$user->rights->categorie->lire) {
throw new RestException(401);
@ -745,7 +745,7 @@ class Thirdparties extends DolibarrApi
*
* @url POST {id}/supplier_categories/{category_id}
*/
public function addSupplierCategory($id, $category_id)
public function addSupplierCategory($id, $category_id)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -783,7 +783,7 @@ class Thirdparties extends DolibarrApi
*
* @url DELETE {id}/supplier_categories/{category_id}
*/
public function deleteSupplierCategory($id, $category_id)
public function deleteSupplierCategory($id, $category_id)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -826,7 +826,7 @@ class Thirdparties extends DolibarrApi
* @throws RestException 401
* @throws RestException 404
*/
public function getOutStandingProposals($id, $mode = 'customer')
public function getOutStandingProposals($id, $mode = 'customer')
{
$obj_ret = array();
@ -870,7 +870,7 @@ class Thirdparties extends DolibarrApi
* @throws RestException 401
* @throws RestException 404
*/
public function getOutStandingOrder($id, $mode = 'customer')
public function getOutStandingOrder($id, $mode = 'customer')
{
$obj_ret = array();
@ -913,7 +913,7 @@ class Thirdparties extends DolibarrApi
* @throws RestException 401
* @throws RestException 404
*/
public function getOutStandingInvoices($id, $mode = 'customer')
public function getOutStandingInvoices($id, $mode = 'customer')
{
$obj_ret = array();
@ -956,7 +956,7 @@ class Thirdparties extends DolibarrApi
* @throws RestException 401
* @throws RestException 404
*/
public function getSalesRepresentatives($id, $mode = 0)
public function getSalesRepresentatives($id, $mode = 0)
{
$obj_ret = array();
@ -999,7 +999,7 @@ class Thirdparties extends DolibarrApi
* @throws RestException 404
* @throws RestException 503
*/
public function getFixedAmountDiscounts($id, $filter = "none", $sortfield = "f.type", $sortorder = 'ASC')
public function getFixedAmountDiscounts($id, $filter = "none", $sortfield = "f.type", $sortorder = 'ASC')
{
$obj_ret = array();
@ -1057,8 +1057,8 @@ class Thirdparties extends DolibarrApi
* @throws RestException 404
* @throws RestException 405
*/
public function getInvoicesQualifiedForReplacement($id)
{
public function getInvoicesQualifiedForReplacement($id)
{
if (!DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401);
}
@ -1100,8 +1100,8 @@ class Thirdparties extends DolibarrApi
* @throws RestException 404
* @throws RestException 405
*/
public function getInvoicesQualifiedForCreditNote($id)
{
public function getInvoicesQualifiedForCreditNote($id)
{
if (!DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401);
}
@ -1136,8 +1136,8 @@ class Thirdparties extends DolibarrApi
*
* @url GET {id}/bankaccounts
*/
public function getCompanyBankAccount($id)
{
public function getCompanyBankAccount($id)
{
global $db, $conf;
if (!DolibarrApiAccess::$user->rights->facture->lire) {
@ -1214,7 +1214,7 @@ class Thirdparties extends DolibarrApi
*
* @url POST {id}/bankaccounts
*/
public function createCompanyBankAccount($id, $request_data = null)
public function createCompanyBankAccount($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -1257,7 +1257,7 @@ class Thirdparties extends DolibarrApi
*
* @url PUT {id}/bankaccounts/{bankaccount_id}
*/
public function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null)
public function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
@ -1301,8 +1301,8 @@ class Thirdparties extends DolibarrApi
*
* @url DELETE {id}/bankaccounts/{bankaccount_id}
*/
public function deleteCompanyBankAccount($id, $bankaccount_id)
{
public function deleteCompanyBankAccount($id, $bankaccount_id)
{
if (!DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401);
}
@ -1408,9 +1408,9 @@ class Thirdparties extends DolibarrApi
} else {
throw new RestException(500);
}
}
}
/**
/**
* Get a specific gateway attached to a thirdparty (by specifying the site key)
*
* @param int $id ID of thirdparty
@ -1422,8 +1422,8 @@ class Thirdparties extends DolibarrApi
*
* @url GET {id}/gateways/
*/
public function getSocieteAccounts($id, $site = null)
{
public function getSocieteAccounts($id, $site = null)
{
global $db, $conf;
if (!DolibarrApiAccess::$user->rights->societe->lire) {
@ -1499,7 +1499,7 @@ class Thirdparties extends DolibarrApi
*
* @url POST {id}/gateways
*/
public function createSocieteAccount($id, $request_data = null)
public function createSocieteAccount($id, $request_data = null)
{
global $db;
@ -1558,7 +1558,7 @@ class Thirdparties extends DolibarrApi
*
* @url PUT {id}/gateways/{site}
*/
public function putSocieteAccount($id, $site, $request_data = null)
public function putSocieteAccount($id, $site, $request_data = null)
{
global $db;
@ -1641,7 +1641,7 @@ class Thirdparties extends DolibarrApi
*
* @url PATCH {id}/gateways/{site}
*/
public function patchSocieteAccount($id, $site, $request_data = null)
public function patchSocieteAccount($id, $site, $request_data = null)
{
global $db;
@ -1694,8 +1694,8 @@ class Thirdparties extends DolibarrApi
*
* @url DELETE {id}/gateways/{site}
*/
public function deleteSocieteAccount($id, $site)
{
public function deleteSocieteAccount($id, $site)
{
global $db;
if (!DolibarrApiAccess::$user->rights->societe->creer) {
@ -1730,8 +1730,8 @@ class Thirdparties extends DolibarrApi
*
* @url DELETE {id}/gateways
*/
public function deleteSocieteAccounts($id)
{
public function deleteSocieteAccounts($id)
{
global $db;
if (!DolibarrApiAccess::$user->rights->societe->creer) {
@ -1767,7 +1767,7 @@ class Thirdparties extends DolibarrApi
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
*
@ -1775,8 +1775,8 @@ class Thirdparties extends DolibarrApi
* @return Object Object with cleaned properties
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
{
// phpcs:enable
$object = parent::_cleanObjectDatas($object);
unset($object->nom); // ->name already defined and nom deprecated
@ -1812,23 +1812,23 @@ class Thirdparties extends DolibarrApi
*
* @throws RestException
*/
private function _validate($data)
{
$thirdparty = array();
foreach (Thirdparties::$FIELDS as $field) {
if (!isset($data[$field]))
throw new RestException(400, "$field field missing");
$thirdparty[$field] = $data[$field];
}
return $thirdparty;
}
private function _validate($data)
{
$thirdparty = array();
foreach (Thirdparties::$FIELDS as $field) {
if (!isset($data[$field]))
throw new RestException(400, "$field field missing");
$thirdparty[$field] = $data[$field];
}
return $thirdparty;
}
/**
* Fetch properties of a thirdparty object.
*
* Return an array with thirdparty informations
*
* @param int $rowid Id of third party to load
/**
* Fetch properties of a thirdparty object.
*
* Return an array with thirdparty informations
*
* @param int $rowid Id of third party to load
* @param string $ref Reference of third party, name (Warning, this can return several records)
* @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr)
* @param string $barcode Barcode of third party to load
@ -1840,42 +1840,42 @@ class Thirdparties extends DolibarrApi
* @param string $idprof6 Prof id 6 of third party (Warning, this can return several records)
* @param string $email Email of third party (Warning, this can return several records)
* @param string $ref_alias Name_alias of third party (Warning, this can return several records)
* @return array|mixed data without useless information
*
* @throws RestException
*/
private function _fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '')
{
global $conf;
if (!DolibarrApiAccess::$user->rights->societe->lire) {
throw new RestException(401);
}
* @return array|mixed data without useless information
*
* @throws RestException
*/
private function _fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '')
{
global $conf;
if (!DolibarrApiAccess::$user->rights->societe->lire) {
throw new RestException(401);
}
if ($rowid == 0) {
$result = $this->company->initAsSpecimen();
} else {
$result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
}
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
} else {
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
}
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
} else {
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
}
$absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount);
$absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote);
$this->company->absolute_discount = price2num($absolute_discount, 'MT');
$this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT');
$absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount);
$absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote);
$this->company->absolute_discount = price2num($absolute_discount, 'MT');
$this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT');
return $this->_cleanObjectDatas($this->company);
}
return $this->_cleanObjectDatas($this->company);
}
}

View File

@ -562,7 +562,7 @@ class Users extends DolibarrApi
return $this->useraccount->delete(DolibarrApiAccess::$user);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
*
@ -571,7 +571,7 @@ class Users extends DolibarrApi
*/
protected function _cleanObjectDatas($object)
{
// phpcs:enable
// phpcs:enable
global $conf;
$object = parent::_cleanObjectDatas($object);