diff --git a/htdocs/adherents/cotisation.class.php b/htdocs/adherents/cotisation.class.php
index 3e5e94fc849..2966ec13b7b 100644
--- a/htdocs/adherents/cotisation.class.php
+++ b/htdocs/adherents/cotisation.class.php
@@ -69,90 +69,20 @@ class Cotisation
$sql .= " VALUES (".$this->fk_adherent.", now(), ".$this->db->idate($this->dateh).", ".$this->amount.",'".$this->note."')";
dolibarr_syslog("Cotisation::create sql=".$sql);
- $result = $this->db->query($sql);
- if ($result)
+ $resql = $this->db->query($sql);
+ if ($resql)
{
return $this->db->last_insert_id(MAIN_DB_PREFIX."cotisation");
}
else
- {
- $this->error=$this->db->error().' sql='.$sql;
- return -1;
- }
- }
-
- /*!
- \TODO A ecrire
- \brief fonction qui permet de mettre à jour le don
- \param userid userid de l'adhérent
- */
- function update($userid)
- {
-
- $this->date = $this->db->idate($this->date);
-
- $sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
- $sql .= "amount = " . $this->amount;
- $sql .= ",fk_paiement = ".$this->modepaiementid;
- $sql .= ",prenom = '".$this->prenom ."'";
- $sql .= ",nom='".$this->nom."'";
- $sql .= ",societe='".$this->societe."'";
- $sql .= ",adresse='".$this->adresse."'";
- $sql .= ",cp='".$this->cp."'";
- $sql .= ",ville='".$this->ville."'";
- $sql .= ",pays='".$this->pays."'";
- $sql .= ",public=".$this->public;
- $sql .= ",fk_don_projet=".$this->projetid;
- $sql .= ",note='".$this->commentaire."'";
- $sql .= ",datedon='".$this->date."'";
- $sql .= ",email='".$this->email."'";
- $sql .= ",fk_statut=".$this->statut;
-
- $sql .= " WHERE rowid = $this->id";
-
- $result = $this->db->query($sql);
-
- if ($result)
- {
- return 1;
- }
- else
- {
- dolibarr_print_error($this->db);
- return 0;
- }
- }
-
- /**
- \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($rowid)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE rowid = ".$rowid;
-
- dolibarr_syslog("Cotisation::delete sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- if ( $this->db->affected_rows($resql))
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else
{
$this->error=$this->db->error();
+ dolibarr_syslog($this->error);
return -1;
}
}
-
+
/**
\brief Fonction qui permet de récupèrer une cotisation
\param rowid Id cotisation
@@ -160,7 +90,10 @@ class Cotisation
*/
function fetch($rowid)
{
- $sql="SELECT rowid, fk_adherent, datec, tms, dateadh, cotisation, note, fk_bank";
+ $sql ="SELECT rowid, fk_adherent, ".$this->db->pdate("datec")." as datec,";
+ $sql.=" tms,";
+ $sql.=" ".$this->db->pdate("dateadh")." as dateadh,";
+ $sql.=" cotisation, note, fk_bank";
$sql.=" FROM ".MAIN_DB_PREFIX."cotisation";
$sql.=" WHERE rowid=".$rowid;
@@ -194,25 +127,58 @@ class Cotisation
$this->error=$this->db->error();
return -1;
}
-
}
/**
- \TODO a ecrire
- \brief fonction qui permet de mettre un commentaire sur le don
- \param rowid
- \param commentaire
- */
- function set_commentaire($rowid, $commentaire='')
+ * \brief Met a jour en base la cotisation
+ * \param user Objet user qui met a jour
+ * \param notrigger 0=Desactive les triggers
+ * \param int <0 if KO, >0 if OK
+ */
+ function update($user,$notrigger=0)
{
- $sql = "UPDATE ".MAIN_DB_PREFIX."don SET note = '$commentaire'";
+ $this->db->begin();
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX."cotisation SET ";
+ $sql .= " fk_adherent = ".$this->fk_adherent.",";
+ $sql .= " fk_bank = ".($this->fk_bank ? $this->fk_bank : 'null').",";
+ $sql .= " note=".($this->note ? "'".addslashes($this->note)."'" : 'null').",";
+ $sql .= " cotisation = '".price2num($this->amount)."',";
+ $sql .= " dateadh='".$this->db->idate($this->dateh)."',";
+ $sql .= " datec='".$this->db->idate($this->datec)."'";
+ $sql .= " WHERE rowid = ".$this->id;
- $sql .= " WHERE rowid = $rowid ;";
-
- if ( $this->db->query( $sql) )
+ dolibarr_syslog("Cotisation::update sql=".$sql);
+ $resql = $this->db->query($sql);
+ if ($resql)
{
- if ( $this->db->affected_rows() )
+ $this->db->commit();
+ return 1;
+ }
+ else
+ {
+ $this->db->rollback();
+ $this->error=$this->db->error();
+ dolibarr_syslog("Cotisation::update ".$this->error);
+ return -1;
+ }
+ }
+
+ /**
+ \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($rowid)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE rowid = ".$rowid;
+
+ dolibarr_syslog("Cotisation::delete sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ if ( $this->db->affected_rows($resql))
{
return 1;
}
@@ -223,8 +189,8 @@ class Cotisation
}
else
{
- dolibarr_print_error($this->db);
- return 0;
+ $this->error=$this->db->error();
+ return -1;
}
}
diff --git a/htdocs/adherents/fiche_subscription.php b/htdocs/adherents/fiche_subscription.php
index d88a00868bf..19e663692de 100644
--- a/htdocs/adherents/fiche_subscription.php
+++ b/htdocs/adherents/fiche_subscription.php
@@ -50,6 +50,7 @@ $typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"];
if (! $user->rights->adherent->cotisation->lire)
accessforbidden();
+
/*
* Actions
*/
@@ -60,30 +61,69 @@ if ($user->rights->adherent->cotisation->creer && $_REQUEST["action"] == 'update
$result=$subscription->fetch($_POST["rowid"]);
if ($result > 0)
{
- // Modifie valeures
-
+ $db->begin();
- $result=$subscription->update($user,0);
- if ($result >= 0 && ! sizeof($subscription->errors))
+ $errmsg='';
+
+ if ($subscription->fk_bank)
{
- Header("Location: fiche_subscription.php?rowid=".$subscription->id);
- exit;
- }
- else
- {
- if ($adh->error)
+ $accountline=new AccountLine($db);
+ $result=$accountline->fetch($subscription->fk_bank);
+
+ // If transaction consolidated
+ if ($accountline->rappro)
{
- $errmsg=$adh->error;
+ $errmsg=$langs->trans("SubscriptionLinkedToConciliatedTrnasaction");
}
else
{
- foreach($adh->errors as $error)
+ $accountline->datev=dolibarr_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
+ $accountline->dateo=dolibarr_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
+ $accountline->amount=$_POST["amount"];
+ $result=$accountline->update($user);
+ if ($result < 0)
{
- if ($errmsg) $errmsg.='
';
- $errmsg.=$error;
+ $errmsg=$accountline->error;
}
}
- $action='';
+ }
+
+ if (! $errmsg)
+ {
+ // Modifie valeures
+ $subscription->dateh=dolibarr_mktime($_POST['datesubhour'], $_POST['datesubmin'], 0, $_POST['datesubmonth'], $_POST['datesubday'], $_POST['datesubyear']);
+ $subscription->amount=$_POST["amount"];
+
+ $result=$subscription->update($user);
+ if ($result >= 0 && ! sizeof($subscription->errors))
+ {
+ $db->commit();
+
+ header("Location: fiche_subscription.php?rowid=".$subscription->id);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+
+ if ($subscription->error)
+ {
+ $errmsg=$subscription->error;
+ }
+ else
+ {
+ foreach($subscription->errors as $error)
+ {
+ if ($errmsg) $errmsg.='
';
+ $errmsg.=$error;
+ }
+ }
+ $action='';
+ }
+ }
+ else
+ {
+ $db->rollback();
}
}
}
@@ -127,105 +167,42 @@ if ($user->rights->adherent->cotisation->creer && $action == 'edit')
*
********************************************/
-
-
+ $subscription->fetch($rowid);
+
/*
* Affichage onglets
*/
- $head = member_prepare_head($adh);
+ $h = 0;
+ $head = array();
- dolibarr_fiche_head($head, 'general', $langs->trans("Member"));
+ $head[$h][0] = DOL_URL_ROOT.'/adherents/fiche_subscription.php?rowid='.$subscription->id;
+ $head[$h][1] = $langs->trans("SubscriptionCard");
+ $head[$h][2] = 'general';
+ $h++;
+ dolibarr_fiche_head($head, 'general', $langs->trans("Subscription"));
+ print "\n";
print '
| '; - print $subscription->id; + print $subscription->ref; if ($previous_id || $next_id) print ' | '.$previous_id.' | '.$next_id.' |