NEW Insert a discount in a specific invoice using the REST API

Add ability to insert a discount in a specific invoice.
This commit is contained in:
Neil Orley 2017-10-25 14:41:12 +02:00
parent 0f98572c2b
commit 257acb6679

View File

@ -667,6 +667,49 @@ class Invoices extends DolibarrApi
}
/**
* Insert a discount in a specific invoice
*
* @param int $id Id of invoice
* @param int $discountId Id of discount
*
* @url POST {id}/adddiscount/{discountId}
*
* @return int
* @throws 400
* @throws 401
* @throws 404
* @throws 405
*/
function addDiscount($id, $discountId) {
if(! DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}
if(empty($id)) {
throw new RestException(400, 'Invoice ID is mandatory');
}
if(empty($discountId)) {
throw new RestException(400, 'Discount 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->insert_discount($discountId);
if( $result < 0) {
throw new RestException(405, $this->invoice->error);
}
return $result;
}
/**
* Get a payment list of a given invoice
*