From a741a6bb3ea6ea08207df635d43079fb846d13b3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 27 Oct 2017 00:41:56 +0200 Subject: [PATCH] Update api_thirdparties.class.php --- .../societe/class/api_thirdparties.class.php | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index ee1fd17d39a..08e67919de9 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -340,14 +340,14 @@ class Thirdparties extends DolibarrApi /** - * Get exceptional discount of a thirdparty + * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...) * * @param int $id ID of the thirdparty * @param string $filter Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts {@choice none,available,used} * @param string $sortfield Sort field * @param string $sortorder Sort order * - * @url GET {id}/exceptionaldiscounts + * @url GET {id}/fixedamountdiscounts * * @return array List of deposit and credit notes * @@ -356,7 +356,7 @@ class Thirdparties extends DolibarrApi * @throws 404 * @throws 503 */ - function getExceptionalDiscount($id,$filter="none",$sortfield = "f.type", $sortorder = 'ASC') + function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC') { if(! DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); @@ -366,7 +366,7 @@ class Thirdparties extends DolibarrApi throw new RestException(400, 'Thirdparty ID is mandatory'); } - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -392,13 +392,53 @@ class Thirdparties extends DolibarrApi while ( $obj = $this->db->fetch_object($result) ) { $obj_ret[] = $obj; } - } return $obj_ret; } + /** + * Return list of invoices qualified to be corrected by a credit note. + * Invoices matching the following rules are returned + * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note + * + * @param int $id Id of thirdparty + * + * @url GET {id}/getinvoicesqualifiedforcreditnote + * + * @return array + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function getInvoicesQualifiedForCreditNote($id) { + + if(! DolibarrApiAccess::$user->rights->facture->lire) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + /*$result = $this->thirdparty->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + }*/ + + $result = $this->thirdparty->list_qualified_avoir_invoices($id); + if( $result < 0) { + throw new RestException(405, $this->thirdparty->error); + } + + return $result; + } + /** * Clean sensible object datas