Merge pull request #7691 from Oeris/develop-api
NEW Retrieves available discounts and payments details from a specific invoice
This commit is contained in:
commit
e9d851ef34
@ -71,6 +71,27 @@ class Invoices extends DolibarrApi
|
|||||||
throw new RestException(404, 'Invoice not found');
|
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 of customer
|
||||||
|
/* TODO Move this into thirdparty API
|
||||||
|
$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)) {
|
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
@ -646,6 +667,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->lire) {
|
||||||
|
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
|
* Clean sensible object datas
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user