mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-07 17:42:53 +01:00
Added setToDraft method
This commit is contained in:
@@ -546,6 +546,46 @@ class ExpenseReports extends DolibarrApi
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an expense report to draft
|
||||
*
|
||||
* @since 23.0.0 Initial implementation
|
||||
*
|
||||
* @param int $id Expense report ID
|
||||
*
|
||||
* @url POST {id}/settodraft
|
||||
*
|
||||
* @return Object
|
||||
*
|
||||
* @throws RestException 304
|
||||
* @throws RestException 403
|
||||
* @throws RestException 404
|
||||
*/
|
||||
public function setToDraft($id)
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
|
||||
throw new RestException(403, "Insufficiant rights");
|
||||
}
|
||||
$result = $this->expensereport->fetch($id);
|
||||
if (!$result) {
|
||||
throw new RestException(404, 'Expense report not found');
|
||||
}
|
||||
|
||||
if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
|
||||
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$result = $this->expensereport->setStatut(0);
|
||||
if ($result == 0) {
|
||||
throw new RestException(304, 'Error nothing done. May be object is already draft');
|
||||
}
|
||||
if ($result < 0) {
|
||||
throw new RestException(500, 'Error when setting to draft expense report: '.$this->expensereport->error);
|
||||
}
|
||||
|
||||
return $this->_cleanObjectDatas($this->expensereport);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an expense report
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user