From 6cafa0bd7dade670a71103419de58b30a510d37f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 10 Jan 2008 19:52:30 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Le=20chp=20date=20fin=20adh=E9sion=20n'?= =?UTF-8?q?=E9tait=20pas=20mis=20a=20jour=20par=20la=20fiche=20adh=E9sion?= =?UTF-8?q?=20en=20=E9dition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/adherents/adherent.class.php | 88 +++++++++++++++++++++------ htdocs/adherents/cotisation.class.php | 4 ++ 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index ce225360c3a..2546422a4b9 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -646,6 +646,59 @@ class Adherent extends CommonObject } + /** + \brief Fonction qui met a jour le chp denormalise date fin adhésion + \param user Utilisateur qui realise la mise a jour + \return int <0 si KO, >0 si OK + */ + function update_end_date($user) + { + global $conf, $langs; + + $error=0; + + $this->db->begin(); + + // Search for last subscription id and end date + $sql = "SELECT rowid, ".$this->db->pdate("datef")." as datef"; + $sql.= " FROM ".MAIN_DB_PREFIX."cotisation"; + $sql.= " WHERE fk_adherent='".$this->id."'"; + $sql.= " ORDER by dateadh DESC"; // Sort by start subscription date + + dolibarr_syslog("Adherent::update_end_date sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $obj=$this->db->fetch_object($resql); + $datefin=$obj->datef; + + $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; + $sql.= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null"); + $sql.= " WHERE rowid = ".$this->id; + + dolibarr_syslog("Adherent::update_end_date sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$this->db->lasterror(); + dolibarr_syslog("Adherent::update_end_date ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + + } + /** \brief Fonction qui supprime l'adherent et les donnees associees \param rowid Id de l'adherent a effacer @@ -1092,11 +1145,22 @@ class Adherent extends CommonObject $this->db->begin(); + if ($datesubend) + { + $datefin=$datesubend; + } + else + { + // If no end date, end date = date + 1 year - 1 day + $datefin = dolibarr_time_plus_duree($date,1,'y'); + $datefin = dolibarr_time_plus_duree($datefin,-1,'d'); + } + // Create subscription $cotisation=new Cotisation($this->db); $cotisation->fk_adherent=$this->id; $cotisation->dateh=$date; - $cotisation->datef=$datesubend; + $cotisation->datef=$datefin; $cotisation->amount=$montant; $cotisation->note=$label; @@ -1104,23 +1168,9 @@ class Adherent extends CommonObject if ($rowid > 0) { - if ($datesubend) - { - $datefin=$datesubend; - } - else - { - // If no end date, end date = date + 1 year - 1 day - $datefin = dolibarr_time_plus_duree($date,1,'y'); - $datefin = dolibarr_time_plus_duree($datefin,-1,'d'); - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin); - $sql.= " WHERE rowid =". $this->id; - - dolibarr_syslog("Adherent::cotisation update member sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) + // Update denormalized subscription end date + $result=$this->update_end_date($user); + if ($result > 0) { // Rajout du nouveau cotisant dans les listes qui vont bien if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin) @@ -1188,8 +1238,6 @@ class Adherent extends CommonObject } else { - $this->error=$this->db->error(); - dolibarr_syslog("Adherent::cotisation error ".$this->error); $this->db->rollback(); return -2; } diff --git a/htdocs/adherents/cotisation.class.php b/htdocs/adherents/cotisation.class.php index fe428813243..d814ca804b2 100644 --- a/htdocs/adherents/cotisation.class.php +++ b/htdocs/adherents/cotisation.class.php @@ -166,6 +166,10 @@ class Cotisation extends CommonObject $resql = $this->db->query($sql); if ($resql) { + $member=new Adherent($this->db); + $result=$member->fetch($this->fk_adherent); + $result=$member->update_end_date($user); + $this->db->commit(); return 1; }