|
@@ -233,29 +233,30 @@ if ($action == 'valid' && $user->rights->facture->creer)
|
|
|
// $conf->global->FACTURE_ADDON = $sav_FACTURE_ADDON;
|
|
|
//}
|
|
|
|
|
|
- $remaintopay = $invoice->getRemainToPay();
|
|
|
-
|
|
|
// Add the payment
|
|
|
- if (!$error && $res >= 0 && $remaintopay > 0) {
|
|
|
- $payment = new Paiement($db);
|
|
|
- $payment->datepaye = $now;
|
|
|
- $payment->fk_account = $bankaccount;
|
|
|
- $payment->amounts[$invoice->id] = $amountofpayment;
|
|
|
- if ($pay == 'cash') $payment->pos_change = price2num(GETPOST('excess', 'alpha'));
|
|
|
-
|
|
|
- // If user has not used change control, add total invoice payment
|
|
|
- // Or if user has used change control and the amount of payment is higher than remain to pay, add the remain to pay
|
|
|
- if ($amountofpayment == 0 || $amountofpayment > $remaintopay) $payment->amounts[$invoice->id] = $remaintopay;
|
|
|
-
|
|
|
- $payment->paiementid = $paiementid;
|
|
|
- $payment->num_payment = $invoice->ref;
|
|
|
-
|
|
|
- if ($pay != "delayed") {
|
|
|
- $payment->create($user);
|
|
|
- $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
|
|
|
+ if (!$error && $res >= 0) {
|
|
|
+ $remaintopay = $invoice->getRemainToPay();
|
|
|
+ if ($remaintopay > 0) {
|
|
|
+ $payment = new Paiement($db);
|
|
|
+ $payment->datepaye = $now;
|
|
|
+ $payment->fk_account = $bankaccount;
|
|
|
+ $payment->amounts[$invoice->id] = $amountofpayment;
|
|
|
+ if ($pay == 'cash') $payment->pos_change = price2num(GETPOST('excess', 'alpha'));
|
|
|
+
|
|
|
+ // If user has not used change control, add total invoice payment
|
|
|
+ // Or if user has used change control and the amount of payment is higher than remain to pay, add the remain to pay
|
|
|
+ if ($amountofpayment == 0 || $amountofpayment > $remaintopay) $payment->amounts[$invoice->id] = $remaintopay;
|
|
|
+
|
|
|
+ $payment->paiementid = $paiementid;
|
|
|
+ $payment->num_payment = $invoice->ref;
|
|
|
+
|
|
|
+ if ($pay != "delayed") {
|
|
|
+ $payment->create($user);
|
|
|
+ $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
|
|
|
+ $remaintopay = $invoice->getRemainToPay(); // Recalculate remain to pay after the payment is recorded
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- $remaintopay = $invoice->getRemainToPay(); // Recalculate remain to pay after the payment is recorded
|
|
|
if ($remaintopay == 0) {
|
|
|
dol_syslog("Invoice is paid, so we set it to status Paid");
|
|
|
$result = $invoice->set_paid($user);
|