diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 8d6eb7a46f2..e79ef595a41 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2023 Joachim Kueter * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024-2025 MDW + * Copyright (C) 2025 Charlene Benke * * 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 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 *