Update api_invoices.class.php

This commit is contained in:
Cédric 2020-09-13 15:12:22 +02:00 committed by GitHub
parent f9af7bc114
commit 929804f4d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
/**