Merge pull request #15086 from ppenelon/develop

NEW Retrieve discount from invoice from API
This commit is contained in:
Laurent Destailleur 2020-10-22 15:45:09 +02:00 committed by GitHub
commit b96a59b089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -981,6 +981,45 @@ class Invoices extends DolibarrApi
return $this->_cleanObjectDatas($this->invoice);
}
/**
* Get discount from invoice
*
* @param int $id Id of invoice
*
* @url GET {id}/discount
*
* @return mixed
*/
public function getDiscount($id)
{
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
if (!DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401);
}
$result = $this->invoice->fetch($id);
if (!$result) {
throw new RestException(404, 'Invoice not found');
}
if (!DolibarrApi::_checkAccessToResource('facture', $this->invoice->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$discountcheck = new DiscountAbsolute($this->db);
$result = $discountcheck->fetch(0, $this->invoice->id);
if ($result == 0){
throw new RestException(404, 'Discount not found');
}
if ($result < 0){
throw new RestException(500, $discountcheck->error);
}
return parent::_cleanObjectDatas($discountcheck);
}
/**
* Create a discount (credit available) for a credit note or a deposit.
*