From 0a43a124202f69fc3bcbe963b0589d7682abdea9 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Tue, 24 Oct 2017 10:50:38 +0200 Subject: [PATCH] NEW Get a payment list of a given invoice using the REST API Add the getpayments method to retrieve a list of payments of a given invoice --- .../facture/class/api_invoices.class.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index f3bb3c6480e..ae2ab7a94ea 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -665,6 +665,47 @@ class Invoices extends DolibarrApi } + /** + * Get a payment list of a given invoice + * + * @param int $id Id of invoice + * + * @url GET {id}/getpayments + * + * @return array + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function getPayments($id) { + + if(! DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Invoice 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); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + + $result = $this->invoice->getListOfPayments(); + if( $result < 0) { + throw new RestException(405, $this->invoice->error); + } + + return $result; + } + + + /** * Clean sensible object datas *