mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-06 17:13:03 +01:00
Add API close to close an order
This commit is contained in:
@@ -387,7 +387,7 @@ class Orders extends DolibarrApi
|
||||
/**
|
||||
* Update order general fields (won't touch lines of order)
|
||||
*
|
||||
* @param int $id Id of commande to update
|
||||
* @param int $id Id of order to update
|
||||
* @param array $request_data Datas
|
||||
*
|
||||
* @return int
|
||||
@@ -498,6 +498,53 @@ class Orders extends DolibarrApi
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an order (Classify it as "Delivered")
|
||||
*
|
||||
* @param int $id Order ID
|
||||
* @param int $notrigger Disabled triggers
|
||||
*
|
||||
* @url POST {id}/close
|
||||
*
|
||||
* @return array
|
||||
* FIXME An error 403 is returned if the request has an empty body.
|
||||
* Error message: "Forbidden: Content type `text/plain` is not supported."
|
||||
* Workaround: send this in the body
|
||||
* {
|
||||
* "notrigger": 0
|
||||
* }
|
||||
*/
|
||||
function close($id, $notrigger=0)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->commande->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
$result = $this->commande->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Order not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
|
||||
if ($result == 0) {
|
||||
throw new RestException(500, 'Error nothing done. May be object is already closed');
|
||||
}
|
||||
if ($result < 0) {
|
||||
throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => array(
|
||||
'code' => 200,
|
||||
'message' => 'Order closed (Ref='.$this->commande->ref.')'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
*
|
||||
@@ -509,6 +556,10 @@ class Orders extends DolibarrApi
|
||||
$object = parent::_cleanObjectDatas($object);
|
||||
|
||||
unset($object->address);
|
||||
unset($object->barcode_type);
|
||||
unset($object->barcode_type_code);
|
||||
unset($object->barcode_type_label);
|
||||
unset($object->barcode_type_coder);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
@@ -557,9 +557,10 @@ class Commande extends CommonOrder
|
||||
* Close order
|
||||
*
|
||||
* @param User $user Objet user that close
|
||||
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function cloture($user)
|
||||
function cloture($user, $notrigger=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@@ -580,10 +581,13 @@ class Commande extends CommonOrder
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('ORDER_CLOSE',$user);
|
||||
if ($result < 0) $error++;
|
||||
// End call triggers
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('ORDER_CLOSE',$user);
|
||||
if ($result < 0) $error++;
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user