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

.query_members(organism) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/adherent/member.rb', line 24

def self.query_members(organism)
  sql = <<-eof 
SELECT adherent_members.id, organism_id, number, name, forname, birthdate,
   adherent_coords.mail AS mail,
   adherent_coords.tel AS tel,
   adherent_coords.gsm AS gsm,
   adherent_coords.office AS office,
   adherent_coords.address AS address,
   adherent_coords.zip AS zip,
   adherent_coords.city AS city,
  (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, 
  (SELECT COUNT(*) FROM adherent_payments
     WHERE adherent_payments.member_id = adherent_members.id) AS nb_payments
     
  FROM adherent_members 
  LEFT JOIN adherent_coords ON adherent_members.id = adherent_coords.member_id
  WHERE organism_id = #{organism.id} 
eof
   find_by_sql(sql)      
end

.to_csv(organism, options = {col_sep:"\t"}) ⇒ Object

edition en csv des membres d’un organisme dont l’id est transmis en argument



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/models/adherent/member.rb', line 131

def self.to_csv(organism, options = {col_sep:"\t"})
  ms = query_members(organism)
  CSV.generate(options) do |csv|
    csv << ['Numero', 'Nom', 'Prénom', 'Date de naissance',
      'Mail', 'Tél', 'Gsm', 'Bureau', 'Adresse', 'Code Postal', 'Ville', 'Doit', 'Fin Adh.']
    ms.each do |m| 
      csv << [m.number, m.name, m.forname, m.birthdate, m.mail, m.tel,
        m.gsm, m.office, m.address, m.zip, m.city,
        ActiveSupport::NumberHelper.number_to_rounded(m.montant_du, precision:2),
        m.m_to_date]
    end
  end
end

.to_xls(organism, options = {col_sep:"\t"}) ⇒ Object

Pour avoir l’encodage Windows, voir à mettre dans un module si répété avec d’autres modèles



147
148
149
# File 'app/models/adherent/member.rb', line 147

def self.to_xls(organism, options = {col_sep:"\t"})
  to_csv(organism, options).encode("windows-1252")
end

Instance Method Details

#a_jour?Boolean

booléen indiquant si l’adhérent est à jour de ces cotisations

Returns:

  • (Boolean)


108
109
110
# File 'app/models/adherent/member.rb', line 108

def a_jour?
  montant_du <= 0.001
end

#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



81
82
83
84
# File 'app/models/adherent/member.rb', line 81

def jusquau
  la = last_adhesion
  la ? la.to_date : I18n::l(created_at.to_date)
end

#montant_duObject

montant dû par l’adhérent pour ses adhésions



101
102
103
104
105
# File 'app/models/adherent/member.rb', line 101

def montant_du
  tadh = t_adhesions ? BigDecimal.new(t_adhesions, 2) : BigDecimal.new(0.0, 2)
  treg = t_reglements ? BigDecimal.new(t_reglements, 2) : BigDecimal.new(0.0, 2)
  tadh - treg
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



89
90
91
92
93
94
95
96
97
98
# File 'app/models/adherent/member.rb', line 89

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



71
72
73
# File 'app/models/adherent/member.rb', line 71

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

#unpaid_adhesionsObject

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



54
55
56
# File 'app/models/adherent/member.rb', line 54

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)


59
60
61
# File 'app/models/adherent/member.rb', line 59

def unpaid_adhesions?
  unpaid_adhesions.any?
end

#unpaid_amountObject

donne le montant total des adhésions impayées



64
65
66
# File 'app/models/adherent/member.rb', line 64

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