diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 15df715664d..43b4757729c 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -325,7 +325,18 @@ if (empty($reshook)) // payments conditions if ($action == 'setconditions' && $user->rights->fournisseur->facture->creer) { - $result=$object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); + $object->fetch($id); + $object->cond_reglement_code = 0; // To clean property + $object->cond_reglement_id = 0; // To clean property + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); + if ($result < 0) dol_print_error($db, $object->error); + + $old_date_echeance = $object->date_echeance; + $new_date_echeance = $object->calculate_date_lim_reglement(); + if ($new_date_echeance > $old_date_echeance) $object->date_echeance = $new_date_echeance; + if ($object->date_echeance < $object->date) $object->date_echeance = $object->date; + $result = $object->update($user); + if ($result < 0) dol_print_error($db, $object->error); } // Set incoterm