From bd0079b3f1d37ae5568d96515415eb05f59718ec Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Mon, 23 Oct 2017 16:45:49 +0200 Subject: [PATCH] NEW Retrieve available discounts and payments details from an invoice Adds the ability to get availbales discounts and payments details of a specific invoice unsing the REST API. --- .../facture/class/api_invoices.class.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 344a5d280c7..475d3736741 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -19,6 +19,7 @@ use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + /** * API class for invoices * @@ -71,6 +72,25 @@ class Invoices extends DolibarrApi throw new RestException(404, 'Invoice not found'); } + // Get payment details + $this->invoice->totalpaye = $this->invoice->getSommePaiement(); + $this->invoice->totalcreditnotes = $this->invoice->getSumCreditNotesUsed(); + $this->invoice->totaldeposits = $this->invoice->getSumDepositsUsed(); + $this->invoice->resteapayer = price2num($this->invoice->total_ttc - $this->invoice->totalpaye - $this->invoice->totalcreditnotes - $this->invoice->totaldeposits, 'MT'); + + // get available discounts + $soc = new Societe($this->db); + if ($this->invoice->socid > 0) + $res = $soc->fetch($this->invoice->socid); + if($res) { + $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%'))"; + $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; + $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount); + $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote); + $this->invoice->absolute_discount = price2num($absolute_discount, 'MT'); + $this->invoice->absolute_creditnote = price2num($absolute_creditnote, 'MT'); + } + if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -421,7 +441,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 */