Added setToDraft method

This commit is contained in:
William Mead
2025-12-07 14:10:57 +01:00
parent a0960d78b4
commit df4e4bf8ff

View File

@@ -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
*