FIX Payment was not saved on TakePOS module.

This commit is contained in:
Laurent Destailleur 2019-10-17 12:28:48 +02:00
parent 084ab53b4b
commit e709c005a0

View File

@ -153,8 +153,10 @@ if ($action == 'valid' && $user->rights->facture->creer)
$res = $invoice->validate($user); $res = $invoice->validate($user);
} }
$remaintopay = $invoice->getRemainToPay();
// Add the payment // Add the payment
if ($res > 0) { if ($res >= 0 && $remaintopay > 0) {
$payment = new Paiement($db); $payment = new Paiement($db);
$payment->datepaye = $now; $payment->datepaye = $now;
$payment->fk_account = $bankaccount; $payment->fk_account = $bankaccount;
@ -166,9 +168,9 @@ if ($action == 'valid' && $user->rights->facture->creer)
$payment->create($user); $payment->create($user);
$payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
$remaintopay = $invoice->getRemainToPay(); $remaintopay = $invoice->getRemainToPay(); // Recalculate remain to pay after the payment is recorded
if ($remaintopay == 0) { if ($remaintopay == 0) {
dol_syslog("Invoice is paid, so we set it to pay"); dol_syslog("Invoice is paid, so we set it to status Paid");
$result = $invoice->set_paid($user); $result = $invoice->set_paid($user);
if ($result > 0) $invoice->paye = 1; if ($result > 0) $invoice->paye = 1;
} else { } else {