diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 4c27ac54b58..e620d30e087 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -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 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 int $accountid {@from body} Account Id {@min 1} - * @param string $num_paiement {@from body} Payment number (optional) - * @param string $comment {@from body} Note (optional) + * @param string $num_payment {@from body} Payment number (optional) + * @param string $comment {@from body} Note private (optional) * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') * @param string $chqbank {@from body} Issuer bank name (optional) * @param string $ref_ext {@from body} External reference (optional) @@ -1413,12 +1413,12 @@ class Invoices extends DolibarrApi * @url POST /paymentsdistributed * * @return int Payment ID - * @throws 400 - * @throws 401 - * @throws 403 - * @throws 404 + * @throws RestException 400 + * @throws RestException 401 + * @throws RestException 403 + * @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; @@ -1441,8 +1441,8 @@ class Invoices extends DolibarrApi throw new RestException(400, 'Account ID is mandatory'); } } - if (empty($paiementid)) { - throw new RestException(400, 'Paiement ID or Paiement Code is mandatory'); + if (empty($paymentid)) { + throw new RestException(400, 'Payment ID or Payment Code is mandatory'); } $this->db->begin(); @@ -1504,38 +1504,38 @@ class Invoices extends DolibarrApi } // Creation of payment line - $paiement = new Paiement($this->db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id - $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->note = $comment; - $paiement->ref_ext = $ref_ext; - $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices - if ($paiement_id < 0) + $paymentobj = new Paiement($this->db); + $paymentobj->datepaye = $datepaye; + $paymentobj->amounts = $amounts; // Array with all payments dispatching with invoice id + $paymentobj->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching + $paymentobj->paiementid = $paymentid; + $paymentobj->paiementcode = dol_getIdFromCode($this->db, $paymentid, 'c_paiement', 'id', 'code', 1); + $paymentobj->num_paiement = $num_payment; + $paymentobj->note = $comment; + $paymentobj->ref_ext = $ref_ext; + $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices + if ($payment_id < 0) { $this->db->rollback(); - throw new RestException(400, 'Payment error : '.$paiement->error); + throw new RestException(400, 'Payment error : '.$paymentobj->error); } if (!empty($conf->banque->enabled)) { $label = '(CustomerInvoicePayment)'; - if ($paiement->paiementcode == 'CHQ' && empty($chqemetteur)) { - throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paiement->paiementcode); + if ($paymentobj->paiementcode == 'CHQ' && empty($chqemetteur)) { + 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 - $result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank); + $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank); if ($result < 0) { $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(); - return $paiement_id; + return $payment_id; } /**