diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 8583b52ca97..fcc16a89cfe 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -89,13 +89,9 @@ if ($action == 'setcustomeraccountancycode') if ($action == 'setconditions' && $user->rights->societe->creer) { $object->fetch($id); - $object->cond_reglement=$_POST['cond_reglement_id']; - - // TODO move to DAO class - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET cond_reglement='".$_POST['cond_reglement_id']; - $sql.= "' WHERE rowid='".$id."'"; - $result = $db->query($sql); - if (! $result) dol_print_error($result); + $object->cond_reglement=GETPOST('cond_reglement_id','int'); + $result=$object->setPaymentTerms($object->cond_reglement); + if ($result < 0) dol_print_error($db,$object->error); } // mode de reglement if ($action == 'setmode' && $user->rights->societe->creer) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8a4640f3562..974b55ca332 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -871,8 +871,12 @@ abstract class CommonObject function setPaymentTerms($id) { dol_syslog(get_class($this).'::setPaymentTerms('.$id.')'); - if ($this->statut >= 0) - { + if ($this->statut >= 0 || $this->element == 'societe') + { + // TODO uniformize field name + $fieldname = 'fk_cond_reglement'; + if ($this->element == 'societe') $fieldname = 'cond_reglement'; + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' SET fk_cond_reglement = '.$id; $sql .= ' WHERE rowid='.$this->id;