From f6f57aa938e9b702aa49f274a84655976aeac0c2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 Feb 2018 02:29:41 +0100 Subject: [PATCH] Missing Api for standing proposal/orders/invoices --- .../societe/class/api_thirdparties.class.php | 133 ++++++++++++++++++ htdocs/societe/class/societe.class.php | 6 +- 2 files changed, 136 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 9bc95c5e836..35301b06a07 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -551,6 +551,139 @@ class Thirdparties extends DolibarrApi } + + /** + * Get outstanding proposals of thirdparty + * + * @param int $id ID of the thirdparty + * @param string $mode 'customer' or 'supplier' + * + * @url GET {id}/outstandingproposals + * + * @return array List of outstandings proposals of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + */ + function getOutStandingProposals($id, $mode='customer') + { + $obj_ret = array(); + + if(! DolibarrApiAccess::$user->rights->societe->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->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + + $result = $this->company->getOutstandingProposals($mode); + + unset($result['total_ht']); + unset($result['total_ttc']); + + return $result; + } + + + /** + * Get outstanding orders of thirdparty + * + * @param int $id ID of the thirdparty + * @param string $mode 'customer' or 'supplier' + * + * @url GET {id}/outstandingorders + * + * @return array List of outstandings orders of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + */ + function getOutStandingOrder($id, $mode='customer') + { + $obj_ret = array(); + + if(! DolibarrApiAccess::$user->rights->societe->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->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + + $result = $this->company->getOutstandingOrders($mode); + + unset($result['total_ht']); + unset($result['total_ttc']); + + return $result; + } + + /** + * Get outstanding invoices of thirdparty + * + * @param int $id ID of the thirdparty + * @param string $mode 'customer' or 'supplier' + * + * @url GET {id}/outstandinginvoices + * + * @return array List of outstandings invoices of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + */ + function getOutStandingInvoices($id, $mode='customer') + { + $obj_ret = array(); + + if(! DolibarrApiAccess::$user->rights->societe->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->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + + $result = $this->company->getOutstandingBills($mode); + + unset($result['total_ht']); + unset($result['total_ttc']); + + return $result; + } + + + /** * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...) * diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index cc2e1fe50af..9883db3bec6 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3466,7 +3466,7 @@ class Societe extends CommonObject $outstandingOpened+=$obj->total_ttc; } } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' } else return array(); @@ -3506,7 +3506,7 @@ class Societe extends CommonObject $outstandingOpened+=$obj->total_ttc; } } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' } else return array(); @@ -3577,7 +3577,7 @@ class Societe extends CommonObject $outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits; } } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' } else {