From 929804f4d2a4a6c1972ab1ad367349f91f8c833c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sun, 13 Sep 2020 15:12:22 +0200 Subject: [PATCH] Update api_invoices.class.php --- .../facture/class/api_invoices.class.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 53603415d7f..eed22f5d761 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1522,6 +1522,52 @@ class Invoices extends DolibarrApi return $paiement_id; } + + /** + * Update a payment + * + * @param int $id Id of payment + * @param string $num_paiement Payment number + * + * @url PUT payments/{id} + * + * @return array + * @throws 400 + * @throws 401 + * @throws 404 + */ + public function putPayment($id, $num_paiement = '') + { + require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; + + if (!DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + if (empty($id)) { + throw new RestException(400, 'Payment ID is mandatory'); + } + + $paiement = new Paiement($this->db); + $result = $paiement->fetch($id); + + if (!$result) { + throw new RestException(404, 'Paiement not found'); + } + + if (!empty($num_paiement)) { + $result = $paiement->update_num($num_paiement); + if ($result < 0) { + throw new RestException(500, 'Error when updating the payment num'); + } + } + + return [ + 'success' => [ + 'code' => 200, + 'message' => 'Payment updated' + ] + ]; + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /**