Skip to content

Commit

Permalink
NEW Set a proposal to draft
Browse files Browse the repository at this point in the history
Set a proposal to draft
  • Loading branch information
Neil Orley committed Dec 15, 2017
1 parent f4e8ce0 commit 4c852d1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions htdocs/comm/propal/class/api_proposals.class.php
Expand Up @@ -466,6 +466,51 @@ function delete($id)

}

/**
* Set a proposal to draft
*
* @param int $id Order ID
*
* @url POST {id}/settodraft
*
* @return array
*/
function settodraft($id)
{
if(! DolibarrApiAccess::$user->rights->propal->creer) {
throw new RestException(401);
}
$result = $this->propal->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Proposal not found');
}

if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

$result = $this->propal->set_draft(DolibarrApiAccess::$user);
if ($result == 0) {
throw new RestException(304, 'Nothing done. May be object is already draft');
}
if ($result < 0) {
throw new RestException(500, 'Error : '.$this->propal->error);
}

$result = $this->propal->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Proposal not found');
}

if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

$this->propal->fetchObjectLinked();
return $this->_cleanObjectDatas($this->propal);
}


/**
* Validate a commercial proposal
*
Expand Down

0 comments on commit 4c852d1

Please sign in to comment.