From 150f3ecfe3929b50c6c62433905a1fb17ed563b4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 13 Mar 2012 19:24:11 +0100 Subject: [PATCH] Fix: move method in common class --- htdocs/comm/propal.php | 2 +- htdocs/comm/propal/class/propal.class.php | 1 + htdocs/commande/class/commande.class.php | 1 + htdocs/commande/fiche.php | 2 +- htdocs/compta/facture.php | 3 +- htdocs/compta/facture/class/facture.class.php | 1 + htdocs/core/class/commonobject.class.php | 38 ++++++++++++++++++- htdocs/expedition/shipment.php | 2 +- .../class/fournisseur.commande.class.php | 1 + htdocs/fourn/commande/fiche.php | 2 +- 10 files changed, 46 insertions(+), 7 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 97fd311a2954a..58a989c97d103 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -989,7 +989,7 @@ 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 0eac6928c886a..53d25bce4b00c 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1886,6 +1886,7 @@ function delete($user, $notrigger=0) * * @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 a828997f3a789..15fcee6efced9 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1980,6 +1980,7 @@ function liste_array($brouillon=0, $user='') * * @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 86a33feb3f6eb..cbe513e87ae2a 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -470,7 +470,7 @@ 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 9e0fb858902b4..c0b294ee6cdf2 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -267,6 +267,7 @@ 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 == '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 a31a84c50f00f..2db61ecbcd9c3 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2692,6 +2692,7 @@ function info($id) * @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 68e9a6d32709f..8a4640f35626e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -861,8 +861,42 @@ function setProject($projectid) 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 48b876b92b2b5..a6085b556b367 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -115,7 +115,7 @@ { $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 685009b19cbe7..9e70f8214ba02 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1305,6 +1305,7 @@ function get_methodes_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 f9e3147efa997..555238b179d94 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -77,7 +77,7 @@ 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