Fix: Le chp date fin adhésion n'était pas mis a jour par la fiche adhésion en édition
This commit is contained in:
parent
b213e0fb09
commit
6cafa0bd7d
@ -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
|
\brief Fonction qui supprime l'adherent et les donnees associees
|
||||||
\param rowid Id de l'adherent a effacer
|
\param rowid Id de l'adherent a effacer
|
||||||
@ -1092,18 +1145,6 @@ class Adherent extends CommonObject
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Create subscription
|
|
||||||
$cotisation=new Cotisation($this->db);
|
|
||||||
$cotisation->fk_adherent=$this->id;
|
|
||||||
$cotisation->dateh=$date;
|
|
||||||
$cotisation->datef=$datesubend;
|
|
||||||
$cotisation->amount=$montant;
|
|
||||||
$cotisation->note=$label;
|
|
||||||
|
|
||||||
$rowid=$cotisation->create($user);
|
|
||||||
|
|
||||||
if ($rowid > 0)
|
|
||||||
{
|
|
||||||
if ($datesubend)
|
if ($datesubend)
|
||||||
{
|
{
|
||||||
$datefin=$datesubend;
|
$datefin=$datesubend;
|
||||||
@ -1115,12 +1156,21 @@ class Adherent extends CommonObject
|
|||||||
$datefin = dolibarr_time_plus_duree($datefin,-1,'d');
|
$datefin = dolibarr_time_plus_duree($datefin,-1,'d');
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET datefin = ".$this->db->idate($datefin);
|
// Create subscription
|
||||||
$sql.= " WHERE rowid =". $this->id;
|
$cotisation=new Cotisation($this->db);
|
||||||
|
$cotisation->fk_adherent=$this->id;
|
||||||
|
$cotisation->dateh=$date;
|
||||||
|
$cotisation->datef=$datefin;
|
||||||
|
$cotisation->amount=$montant;
|
||||||
|
$cotisation->note=$label;
|
||||||
|
|
||||||
dolibarr_syslog("Adherent::cotisation update member sql=".$sql);
|
$rowid=$cotisation->create($user);
|
||||||
$resql=$this->db->query($sql);
|
|
||||||
if ($resql)
|
if ($rowid > 0)
|
||||||
|
{
|
||||||
|
// Update denormalized subscription end date
|
||||||
|
$result=$this->update_end_date($user);
|
||||||
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
// Rajout du nouveau cotisant dans les listes qui vont bien
|
// Rajout du nouveau cotisant dans les listes qui vont bien
|
||||||
if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin)
|
if ($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT && ! $adh->datefin)
|
||||||
@ -1188,8 +1238,6 @@ class Adherent extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
|
||||||
dolibarr_syslog("Adherent::cotisation error ".$this->error);
|
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,6 +166,10 @@ class Cotisation extends CommonObject
|
|||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
|
$member=new Adherent($this->db);
|
||||||
|
$result=$member->fetch($this->fk_adherent);
|
||||||
|
$result=$member->update_end_date($user);
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user