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 ""; print ""; - print "statut."\">"; - + print "fk_bank."\">"; print ''; $htmls = new Form($db); // Ref - print ''; + print ''; - // Nom - print ''; - // Photo - $rowspan=17; - $rowspan+=sizeof($adho->attribute_label); - print ''; - print ''; + print ''; - // Prenom - print ''; - print ''; - - // Login - print ''; - - // Password - print ''; - - // Type - print '"; - - // Physique-Moral - $morphys["phy"] = $langs->trans("Physical"); - $morphys["mor"] = $langs->trans("Morale"); - print ""; - - // Société - print ''; - - // Adresse - print ''; - - // Cp - print ''; - - // Pays - print ''; - - // Tel - print ''; - - // Tel perso - print ''; - - // Tel mobile - print ''; - - // EMail - print ''; - - // Date naissance - print "\n"; - - // Url photo - print ''; - - // Profil public - print "\n"; - - // Attributs supplémentaires - foreach($adho->attribute_label as $key=>$value) - { - print "\n"; - } + // Amount + print ''; print '
'.$langs->trans("Ref").''.$adh->id.' 
'.$langs->trans("Ref").''.$subscription->ref.' 
'.$langs->trans("Lastname").''; - print ' '; + // Date + print '
'.$langs->trans("Date").''; + $htmls->select_date($subscription->dateh,'datesub',1,1,0,'update',1); print '
'.$langs->trans("Firstname").'
'.$langs->trans("Login").'
'.$langs->trans("Password").'
'.$langs->trans("Type").''; - $htmls->select_array("type", $adht->liste_array(), $adh->typeid); - print "
".$langs->trans("Person").""; - $htmls->select_array("morphy", $morphys, $adh->morphy); - print "
'.$langs->trans("Company").'
'.$langs->trans("Address").''; - print '
'.$langs->trans("Zip").'/'.$langs->trans("Town").'
'.$langs->trans("Country").''; - $htmls->select_pays($adh->pays_code?$adh->pays_code:$mysoc->pays_code,'pays'); - print '
'.$langs->trans("PhonePro").'
'.$langs->trans("PhonePerso").'
'.$langs->trans("PhoneMobile").'
'.$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'*':'').'
".$langs->trans("Birthday")."\n"; - $htmls->select_date(($adh->naiss ? $adh->naiss : -1),'naiss','','',1,'update'); - print "
URL photo
".$langs->trans("Public")."\n"; - print $htmls->selectyesno("public",$adh->public,1); - print "
$valuearray_options["options_$key"]."\">
'.$langs->trans("Amount").''; + print '
'; print ''; @@ -235,8 +212,10 @@ if ($user->rights->adherent->cotisation->creer && $action == 'edit') print '
'; print '
'; + print "\n"; print ''; + print "\n"; } if ($rowid && $action != 'edit') @@ -289,7 +268,7 @@ if ($rowid && $action != 'edit') print ''.$langs->trans("Ref").''; print ''; if ($previous_id || $next_id) print '
'; - print $subscription->id; + print $subscription->ref; if ($previous_id || $next_id) print ''.$previous_id.''.$next_id.'
'; print ''; @@ -298,7 +277,7 @@ if ($rowid && $action != 'edit') print ''; // Amount - print ''.$langs->trans("Amount").''.$subscription->amount.''; + print ''.$langs->trans("Amount").''.price($subscription->amount).''; print "\n"; print ''; @@ -312,10 +291,10 @@ if ($rowid && $action != 'edit') */ print '
'; -// if ($user->rights->adherent->cotisation->creer) -// { -// print "id."&action=edit\">".$langs->trans("Edit").""; -// } + if ($user->rights->adherent->cotisation->creer) + { + print "id."&action=edit\">".$langs->trans("Edit").""; + } // Supprimer if ($user->rights->adherent->cotisation->creer) diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php index 0a0b270544f..d1be7d54984 100644 --- a/htdocs/compta/bank/account.class.php +++ b/htdocs/compta/bank/account.class.php @@ -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 diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index db4f36121ad..abdb1f13e36 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -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 ''; - + // Icone calendrier print '