New: Possibilite de modifier montant et date d'une cotisation

This commit is contained in:
Laurent Destailleur 2007-08-27 21:39:01 +00:00
parent 80d0fe4651
commit b522944ad3
4 changed files with 194 additions and 206 deletions

View File

@ -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;
}
}

View File

@ -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.='<br>';
$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.='<br>';
$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 '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print "<input type=\"hidden\" name=\"action\" value=\"update\">";
print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
print "<input type=\"hidden\" name=\"statut\" value=\"".$adh->statut."\">";
print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$subscription->fk_bank."\">";
print '<table class="border" width="100%">';
$htmls = new Form($db);
// Ref
print '<tr><td>'.$langs->trans("Ref").'</td><td class="valeur" colspan="2">'.$adh->id.'&nbsp;</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td class="valeur" colspan="2">'.$subscription->ref.'&nbsp;</td></tr>';
// Nom
print '<tr><td>'.$langs->trans("Lastname").'</td><td><input type="text" name="nom" size="40" value="'.$adh->nom.'"></td>';
// Photo
$rowspan=17;
$rowspan+=sizeof($adho->attribute_label);
print '<td rowspan="'.$rowspan.'" valign="top">';
print '&nbsp;';
// Date
print '<tr><td>'.$langs->trans("Date").'</td><td class="valeur" colspan="2">';
$htmls->select_date($subscription->dateh,'datesub',1,1,0,'update',1);
print '</td>';
print '</tr>';
print '</tr>';
// Prenom
print '<tr><td width="20%">'.$langs->trans("Firstname").'</td><td width="35%"><input type="text" name="prenom" size="40" value="'.$adh->prenom.'"></td>';
print '</tr>';
// Login
print '<tr><td>'.$langs->trans("Login").'</td><td><input type="text" name="login" size="40" value="'.$adh->login.'"></td></tr>';
// Password
print '<tr><td>'.$langs->trans("Password").'</td><td><input type="password" name="pass" size="40" value="'.$adh->pass.'"></td></tr>';
// Type
print '<tr><td>'.$langs->trans("Type").'</td><td>';
$htmls->select_array("type", $adht->liste_array(), $adh->typeid);
print "</td></tr>";
// Physique-Moral
$morphys["phy"] = $langs->trans("Physical");
$morphys["mor"] = $langs->trans("Morale");
print "<tr><td>".$langs->trans("Person")."</td><td>";
$htmls->select_array("morphy", $morphys, $adh->morphy);
print "</td></tr>";
// Société
print '<tr><td>'.$langs->trans("Company").'</td><td><input type="text" name="societe" size="40" value="'.$adh->societe.'"></td></tr>';
// Adresse
print '<tr><td>'.$langs->trans("Address").'</td><td>';
print '<textarea name="adresse" wrap="soft" cols="40" rows="2">'.$adh->adresse.'</textarea></td></tr>';
// Cp
print '<tr><td>'.$langs->trans("Zip").'/'.$langs->trans("Town").'</td><td><input type="text" name="cp" size="6" value="'.$adh->cp.'"> <input type="text" name="ville" size="32" value="'.$adh->ville.'"></td></tr>';
// Pays
print '<tr><td>'.$langs->trans("Country").'</td><td>';
$htmls->select_pays($adh->pays_code?$adh->pays_code:$mysoc->pays_code,'pays');
print '</td></tr>';
// Tel
print '<tr><td>'.$langs->trans("PhonePro").'</td><td><input type="text" name="phone" size="20" value="'.$adh->phone.'"></td></tr>';
// Tel perso
print '<tr><td>'.$langs->trans("PhonePerso").'</td><td><input type="text" name="phone_perso" size="20" value="'.$adh->phone_perso.'"></td></tr>';
// Tel mobile
print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td><input type="text" name="phone_mobile" size="20" value="'.$adh->phone_mobile.'"></td></tr>';
// EMail
print '<tr><td>'.$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'*':'').'</td><td><input type="text" name="email" size="40" value="'.$adh->email.'"></td></tr>';
// Date naissance
print "<tr><td>".$langs->trans("Birthday")."</td><td>\n";
$htmls->select_date(($adh->naiss ? $adh->naiss : -1),'naiss','','',1,'update');
print "</td></tr>\n";
// Url photo
print '<tr><td>URL photo</td><td><input type="text" name="photo" size="40" value="'.$adh->photo.'"></td></tr>';
// Profil public
print "<tr><td>".$langs->trans("Public")."</td><td>\n";
print $htmls->selectyesno("public",$adh->public,1);
print "</td></tr>\n";
// Attributs supplémentaires
foreach($adho->attribute_label as $key=>$value)
{
print "<tr><td>$value</td><td><input type=\"text\" name=\"options_$key\" size=\"40\" value=\"".$adh->array_options["options_$key"]."\"></td></tr>\n";
}
// Amount
print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur" colspan="2">';
print '<input type="text" class="flat" size="10" name="amount" value="'.price($subscription->amount).'"></td></tr>';
print '<tr><td colspan="3" align="center">';
print '<input type="submit" class="button" name="submit" value="'.$langs->trans("Save").'">';
@ -235,8 +212,10 @@ if ($user->rights->adherent->cotisation->creer && $action == 'edit')
print '</table>';
print '</form>';
print "\n";
print '</div>';
print "\n";
}
if ($rowid && $action != 'edit')
@ -289,7 +268,7 @@ if ($rowid && $action != 'edit')
print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
print '<td class="valeur" colspan="2">';
if ($previous_id || $next_id) print '<table class="nobordernopadding" width="100%"><tr class="nobordernopadding"><td class="nobordernopadding">';
print $subscription->id;
print $subscription->ref;
if ($previous_id || $next_id) print '</td><td class="nobordernopadding" align="center" width="20">'.$previous_id.'</td><td class="nobordernopadding" align="center" width="20">'.$next_id.'</td></tr></table>';
print '</td></tr>';
@ -298,7 +277,7 @@ if ($rowid && $action != 'edit')
print '</tr>';
// Amount
print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur">'.$subscription->amount.'</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur">'.price($subscription->amount).'</td></tr>';
print "</table>\n";
print '</form>';
@ -312,10 +291,10 @@ if ($rowid && $action != 'edit')
*/
print '<div class="tabsAction">';
// if ($user->rights->adherent->cotisation->creer)
// {
// print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?rowid=".$subscription->id."&action=edit\">".$langs->trans("Edit")."</a>";
// }
if ($user->rights->adherent->cotisation->creer)
{
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?rowid=".$subscription->id."&action=edit\">".$langs->trans("Edit")."</a>";
}
// Supprimer
if ($user->rights->adherent->cotisation->creer)

