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

@ -115,7 +115,7 @@ if ($action == 'valid' && $user->rights->facture->creer)
$invoice = new Facture($db);
$invoice->fetch($placeid);
if($invoice->total_ttc<0){
if ($invoice->total_ttc < 0) {
$invoice->type= $invoice::TYPE_CREDIT_NOTE;
$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE ";
$sql.="fk_soc = '".$invoice->socid."' ";
@ -153,8 +153,10 @@ if ($action == 'valid' && $user->rights->facture->creer)
$res = $invoice->validate($user);
}
$remaintopay = $invoice->getRemainToPay();
// Add the payment
if ($res > 0) {
if ($res >= 0 && $remaintopay > 0) {
$payment = new Paiement($db);
$payment->datepaye = $now;
$payment->fk_account = $bankaccount;
@ -166,9 +168,9 @@ if ($action == 'valid' && $user->rights->facture->creer)
$payment->create($user);
$payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
$remaintopay = $invoice->getRemainToPay();
$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 pay");
dol_syslog("Invoice is paid, so we set it to status Paid");
$result = $invoice->set_paid($user);
if ($result > 0) $invoice->paye = 1;
} else {