From f985b1ede6919ae3c2790b33a40ec5a24ae2ae4b Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Fri, 22 Sep 2017 12:00:54 +0200 Subject: [PATCH] NEW GET lines of an invoice in the REST API Adds the ability to get lines of an invoice using the REST API --- .../facture/class/api_invoices.class.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index f841fc80050..fc45d5fb246 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -276,6 +276,36 @@ class Invoices extends DolibarrApi ); } + /** + * Get lines of an invoice + * + * @param int $id Id of invoice + * + * @url GET {id}/lines + * + * @return array + */ + function getLines($id) { + if(! DolibarrApiAccess::$user->rights->facture->lire) { + throw new RestException(401); + } + + $result = $this->invoice->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + + 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; + } + /** * Validate an order *