add getContacts method on invoice api (#35656)
* add getContacts method on invoice api Add the getContacts method to fetch both external and internal contacts for a given invoice. * Change return type from Object to array in API docs Updated return type in the documentation for the get contacts method. * Update api_invoices.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
parent
07518a6865
commit
0c2f6ea9b0
1 changed files with 37 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
|||
* Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
|
||||
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
|
||||
* Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -621,6 +622,42 @@ class Invoices extends DolibarrApi
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contacts of given invoice
|
||||
*
|
||||
* Return an array with contact information
|
||||
*
|
||||
* @param int $id ID of invoice
|
||||
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
|
||||
* @return array<int,mixed> Array with contact and user associated
|
||||
*
|
||||
* @url GET {id}/contacts
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
public function getContacts($id, $type = '')
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
|
||||
throw new RestException(403);
|
||||
}
|
||||
|
||||
$result = $this->invoice->fetch($id);
|
||||
if (!$result) {
|
||||
throw new RestException(404, 'Invoice not found');
|
||||
}
|
||||
|
||||
if (!DolibarrApi::_checkAccessToResource('facture', $this->invoice->id)) {
|
||||
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$contacts = $this->invoice->liste_contact(-1, 'external', 0, $type);
|
||||
$socpeoples = $this->invoice->liste_contact(-1, 'internal', 0, $type);
|
||||
|
||||
$contacts = array_merge($contacts, $socpeoples);
|
||||
|
||||
return $contacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a contact type of given invoice
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue