Update api_invoices.class.php

This commit is contained in:
Cédric 2020-09-19 15:12:57 +02:00 committed by GitHub
parent 9f22882417
commit a0efd47cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1401,11 +1401,11 @@ class Invoices extends DolibarrApi
* *
* @param array $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice * @param array $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice
* @param string $datepaye {@from body} Payment date {@type timestamp} * @param string $datepaye {@from body} Payment date {@type timestamp}
* @param int $paiementid {@from body} Payment mode Id {@min 1} * @param int $paymentid {@from body} Payment mode Id {@min 1}
* @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no} * @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no}
* @param int $accountid {@from body} Account Id {@min 1} * @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 $comment {@from body} Note private (optional)
* @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ')
* @param string $chqbank {@from body} Issuer bank name (optional) * @param string $chqbank {@from body} Issuer bank name (optional)
* @param string $ref_ext {@from body} External reference (optional) * @param string $ref_ext {@from body} External reference (optional)
@ -1413,12 +1413,12 @@ class Invoices extends DolibarrApi
* @url POST /paymentsdistributed * @url POST /paymentsdistributed
* *
* @return int Payment ID * @return int Payment ID
* @throws 400 * @throws RestException 400
* @throws 401 * @throws RestException 401
* @throws 403 * @throws RestException 403
* @throws 404 * @throws RestException 404
*/ */
public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '') public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '')
{ {
global $conf; global $conf;
@ -1441,8 +1441,8 @@ class Invoices extends DolibarrApi
throw new RestException(400, 'Account ID is mandatory'); throw new RestException(400, 'Account ID is mandatory');
} }
} }
if (empty($paiementid)) { if (empty($paymentid)) {
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(); $this->db->begin();
@ -1504,38 +1504,38 @@ class Invoices extends DolibarrApi
} }
// Creation of payment line // Creation of payment line
$paiement = new Paiement($this->db); $paymentobj = new Paiement($this->db);
$paiement->datepaye = $datepaye; $paymentobj->datepaye = $datepaye;
$paiement->amounts = $amounts; // Array with all payments dispatching with invoice id $paymentobj->amounts = $amounts; // Array with all payments dispatching with invoice id
$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $paymentobj->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
$paiement->paiementid = $paiementid; $paymentobj->paiementid = $paymentid;
$paiement->paiementcode = dol_getIdFromCode($this->db, $paiementid, 'c_paiement', 'id', 'code', 1); $paymentobj->paiementcode = dol_getIdFromCode($this->db, $paymentid, 'c_paiement', 'id', 'code', 1);
$paiement->num_paiement = $num_paiement; $paymentobj->num_paiement = $num_payment;
$paiement->note = $comment; $paymentobj->note = $comment;
$paiement->ref_ext = $ref_ext; $paymentobj->ref_ext = $ref_ext;
$paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices
if ($paiement_id < 0) if ($payment_id < 0)
{ {
$this->db->rollback(); $this->db->rollback();
throw new RestException(400, 'Payment error : '.$paiement->error); throw new RestException(400, 'Payment error : '.$paymentobj->error);
} }
if (!empty($conf->banque->enabled)) { if (!empty($conf->banque->enabled)) {
$label = '(CustomerInvoicePayment)'; $label = '(CustomerInvoicePayment)';
if ($paiement->paiementcode == 'CHQ' && empty($chqemetteur)) { if ($paymentobj->paiementcode == 'CHQ' && empty($chqemetteur)) {
throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paiement->paiementcode); throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
} }
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
$result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank); $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank);
if ($result < 0) if ($result < 0)
{ {
$this->db->rollback(); $this->db->rollback();
throw new RestException(400, 'Add payment to bank error : '.$paiement->error); throw new RestException(400, 'Add payment to bank error : '.$paymentobj->error);
} }
} }
$this->db->commit(); $this->db->commit();
return $paiement_id; return $payment_id;
} }
/** /**