mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 17:48:25 +01:00
NEW expense report API validate (#34499)
* Added expense report API validate * Cleaned code * Cleaned code
This commit is contained in:
@@ -547,49 +547,50 @@ class ExpenseReports extends DolibarrApi
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate an Expense Report
|
* Validate an expense report
|
||||||
*
|
*
|
||||||
* @param int $id Expense Report ID
|
* If you get a bad value for param notrigger check, provide this in body
|
||||||
|
* {
|
||||||
|
* "notrigger": 0
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @since 23.0.0 Initial implementation
|
||||||
|
*
|
||||||
|
* @param int $id Expense report ID
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||||
*
|
*
|
||||||
* @url POST {id}/validate
|
* @url POST {id}/validate
|
||||||
*
|
*
|
||||||
* @return array
|
* @return Object
|
||||||
* FIXME An error 403 is returned if the request has an empty body.
|
*
|
||||||
* Error message: "Forbidden: Content type `text/plain` is not supported."
|
* @throws RestException
|
||||||
* Workaround: send this in the body
|
|
||||||
* {
|
|
||||||
* "idwarehouse": 0
|
|
||||||
* }
|
|
||||||
*/
|
*/
|
||||||
/*
|
public function validate($id, $notrigger = 0)
|
||||||
public function validate($id, $idwarehouse=0)
|
|
||||||
{
|
{
|
||||||
if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
|
if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
|
||||||
throw new RestException(403);
|
throw new RestException(403, "Insuffisant rights");
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->expensereport->fetch($id);
|
$result = $this->expensereport->fetch($id);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
throw new RestException(404, 'expensereport not found');
|
throw new RestException(404, 'Expense report not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
|
if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
|
||||||
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! $this->expensereport->valid(DolibarrApiAccess::$user, $idwarehouse)) {
|
$result = $this->expensereport->setValidate(DolibarrApiAccess::$user, $notrigger);
|
||||||
throw new RestException(500, 'Error when validate expensereport');
|
if ($result == 0) {
|
||||||
|
throw new RestException(304, 'Error nothing done. May be object is already validated');
|
||||||
|
}
|
||||||
|
if ($result < 0) {
|
||||||
|
throw new RestException(500, 'Error when validating expense report: '.$this->expensereport->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
$this->expensereport->fetchObjectLinked();
|
||||||
'success' => array(
|
|
||||||
'code' => 200,
|
|
||||||
'message' => 'expensereport validated'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
return $this->_cleanObjectDatas($this->expensereport);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of payments of an expense report
|
* Get the list of payments of an expense report
|
||||||
|
|||||||
Reference in New Issue
Block a user