From f8bf7ade83703e2e0421fa0b62ccf2dfb14e9329 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 13 Mar 2012 20:01:10 +0100 Subject: [PATCH] Fix: move method in common class --- htdocs/comm/fiche.php | 12 ++---- 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 | 2 +- htdocs/compta/facture/class/facture.class.php | 1 + htdocs/core/class/commonobject.class.php | 43 ++++++++++++++++++- htdocs/expedition/shipment.php | 2 +- .../class/fournisseur.commande.class.php | 1 + htdocs/fourn/commande/fiche.php | 2 +- 11 files changed, 54 insertions(+), 15 deletions(-) diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index fcc16a89cfe..43cc72d58d9 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -89,21 +89,15 @@ if ($action == 'setcustomeraccountancycode') if ($action == 'setconditions' && $user->rights->societe->creer) { $object->fetch($id); - $object->cond_reglement=GETPOST('cond_reglement_id','int'); - $result=$object->setPaymentTerms($object->cond_reglement); + $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); if ($result < 0) dol_print_error($db,$object->error); } // mode de reglement if ($action == 'setmode' && $user->rights->societe->creer) { $object->fetch($id); - $object->mode_reglement=$_POST['mode_reglement_id']; - - // TODO move to DAO class - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET mode_reglement='".$_POST['mode_reglement_id']; - $sql.= "' WHERE rowid='".$id."'"; - $result = $db->query($sql); - if (! $result) dol_print_error($result); + $result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int')); + if ($result < 0) dol_print_error($db,$object->error); } // assujetissement a la TVA if ($action == 'setassujtva' && $user->rights->societe->creer) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 58a989c97d1..7ac7cec3de5 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1008,7 +1008,7 @@ else if ($action == 'setremiseabsolue' && $user->rights->propale->creer) else if ($action == 'setmode') { $object->fetch($id); - $result = $object->mode_reglement($_POST['mode_reglement_id']); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); } /* diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 53d25bce4b0..97bc0493f4b 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1922,6 +1922,7 @@ class Propal extends CommonObject * * @param int $mode_reglement_id Id of new payment mode * @return int >0 if OK, <0 if KO + * TODO deprecated */ function mode_reglement($mode_reglement_id) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 15fcee6efce..c67fc51de3f 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2016,6 +2016,7 @@ class Commande extends CommonObject * * @param int $mode Id du nouveau mode * @return int >0 si ok, <0 si ko + * TODO deprecated */ function mode_reglement($mode_reglement_id) { diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index cbe513e87ae..0cdaf1ce491 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -449,7 +449,7 @@ if ($action == 'setaddress' && $user->rights->commande->creer) if ($action == 'setmode' && $user->rights->commande->creer) { $object->fetch($id); - $result=$object->mode_reglement($_POST['mode_reglement_id']); + $result = $object->setPaymentMethods(GETPOST('mode_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 c0b294ee6cd..de4db61574c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -254,7 +254,7 @@ if ($action == 'classin') if ($action == 'setmode') { $object->fetch($id); - $result=$object->mode_reglement($_POST['mode_reglement_id']); + $result = $object->setPaymentMethods(GETPOST('mode_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 2db61ecbcd9..d5247846507 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2742,6 +2742,7 @@ class Facture extends CommonObject * * @param int $mode_reglement_id Id du nouveau mode * @return int >0 if OK, <0 if KO + * TODO deprecated */ function mode_reglement($mode_reglement_id) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 11e4550b9ba..8df1964c1de 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -862,6 +862,46 @@ abstract class CommonObject } } + /** + * Change the payments methods + * + * @param int $id Id of new payment method + * @return int >0 if OK, <0 if KO + */ + function setPaymentMethods($id) + { + dol_syslog(get_class($this).'::setPaymentMethods('.$id.')'); + if ($this->statut >= 0 || $this->element == 'societe') + { + // TODO uniformize field name + $fieldname = 'fk_mode_reglement'; + if ($this->element == 'societe') $fieldname = 'mode_reglement'; + + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' SET '.$fieldname.' = '.$id; + $sql .= ' WHERE rowid='.$this->id; + + if ($this->db->query($sql)) + { + $this->mode_reglement_id = $id; + $this->mode_reglement = $id; // for compatibility + return 1; + } + else + { + dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); + $this->error=$this->db->error(); + return -1; + } + } + else + { + dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); + $this->error='Status of the object is incompatible '.$this->statut; + return -2; + } + } + /** * Change the payments terms * @@ -883,7 +923,8 @@ abstract class CommonObject if ($this->db->query($sql)) { - $this->cond_reglement_id = $id; + $this->cond_reglement_id = $id; + $this->cond_reglement = $id; // for compatibility return 1; } else diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index a6085b556b3..a7d9837eccb 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -107,7 +107,7 @@ if ($action == 'setmode' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($id); - $result=$commande->mode_reglement(GETPOST('mode_reglement_id','int')); + $result = $commande->setPaymentMethods(GETPOST('mode_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 9e70f8214ba..acde026bdee 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1340,6 +1340,7 @@ class CommandeFournisseur extends Commande * * @param int $mode_reglement_id Id du nouveau mode * @return int >0 if OK, <0 if KO + * TODO deprecated */ function mode_reglement($mode_reglement_id) { diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 555238b179d..ac741e683f3 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -84,7 +84,7 @@ if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) if ($action == 'setmode' && $user->rights->fournisseur->commande->creer) { $object->fetch($id); - $result=$object->mode_reglement($_POST['mode_reglement_id']); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); } // Set project