View File

@ -324,7 +324,7 @@ class Account
{
global $langs;
dolibarr_syslog("Account.class::update");
dolibarr_syslog("Account::update");
if (! $this->ref)
{
@ -352,8 +352,7 @@ class Account
$sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Account.class::update sql=$sql");
dolibarr_syslog("Account::update sql=$sql");
$result = $this->db->query($sql);
if ($result)
{
@ -380,7 +379,7 @@ class Account
// Chargement librairie pour acces fonction controle RIB
require_once(DOL_DOCUMENT_ROOT.'/lib/bank.lib.php');
dolibarr_syslog("Account.class::update $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban_prefix");
dolibarr_syslog("Account::update $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban_prefix");
// Verification parametres
if (! verif_rib($this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban_prefix)) {
@ -407,7 +406,7 @@ class Account
$sql .= ",adresse_proprio = '".addslashes($this->adresse_proprio)."'";
$sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Account.class::update_rib sql=$sql");
dolibarr_syslog("Account::update_rib sql=$sql");
$result = $this->db->query($sql);
if ($result)
@ -726,11 +725,22 @@ class Account
}
/**
\class AccountLine
\brief Classe permettant la gestion des lignes de transactions bancaires
*/
class AccountLine
{
var $db;
var $rowid;
var $rappro;
var $datec;
var $dateo;
var $datev;
var $amount;
var $label;
var $note;
/**
@ -838,6 +848,39 @@ class AccountLine
}
/**
* \brief Met a jour en base la ligne
* \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)
{
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
$sql.= " amount = ".price2num($this->amount).",";
$sql.= " datev='".$this->db->idate($this->datev)."',";
$sql.= " dateo='".$this->db->idate($this->dateo)."'";
$sql.= " WHERE rowid = ".$this->rowid;
dolibarr_syslog("AccountLine::update sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->error();
dolibarr_syslog("AccountLine::update ".$this->error);
return -1;
}
}
/**
* \brief Charge les informations d'ordre info dans l'objet facture
* \param id Id de la facture a charger

View File

@ -2536,7 +2536,7 @@ class Form
function select_date($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1)
{
global $conf,$langs;
if($prefix=='') $prefix='re';
if($h == '') $h=0;
if($m == '') $m=0;
@ -2579,11 +2579,11 @@ class Form
* Affiche date en popup
*/
if ($conf->use_javascript && $conf->use_popup_calendar)
{
//print "e".$set_time." t ".$conf->format_date_short;
if ($set_time > 0)
{
$formated_date=dolibarr_print_date($set_time,$conf->format_date_short);
{
//print "e".$set_time." t ".$conf->format_date_short;
if ($set_time > 0)
{
$formated_date=dolibarr_print_date($set_time,$conf->format_date_short);
}
// Calendrier popup version eldy
@ -2593,7 +2593,7 @@ class Form
print '<input id="'.$prefix.'" name="'.$prefix.'" type="text" size="10" maxlength="11" value="'.$formated_date.'"';
print ' onChange="dpChangeDay(\''.$prefix.'\',\''.$conf->format_date_short_java.'\')"';
print '>';
// Icone calendrier
print '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons"';
$base=DOL_URL_ROOT.'/lib/';
@ -2607,7 +2607,7 @@ class Form
{
// Calendrier popup version defaut
if ($langs->defaultlang != "")
{
{
print '<script language="javascript" type="text/javascript">';
print 'selectedLanguage = "'.substr($langs->defaultlang,0,2).'"';
print '</script>';
@ -2624,7 +2624,7 @@ class Form
else
print '<A HREF="javascript:showCalendar(document.forms[\''.$form_name.'\'].'.$prefix.')">'.img_cal().'</a>';
}
}
}
/*
* Affiche date en select