Class: Adherent::Member

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/adherent/member.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.index_membersObject

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)



73
74
75
76
77
78
79
80
81
82
# File 'app/models/adherent/member.rb', line 73

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

#jusquauObject

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



48
49
50
51
# File 'app/models/adherent/member.rb', line 48

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



56
57
58
59
60
61
62
63
64
65
# File 'app/models/adherent/member.rb', line 56

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_sObject

renvoie le prenom NOM



38
39
40
# File 'app/models/adherent/member.rb', line 38

def to_s
  [forname, name.upcase].join(' ')
end

#unpaid_adhesionsObject

arel des adhésions impayées par ordre de date



23
24
25
# File 'app/models/adherent/member.rb', line 23

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

Returns:

  • (Boolean)


28
29
30
# File 'app/models/adherent/member.rb', line 28

def unpaid_adhesions?
  unpaid_adhesions.any?
end

#unpaid_amountObject

donne le montant total des adhésions impayées



33
34
35
# File 'app/models/adherent/member.rb', line 33

def unpaid_amount
  unpaid_adhesions.to_a.sum(&:due)
end