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 1/4] 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 /** From 8d3bc3ee6f9e69ca4df88c0121bbf8d04bc26f23 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 13 Sep 2020 13:18:42 +0000 Subject: [PATCH 2/4] Fixing style errors. --- htdocs/compta/facture/class/api_invoices.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index eed22f5d761..0cb2a1f78fa 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1522,7 +1522,7 @@ class Invoices extends DolibarrApi return $paiement_id; } - + /** * Update a payment * @@ -1539,28 +1539,28 @@ class Invoices extends DolibarrApi 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, From dcdce246b1d24e2a87d9a162b18573dd4753c398 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 14 Sep 2020 00:26:16 +0200 Subject: [PATCH 3/4] Update api_invoices.class.php --- htdocs/compta/facture/class/api_invoices.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 0cb2a1f78fa..3b77d2ed8b2 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1496,7 +1496,7 @@ class Invoices extends DolibarrApi $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $paiement->paiementid = $paiementid; $paiement->paiementcode = dol_getIdFromCode($this->db, $paiementid, 'c_paiement', 'id', 'code', 1); - $paiement->num_paiement = $num_paiement; + $paiement->num_payment = $num_paiement; $paiement->note = $comment; $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices if ($paiement_id < 0) @@ -1527,7 +1527,7 @@ class Invoices extends DolibarrApi * Update a payment * * @param int $id Id of payment - * @param string $num_paiement Payment number + * @param string $num_payment Payment number * * @url PUT payments/{id} * @@ -1547,15 +1547,15 @@ class Invoices extends DolibarrApi throw new RestException(400, 'Payment ID is mandatory'); } - $paiement = new Paiement($this->db); - $result = $paiement->fetch($id); + $paymentobj = new Paiement($this->db); + $result = $paymentobj->fetch($id); if (!$result) { - throw new RestException(404, 'Paiement not found'); + throw new RestException(404, 'Payment not found'); } - if (!empty($num_paiement)) { - $result = $paiement->update_num($num_paiement); + if (!empty($num_payment)) { + $result = $paymentobj->update_num($num_payment); if ($result < 0) { throw new RestException(500, 'Error when updating the payment num'); } From e9d0869383e10ead5a80b5e9f17201802499d777 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 14 Sep 2020 00:28:43 +0200 Subject: [PATCH 4/4] Update api_invoices.class.php --- .../facture/class/api_invoices.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 3b77d2ed8b2..e620506a8e7 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1284,7 +1284,7 @@ class Invoices extends DolibarrApi * @param int $paiementid {@from body} Payment mode Id {@min 1} * @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no} * @param int $accountid {@from body} Account Id {@min 1} - * @param string $num_paiement {@from body} Payment number (optional) + * @param string $num_payment {@from body} Payment number (optional) * @param string $comment {@from body} Note (optional) * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') * @param string $chqbank {@from body} Issuer bank name (optional) @@ -1297,7 +1297,7 @@ class Invoices extends DolibarrApi * @throws RestException 401 * @throws RestException 404 */ - public function addPayment($id, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '') + public function addPayment($id, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '') { global $conf; @@ -1321,7 +1321,7 @@ class Invoices extends DolibarrApi } if (empty($paiementid)) { - throw new RestException(400, 'Paiement ID or Paiement Code is mandatory'); + throw new RestException(400, 'Payment ID or Payment Code is mandatory'); } @@ -1364,7 +1364,7 @@ class Invoices extends DolibarrApi $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $paiement->paiementid = $paiementid; $paiement->paiementcode = dol_getIdFromCode($this->db, $paiementid, 'c_paiement', 'id', 'code', 1); - $paiement->num_paiement = $num_paiement; + $paiement->num_payment = $num_payment; $paiement->note = $comment; $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices @@ -1404,7 +1404,7 @@ class Invoices extends DolibarrApi * @param int $paiementid {@from body} Payment mode Id {@min 1} * @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no} * @param int $accountid {@from body} Account Id {@min 1} - * @param string $num_paiement {@from body} Payment number (optional) + * @param string $num_payment {@from body} Payment number (optional) * @param string $comment {@from body} Note (optional) * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') * @param string $chqbank {@from body} Issuer bank name (optional) @@ -1418,7 +1418,7 @@ class Invoices extends DolibarrApi * @throws RestException 403 * @throws RestException 404 */ - public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '') + public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '') { global $conf; @@ -1442,7 +1442,7 @@ class Invoices extends DolibarrApi } } if (empty($paiementid)) { - throw new RestException(400, 'Paiement ID or Paiement Code is mandatory'); + throw new RestException(400, 'Payment ID or Payment Code is mandatory'); } $this->db->begin(); @@ -1496,7 +1496,7 @@ class Invoices extends DolibarrApi $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $paiement->paiementid = $paiementid; $paiement->paiementcode = dol_getIdFromCode($this->db, $paiementid, 'c_paiement', 'id', 'code', 1); - $paiement->num_payment = $num_paiement; + $paiement->num_payment = $num_payment; $paiement->note = $comment; $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices if ($paiement_id < 0) @@ -1536,7 +1536,7 @@ class Invoices extends DolibarrApi * @throws 401 * @throws 404 */ - public function putPayment($id, $num_paiement = '') + public function putPayment($id, $num_payment = '') { require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';