From b449d5f7e6d078cc949073508865301cd93ebae9 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 25 Oct 2019 17:14:00 +0200 Subject: [PATCH 1/2] NEW Get thirdparty's salesrepresentatives by API --- .../societe/class/api_thirdparties.class.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 1ed4916e3c9..a2385f0fb80 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -849,6 +849,46 @@ class Thirdparties extends DolibarrApi return $result; } + + /** + * Get representatives of thirdparty + * + * @param int $id ID of the thirdparty + * @param string $mode 0=Array with properties, 1=Array of id. + * + * @url GET {id}/representatives + * + * @return array List of representatives of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + */ + public function getSalesRepresentatives($id, $mode = 0) + { + $obj_ret = array(); + + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } + + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe', $id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + + $result = $this->company->getSalesRepresentatives(DolibarrApiAccess::$user, $mode); + + return $result; + } /** * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...) From 20b518d5272ecf9341546291000bbb16294bd933 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 25 Oct 2019 15:15:58 +0000 Subject: [PATCH 2/2] Fixing style errors. --- htdocs/societe/class/api_thirdparties.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index a2385f0fb80..6471ce61f38 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -849,7 +849,7 @@ class Thirdparties extends DolibarrApi return $result; } - + /** * Get representatives of thirdparty *