From 925a86b2ba251d364bd1877b50fbf3354ed9b1ea Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Fri, 6 Oct 2017 20:49:58 +0200 Subject: [PATCH 1/2] NEW Delete a line of invoice using the REST API Adds the ability to delete a line of an invoice using the REST API Rename a post action with a "verb" --- .../facture/class/api_invoices.class.php | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index a1f76807ab6..c0e3b6bbfcc 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -305,6 +305,56 @@ class Invoices extends DolibarrApi } return $result; } + + /** + * Deletes a line of a given invoice + * + * @param int $id Id of invoice + * @param int $rowid Id of the line to delete + * + * @url DELETE {id}/deleteline + * + * @return array + * @throws 304 + * @throws 400 + * @throws 401 + * @throws 404 + */ + function deleteLine($id, $rowid) { + + if(! DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + if(empty($rowid)) { + throw new RestException(400, 'RowID is mandatory'); + } + + $result = $this->invoice->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + + + $result = $this->invoice->deleteline($rowid); + if( $result < 0) { + throw new RestException(304); + } + + $result = $this->invoice->fetch($id); + + if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->invoice->getLinesArray(); + $result = array(); + foreach ($this->invoice->lines as $line) { + array_push($result,$this->_cleanObjectDatas($line)); + } + return $result; + } + + + /** * Add a line to a given invoice @@ -314,7 +364,7 @@ class Invoices extends DolibarrApi * @param int $id Id of invoice * @param array $request_data Invoiceline data * - * @url POST {id}/lines + * @url POST {id}/addline * * @return int */ From 1b399dc8dd304308b00a867c717a1e5767108318 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 7 Oct 2017 13:28:04 +0200 Subject: [PATCH 2/2] Update api_invoices.class.php --- .../facture/class/api_invoices.class.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index c0e3b6bbfcc..4531a0587cc 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -310,9 +310,9 @@ class Invoices extends DolibarrApi * Deletes a line of a given invoice * * @param int $id Id of invoice - * @param int $rowid Id of the line to delete + * @param int $lineid Id of the line to delete * - * @url DELETE {id}/deleteline + * @url DELETE {id}/deleteline/{lineid} * * @return array * @throws 304 @@ -320,13 +320,17 @@ class Invoices extends DolibarrApi * @throws 401 * @throws 404 */ - function deleteLine($id, $rowid) { + function deleteLine($id, $lineid) { if(! DolibarrApiAccess::$user->rights->facture->creer) { throw new RestException(401); } - if(empty($rowid)) { - throw new RestException(400, 'RowID is mandatory'); + if(empty($lineid)) { + throw new RestException(400, 'Line ID is mandatory'); + } + + if( ! DolibarrApi::_checkAccessToResource('facture',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } $result = $this->invoice->fetch($id); @@ -334,17 +338,13 @@ class Invoices extends DolibarrApi throw new RestException(404, 'Invoice not found'); } - - $result = $this->invoice->deleteline($rowid); + $result = $this->invoice->deleteline($lineid); if( $result < 0) { throw new RestException(304); } $result = $this->invoice->fetch($id); - if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } $this->invoice->getLinesArray(); $result = array(); foreach ($this->invoice->lines as $line) {