diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 97fd311a295..58a989c97d1 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -989,7 +989,7 @@ else if ($action == 'setdemandreason') else if ($action == 'setconditions') { $object->fetch($id); - $result = $object->cond_reglement($_POST['cond_reglement_id']); + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id','int')); } else if ($action == 'setremisepercent' && $user->rights->propale->creer) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 0eac6928c88..53d25bce4b0 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1886,6 +1886,7 @@ class Propal extends CommonObject * * @param int $cond_reglement_id Id of new payment condition * @return int >0 if OK, <0 if KO + * TODO deprecated */ function cond_reglement($cond_reglement_id) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index a828997f3a7..15fcee6efce 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1980,6 +1980,7 @@ class Commande extends CommonObject * * @param int $cond_reglement_id Id de la nouvelle condition de reglement * @return int >0 if OK, <0 if KO + * TODO deprecated */ function cond_reglement($cond_reglement_id) { diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 86a33feb3f6..cbe513e87ae 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -470,7 +470,7 @@ if ($action == 'setdemandreason' && $user->rights->commande->creer) if ($action == 'setconditions' && $user->rights->commande->creer) { $object->fetch($id); - $result=$object->cond_reglement($_POST['cond_reglement_id']); + $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); if ($result < 0) dol_print_error($db,$object->error); } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 9e0fb858902..c0b294ee6cd 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -267,6 +267,7 @@ if ($action == 'setinvoicedate') if ($result < 0) dol_print_error($db,$object->error); } +// TODO obsolete ? not used if ($action == 'setpaymentterm') { $object->fetch($id); @@ -278,7 +279,7 @@ if ($action == 'setpaymentterm') if ($action == 'setconditions') { $object->fetch($id); - $result=$object->cond_reglement($_POST['cond_reglement_id']); + $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); if ($result < 0) dol_print_error($db,$object->error); } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index a31a84c50f0..2db61ecbcd9 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2692,6 +2692,7 @@ class Facture extends CommonObject * @param int $cond_reglement_id Id de la nouvelle condition de reglement * @param date $date Date to force payment term * @return int >0 si ok, <0 si ko + * TODO deprecated, not used */ function cond_reglement($cond_reglement_id,$date='') { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 68e9a6d3270..8a4640f3562 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -861,8 +861,42 @@ abstract class CommonObject return -1; } } - - + + /** + * Change the payments terms + * + * @param int $id Id of new payment terms + * @return int >0 if OK, <0 if KO + */ + function setPaymentTerms($id) + { + dol_syslog(get_class($this).'::setPaymentTerms('.$id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' SET fk_cond_reglement = '.$id; + $sql .= ' WHERE rowid='.$this->id; + + if ($this->db->query($sql)) + { + $this->cond_reglement_id = $id; + return 1; + } + else + { + dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); + $this->error=$this->db->error(); + return -1; + } + } + else + { + dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); + $this->error='Status of the object is incompatible '.$this->statut; + return -2; + } + } + /** * Set last model used by doc generator * diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 48b876b92b2..a6085b556b3 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -115,7 +115,7 @@ if ($action == 'setconditions' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($id); - $result=$commande->cond_reglement(GETPOST('mode_reglement_id','int')); + $result=$commande->setPaymentTerms(GETPOST('cond_reglement_id','int')); if ($result < 0) dol_print_error($db,$commande->error); } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 685009b19cb..9e70f8214ba 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1305,6 +1305,7 @@ class CommandeFournisseur extends Commande * * @param int $cond_reglement_id Id de la nouvelle condition de reglement * @return int >0 si ok, <0 si ko + * TODO deprecated */ function cond_reglement($cond_reglement_id) { diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index f9e3147efa9..555238b179d 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -77,7 +77,7 @@ $object = new CommandeFournisseur($db); if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) { $object->fetch($id); - $result=$object->cond_reglement($_POST['cond_reglement_id']); + $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); } // mode de reglement