Class: Adherent::Member
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Adherent::Member
- Defined in:
- app/models/adherent/member.rb
Class Method Summary collapse
-
.index_members ⇒ Object
Permet en une seule requête de récupérer les données de la vue index avec l’id, le number, name, forname, mail, tel, l’échande de l’adhésion (champ to_date), le montant des reglements reçus pour les adhésions de ce membre (champ t_reglements), le montant des adhésions de ce membre champ (t_adhesions).
Instance Method Summary collapse
-
#jusquau ⇒ Object
indique la date de fin de son adhésion actuelle.
-
#next_adhesion(amount = nil) ⇒ Object
renvoie une nouvelle adhésion préremplie avec les éléments issus de la dernière adhésion.
-
#to_s ⇒ Object
renvoie le prenom NOM.
-
#unpaid_adhesions ⇒ Object
arel des adhésions impayées par ordre de date.
-
#unpaid_adhesions? ⇒ Boolean
indique s’il y a des adhésions impayées pour ce membre.
-
#unpaid_amount ⇒ Object
donne le montant total des adhésions impayées.
Class Method Details
.index_members ⇒ Object
Permet en une seule requête de récupérer les données de la vue index avec l’id, le number, name, forname, mail, tel, l’échande de l’adhésion (champ to_date), le montant des reglements reçus pour les adhésions de ce membre (champ t_reglements), le montant des adhésions de ce membre champ (t_adhesions)
70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/adherent/member.rb', line 70 def self.index_members sql= <<EOF SELECT adherent_members.id, number, name, forname, birthdate, adherent_coords.mail AS mail, adherent_coords.tel AS tel, (SELECT to_date FROM adherent_adhesions WHERE adherent_adhesions.member_id = adherent_members.id ORDER BY to_date DESC LIMIT 1 ) AS m_to_date, (SELECT SUM(adherent_reglements.amount) FROM adherent_reglements, adherent_adhesions WHERE adherent_reglements.adhesion_id = adherent_adhesions.id AND adherent_adhesions.member_id = adherent_members.id) AS t_reglements, (SELECT SUM(amount) FROM adherent_adhesions WHERE adherent_adhesions.member_id = adherent_members.id) AS t_adhesions FROM adherent_members LEFT JOIN adherent_coords ON adherent_members.id = adherent_coords.member_id; EOF Adherent::Member.connection.execute( sql.gsub("\n", '')) end |
Instance Method Details
#jusquau ⇒ Object
indique la date de fin de son adhésion actuelle. S’il n’y a pas d’adhésion, on prend la date de création du membre
On n’a qu’un I18n::l car le to_date de last_adhesion est déja mis au format par le module pick_date_extension
45 46 47 48 |
# File 'app/models/adherent/member.rb', line 45 def jusquau la = last_adhesion la ? la.to_date : I18n::l(created_at.to_date) end |
#next_adhesion(amount = nil) ⇒ Object
renvoie une nouvelle adhésion préremplie avec les éléments issus de la dernière adhésion. il est possible d’imposer le montant si nécessaire
53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/adherent/member.rb', line 53 def next_adhesion(amount = nil) amount ||= 0 adh = adhesions(true).order('to_date').last if adh vals = adh.next_adh_values(amount) else vals = Adhesion::next_adh_values(amount) end adhesions.new(vals) end |
#to_s ⇒ Object
renvoie le prenom NOM
35 36 37 |
# File 'app/models/adherent/member.rb', line 35 def to_s [forname, name.upcase].join(' ') end |
#unpaid_adhesions ⇒ Object
arel des adhésions impayées par ordre de date
20 21 22 |
# File 'app/models/adherent/member.rb', line 20 def unpaid_adhesions adhesions.order(:to_date).unpaid end |
#unpaid_adhesions? ⇒ Boolean
indique s’il y a des adhésions impayées pour ce membre
25 26 27 |
# File 'app/models/adherent/member.rb', line 25 def unpaid_adhesions? unpaid_adhesions.any? end |
#unpaid_amount ⇒ Object
donne le montant total des adhésions impayées
30 31 32 |
# File 'app/models/adherent/member.rb', line 30 def unpaid_amount unpaid_adhesions.to_a.sum(&:due) end |