forked from Wavyzz/dolibarr
Compare commits
2 Commits
phpstan-ba
...
22.0.2_wav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c61da3212 | ||
|
|
ce89584f76 |
@@ -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);
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user