2
0
forked from Wavyzz/dolibarr

Compare commits

...

2 Commits

Author SHA1 Message Date
estebanthi
3c61da3212 API endpoint to mark invoice as paid 2025-10-11 15:11:39 +02:00
estebanthi
ce89584f76 Removed credit notes bug 2025-10-08 22:17:57 +02:00
2 changed files with 54 additions and 14 deletions

View File

@@ -1555,20 +1555,11 @@ class Invoices extends DolibarrApi
$amounts = array();
$multicurrency_amounts = array();
// Clean parameters amount if payment is for a credit note
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) {
$resteapayer = price2num($resteapayer, 'MT');
$amounts[$id] = (float) price2num(-1 * (float) $resteapayer, 'MT');
// Multicurrency
$newvalue = price2num($this->invoice->multicurrency_total_ttc, 'MT');
$multicurrency_amounts[$id] = (float) price2num(-1 * (float) $newvalue, 'MT');
} else {
$resteapayer = price2num($resteapayer, 'MT');
$amounts[$id] = (float) $resteapayer;
// Multicurrency
$newvalue = price2num($this->invoice->multicurrency_total_ttc, 'MT');
$multicurrency_amounts[$id] = (float) $newvalue;
}
$resteapayer = price2num($resteapayer, 'MT');
$amounts[$id] = (float) $resteapayer;
// Multicurrency
$newvalue = price2num($this->invoice->multicurrency_total_ttc, 'MT');
$multicurrency_amounts[$id] = (float) $newvalue;
// Creation of payment line
$paymentobj = new Paiement($this->db);

View File

@@ -594,6 +594,55 @@ class SupplierInvoices extends DolibarrApi
return $paiement_id;
}
/**
* Mark a supplier invoice as paid.
*
* @param int $id Supplier invoice ID
*
* @url POST {id}/setpaid
*
* @return object Updated invoice (cleaned)
*
* @throws RestException 400 Already paid
* @throws RestException 403 Not allowed
* @throws RestException 404 Not found
* @throws RestException 500 System error
*/
public function setpaid($id)
{
if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
throw new RestException(403);
}
if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
}
if ($this->invoice->fetch($id) <= 0) {
throw new RestException(404, 'Supplier invoice not found');
}
$alreadyPaid =
((int) ($this->invoice->paye ?? 0) === 1) ||
((int) ($this->invoice->paid ?? 0) === 1) ||
((int) ($this->invoice->fk_statut ?? -1) === 2) ||
((int) ($this->invoice->statut ?? -1) === 2) ||
((int) ($this->invoice->status ?? -1) === 2);
if ($alreadyPaid) {
throw new RestException(400, 'Invoice is already marked as paid');
}
$res = $this->invoice->setPaid(DolibarrApiAccess::$user);
if ($res <= 0) {
throw new RestException(500, 'Error when setting invoice as paid: ' . $this->invoice->error);
}
// Reload and return cleaned object
$this->invoice->fetch($id);
return $this->_cleanObjectDatas($this->invoice);
}
/**
* Get lines of a supplier invoice
*