From 56a0a20bb34549ac4f23a3b9f8d950aa8ddc7332 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Feb 2019 00:27:29 +0100 Subject: [PATCH 1/5] Fix delete contact --- htdocs/comm/propal/class/api_proposals.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index a9bc15ef088..ca6a955565c 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -451,13 +451,13 @@ class Proposals extends DolibarrApi return $this->propal; } - /** + /** * Delete a contact type of given commercial proposal * * @param int $id Id of commercial proposal to update * @param int $rowid Row key of the contact in the array contact_ids. * - * @url DELETE {id}/contact/{lineid} + * @url DELETE {id}/contact/{rowid} * * @return int * @throws 401 From 1771ea8eaae300a674652e7af906f39271ea42ed Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Feb 2019 00:27:53 +0100 Subject: [PATCH 2/5] Update api_proposals.class.php --- htdocs/comm/propal/class/api_proposals.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index ca6a955565c..c72c54294ae 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -451,7 +451,7 @@ class Proposals extends DolibarrApi return $this->propal; } - /** + /** * Delete a contact type of given commercial proposal * * @param int $id Id of commercial proposal to update From 7ac47fabda3c49837255c590723f05f0ba3b6300 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Feb 2019 00:36:35 +0100 Subject: [PATCH 3/5] NEW link/delete contact in order object --- htdocs/commande/class/api_orders.class.php | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index acb2106065c..cbdce449a6f 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -399,6 +399,86 @@ class Orders extends DolibarrApi throw new RestException(405, $this->commande->error); } } + + /** + * Add a contact type of given order + * + * @param int $id Id of order to update + * @param int $contactid Id of contact to add + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER) + * + * @url POST {id}/contact/{contactid}/{type} + * + * @return int + * @throws 401 + * @throws 404 + */ + function postContact($id, $contactid, $type) + { + if(!DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } + + $result = $this->commande->fetch($id); + + if(!$result) { + throw new RestException(404, 'Order not found'); + } + + if (!in_array($type, array('BILLING', 'SHIPPING', 'CUSTOMER'), true)) { + throw new RestException(500, 'Availables types: BILLING, SHIPPING OR CUSTOMER'); + } + + if(!DolibarrApi::_checkAccessToResource('order', $this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->commande->add_contact($contactid, $type, 'external'); + + if (!$result) { + throw new RestException(500, 'Error when added the contact'); + } + + return $this->commande; + } + + /** + * Delete a contact type of given order + * + * @param int $id Id of order to update + * @param int $rowid Row key of the contact in the array contact_ids. + * + * @url DELETE {id}/contact/{rowid} + * + * @return int + * @throws 401 + * @throws 404 + * @throws 500 + */ + function deleteContact($id, $rowid) + { + if(!DolibarrApiAccess::$user->rights->comande->creer) { + throw new RestException(401); + } + + $result = $this->commande->fetch($id); + + if(!$result) { + throw new RestException(404, 'Order not found'); + } + + if(!DolibarrApi::_checkAccessToResource('order', $this->commande->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->commande->delete_contact($rowid); + + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } + + return $this->commande; + } /** * Update order general fields (won't touch lines of order) From 58a73e7b4c871f1dc76cf4a7bbf8f989d762583f Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Feb 2019 00:42:00 +0100 Subject: [PATCH 4/5] Update api_orders.class.php --- htdocs/commande/class/api_orders.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index cbdce449a6f..95fe3f55d0d 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -445,7 +445,7 @@ class Orders extends DolibarrApi /** * Delete a contact type of given order * - * @param int $id Id of order to update + * @param int $id Id of order to update * @param int $rowid Row key of the contact in the array contact_ids. * * @url DELETE {id}/contact/{rowid} @@ -457,7 +457,7 @@ class Orders extends DolibarrApi */ function deleteContact($id, $rowid) { - if(!DolibarrApiAccess::$user->rights->comande->creer) { + if(!DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } From 7f3f166a81df3b1bd7a9f501f0c27fd768958af0 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Feb 2019 00:44:40 +0100 Subject: [PATCH 5/5] NEW link/delete contact in invoice object --- .../facture/class/api_invoices.class.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index ec098bca224..af3626942de 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -372,6 +372,86 @@ class Invoices extends DolibarrApi throw new RestException(304, $this->invoice->error); } } + + /** + * Add a contact type of given invoice + * + * @param int $id Id of invoice to update + * @param int $contactid Id of contact to add + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER) + * + * @url POST {id}/contact/{contactid}/{type} + * + * @return int + * @throws 401 + * @throws 404 + */ + function postContact($id, $contactid, $type) + { + if(!DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + + $result = $this->facture->fetch($id); + + if(!$result) { + throw new RestException(404, 'Invoice not found'); + } + + if (!in_array($type, array('BILLING', 'SHIPPING', 'CUSTOMER'), true)) { + throw new RestException(500, 'Availables types: BILLING, SHIPPING OR CUSTOMER'); + } + + if(!DolibarrApi::_checkAccessToResource('invoice', $this->facture->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->facture->add_contact($contactid, $type, 'external'); + + if (!$result) { + throw new RestException(500, 'Error when added the contact'); + } + + return $this->facture; + } + + /** + * Delete a contact type of given invoice + * + * @param int $id Id of invoice to update + * @param int $rowid Row key of the contact in the array contact_ids. + * + * @url DELETE {id}/contact/{rowid} + * + * @return int + * @throws 401 + * @throws 404 + * @throws 500 + */ + function deleteContact($id, $rowid) + { + if(!DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + + $result = $this->facture->fetch($id); + + if(!$result) { + throw new RestException(404, 'Invoice not found'); + } + + if(!DolibarrApi::_checkAccessToResource('invoice', $this->facture->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->facture->delete_contact($rowid); + + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } + + return $this->facture; + } /** * Deletes a line of a given invoice