From c68f717071cba21726653ac9cee4a6ff7df33a1a Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Fri, 10 Nov 2017 16:22:20 +0100 Subject: [PATCH] NEW Update availability Add the ability to update availability while updating an invoice using the REST API --- htdocs/commande/class/api_orders.class.php | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 60f1be1e00c..086379a3989 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -413,6 +413,12 @@ class Orders extends DolibarrApi $this->commande->$field = $value; } + // Update availability + if( isset($this->commande->availability_id) && !empty($this->commande->availability_id) ) { + if($this->commande->availability($this->commande->availability_id) < 0) + throw new RestException(400, 'Error while updating availability'); + } + if($this->commande->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) return $this->get($id); @@ -545,6 +551,50 @@ class Orders extends DolibarrApi ); } + /** + * Set an order to draft + * + * @param int $id Order ID + * + * @url POST {id}/settodraft + * + * @return array + */ + function settodraft($id) + { + 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->set_draft(DolibarrApiAccess::$user); + if ($result == 0) { + throw new RestException(304, 'Nothing done. May be object is already closed'); + } + if ($result < 0) { + throw new RestException(500, 'Error when closing Order: '.$this->commande->error); + } + + $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); + } + + $this->commande->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->commande); + } + /** * Clean sensible object datas