From d1e0efc4663906551c4e5da489a001826bfc552a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Sat, 4 Oct 2025 20:01:57 +0200 Subject: [PATCH] NEW Add getcontacts on api of interventional and proposal (#35589) * Add getContacts method to retrieve contact information * Implement getContacts method for proposals Added a method to retrieve contacts associated with a proposal, including access checks and data cleaning. * Implement getContacts method for invoices Added a method to retrieve contacts associated with a specific invoice, including access checks and error handling. * Update api_proposals.class.php * Update api_invoices.class.php * Update api_interventions.class.php * Update api_interventions.class.php * Add method to set invoice as draft * Return contacts directly instead of cleaned data * Return raw contacts instead of cleaned data * Combine external and internal contacts in order list Merge external and internal contacts for orders. * Change return type from Object to array in API doc Updated return type in API documentation for contact information. * Change return type in api_orders.class.php docblock Updated return type in docblock to reflect array return. * Change return type from Object to array in API doc * Update api_orders.class.php * Update api_interventions.class.php * Update api_proposals.class.php * Update api_orders.class.php * Update api_interventions.class.php * Update api_interventions.class.php * Update api_interventions.class.php --------- Co-authored-by: Laurent Destailleur --- .../comm/propal/class/api_proposals.class.php | 35 ++++++++++++++ htdocs/commande/class/api_orders.class.php | 3 ++ .../class/api_interventions.class.php | 48 ++++++++++++++++--- 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 5a6bd277618..ae53c83c61d 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -655,6 +655,41 @@ class Proposals extends DolibarrApi throw new RestException(405, $this->propal->error); } } + /** + * Get contacts of given proposal + * + * Return an array with contact information + * + * @param int $id ID of proposal + * @param string $type Type of the proposal + * @return array Array of contacts associated + * + * @url GET {id}/contacts + * + * @throws RestException + */ + public function getContacts($id, $type = '') + { + if (!DolibarrApiAccess::$user->hasRight('propal', 'lire')) { + throw new RestException(403); + } + + $result = $this->propal->fetch($id); + if (!$result) { + throw new RestException(404, 'Proposal not found'); + } + + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $contacts = $this->propal->liste_contact(-1, 'external', 0, $type); + $socpeoples = $this->propal->liste_contact(-1, 'internal', 0, $type); + + $contacts = array_merge($contacts, $socpeoples); + + return $contacts; + } /** * Add (link) a contact to a commercial proposal diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 5cba8258a8d..053d01a10e7 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -607,6 +607,9 @@ class Orders extends DolibarrApi } $contacts = $this->commande->liste_contact(-1, 'external', 0, $type); + $socpeoples = $this->commande->liste_contact(-1, 'internal', 0, $type); + + $contacts = array_merge($contacts, $socpeoples); return $contacts; } diff --git a/htdocs/fichinter/class/api_interventions.class.php b/htdocs/fichinter/class/api_interventions.class.php index d9150a3620d..557e77e159a 100644 --- a/htdocs/fichinter/class/api_interventions.class.php +++ b/htdocs/fichinter/class/api_interventions.class.php @@ -732,13 +732,50 @@ class Interventions extends DolibarrApi return $this->_cleanObjectDatas($this->fichinter); } - /** + /** + * Get contacts of given interventional + * + * Return an array with contact information + * + * @param int $id ID of interventional + * @param string $type Type of the interventional + * @return array Object with cleaned properties + * + * @url GET {id}/contacts + * + * @throws RestException + */ + public function getContacts($id, $type = '') + { + if (!DolibarrApiAccess::$user->hasRight('ficheinter', 'lire')) { + throw new RestException(403); + } + + $result = $this->fichinter->fetch($id); + if (!$result) { + throw new RestException(404, 'Interventional not found'); + } + + if (!DolibarrApi::_checkAccessToResource('ficheinter', $this->fichinter->id)) { + throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $contacts = $this->fichinter->liste_contact(-1, 'external', 0, $type); + $socpeoples = $this->fichinter->liste_contact(-1, 'internal', 0, $type); + + $contacts = array_merge($contacts, $socpeoples); + + return $contacts; + } + + + /** * Delete a contact type of given interventional * - * @param int $id Id of interventional to update - * @param int $contactid Row key of the contact in the array contact_ids. - * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). - * @return Object Object with cleaned properties + * @param int $id Id of interventional to update + * @param int $contactid Row key of the contact in the array contact_ids. + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). + * @return Object Object deleted * * @url DELETE {id}/contact/{contactid}/{type} * @@ -792,7 +829,6 @@ class Interventions extends DolibarrApi */ public function updateInterventionalLine($id, $lineid, $request_data) { - $result = $this->fichinter->fetch($id); if (!$result) { throw new RestException(404, 'Interventional not found');