FIX set paid on total discount of a product in cash desk

This commit is contained in:
lvessiller 2020-09-30 15:09:45 +02:00
parent 019a825bf4
commit 259737f082

View File

@ -153,22 +153,23 @@ if ($action == 'valid' && $user->rights->facture->creer)
$res = $invoice->validate($user);
}
$remaintopay = $invoice->getRemainToPay();
// Add the payment
if ($res >= 0 && $remaintopay > 0) {
$payment = new Paiement($db);
$payment->datepaye = $now;
$payment->fk_account = $bankaccount;
$payment->amounts[$invoice->id] = $amountofpayment;
if ($res >= 0) {
$remaintopay = $invoice->getRemainToPay();
if ($remaintopay > 0) {
$payment = new Paiement($db);
$payment->datepaye = $now;
$payment->fk_account = $bankaccount;
$payment->amounts[$invoice->id] = $amountofpayment;
$payment->paiementid = $paiementid;
$payment->num_payment = $invoice->ref;
$payment->paiementid = $paiementid;
$payment->num_payment = $invoice->ref;
$payment->create($user);
$payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
$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);