NEW : Adds a contact to an invoice
Adds a contact to an invoice using the REST API
This commit is contained in:
parent
59d0e9a64f
commit
991d5c4215
@ -562,6 +562,59 @@ class Invoices extends DolibarrApi
|
||||
return $updateRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a contact to an invoice
|
||||
*
|
||||
* @param int $id Order ID
|
||||
* @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link
|
||||
* @param string $type_contact Type of contact (code). Must a code found into table llx_c_type_contact. For example: BILLING
|
||||
* @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
|
||||
* @param int $notrigger Disable all triggers
|
||||
*
|
||||
* @url POST {id}/contacts
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws 200
|
||||
* @throws 304
|
||||
* @throws 401
|
||||
* @throws 404
|
||||
* @throws 500
|
||||
*
|
||||
*/
|
||||
function addContact($id, $fk_socpeople, $type_contact, $source, $notrigger=0)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->facture->creer) {
|
||||
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);
|
||||
}
|
||||
|
||||
$result = $this->invoice->add_contact($fk_socpeople,$type_contact,$source,$notrigger);
|
||||
if ($result < 0) {
|
||||
throw new RestException(500, 'Error : '.$this->invoice->error);
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
return $this->_cleanObjectDatas($this->invoice);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets an invoice as draft
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user