From 1795ec6a9dc3ffa16792598ac97cf51de3781a5b Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 22 Oct 2020 16:11:12 +0200 Subject: [PATCH] FIX: supplier invoice: autoatically calculate payment term when modifying payment condition --- htdocs/fourn/facture/card.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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