From 30d585495eef04e79f229f398434431a470a6921 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 May 2009 03:23:56 +0000 Subject: [PATCH] Fix: When deleting a subscription, end date was not updated. --- htdocs/adherents/adherent.class.php | 23 +++++++++++++++++++---- htdocs/adherents/cotisation.class.php | 19 ++++++++++++------- htdocs/adherents/fiche_subscription.php | 4 ++-- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index c2d491c1f0e..4717fecb88f 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -96,6 +96,7 @@ class Adherent extends CommonObject var $fistsubscription_amount; var $lastsubscription_date; var $lastsubscription_amount; + var $subscriptions=array(); // var $public; var $array_options; @@ -937,9 +938,10 @@ class Adherent extends CommonObject global $langs; $sql = "SELECT c.rowid, c.fk_adherent, c.cotisation, c.note, c.fk_bank,"; - $sql.= " ".$this->db->pdate("c.tms")." as datem,"; - $sql.= " ".$this->db->pdate("c.datec")." as datec,"; - $sql.= " ".$this->db->pdate("c.dateadh")." as dateadh"; + $sql.= " c.tms as datem,"; + $sql.= " c.datec as datec,"; + $sql.= " c.dateadh as dateadh,"; + $sql.= " c.datef as datef"; $sql.= " FROM ".MAIN_DB_PREFIX."cotisation as c"; $sql.= " WHERE c.fk_adherent = ".$this->id; $sql.= " ORDER BY c.dateadh"; @@ -948,6 +950,8 @@ class Adherent extends CommonObject $resql=$this->db->query($sql); if ($resql) { + $this->subscriptions=array(); + $i=0; while ($obj = $this->db->fetch_object($resql)) { @@ -959,7 +963,18 @@ class Adherent extends CommonObject $this->lastsubscription_date=$obj->dateadh; $this->lastsubscription_amount=$obj->cotisation; - // TODO Add also array of subscription records + $subscription=new Cotisation($this->db); + $subscription->id=$obj->rowid; + $subscription->fk_adherent=$obj->fk_adherent; + $subscription->amount=$obj->cotisation; + $subscription->note=$obj->note; + $subscription->fk_bank=$obj->fk_bank; + $subscription->datem=$this->db->jdate($obj->datem); + $subscription->datec=$this->db->jdate($obj->datec); + $subscription->dateadh=$this->db->jdate($obj->dateadh); + $subscription->datef=$this->db->jdate($obj->datef); + + $this->subscriptions[]=$subscription; $i++; } diff --git a/htdocs/adherents/cotisation.class.php b/htdocs/adherents/cotisation.class.php index 01aff9f8870..d08b6e77a45 100644 --- a/htdocs/adherents/cotisation.class.php +++ b/htdocs/adherents/cotisation.class.php @@ -181,13 +181,13 @@ class Cotisation extends CommonObject } /** - \brief Fonction qui permet de supprimer la cotisation - \param rowid Id cotisation - \return int <0 si KO, 0 si OK mais non trouve, >0 si OK - */ - function delete() + * \brief Delete a subscription + * \param rowid Id cotisation + * \return int <0 si KO, 0 si OK mais non trouve, >0 si OK + */ + function delete($user) { - // Verification + // It subscription is linked to a bank transaction, we get it if ($this->fk_bank) { require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); @@ -205,9 +205,14 @@ class Cotisation extends CommonObject $num=$this->db->affected_rows($resql); if ($num) { + require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); + $member=new Adherent($this->db); + $result=$member->fetch($this->fk_adherent); + $result=$member->update_end_date($user); + if ($this->fk_bank) { - $result=$accountline->delete(); // Renvoi faux si ligne rapprocher + $result=$accountline->delete($user); // Return false if refused because line is conciliated if ($result > 0) { $this->db->commit(); diff --git a/htdocs/adherents/fiche_subscription.php b/htdocs/adherents/fiche_subscription.php index c1cbfd9bf34..0d9dacc974a 100644 --- a/htdocs/adherents/fiche_subscription.php +++ b/htdocs/adherents/fiche_subscription.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2007-2009 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -126,7 +126,7 @@ if ($user->rights->adherent->cotisation->creer && $_REQUEST["action"] == 'update } } -if ($user->rights->adherent->cotisation->creer && $_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes') +if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->adherent->cotisation->creer) { $result=$subscription->fetch($rowid); $result=$subscription->delete();