Class: Adherent::QueryMember
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Adherent::QueryMember
- Defined in:
- app/models/adherent/query_member.rb
Overview
La classe QueryMember s’appuie sur une view de SQL appelée adherent_query_members.
Elle reprend les principaux éléments de Member (organism_id, id, name, forname, birthdate, et rajoute la date de la dernière adhésion (champ m_to_date), le montant total des adhésions dues (t_adhesions) et le montant total des règlements (t_reglements).
Ces deux derniers champs sont utilisés pour savoir si le membre est à
jour de ses paiements (méthode #a_jour?)
Class Method Summary collapse
- .column(name, sql_type = nil, default = nil, null = true) ⇒ Object
- .columns ⇒ Object
- .query_members(organism) ⇒ Object
- .query_sql(organism) ⇒ Object
-
.to_csv(organism, options = {col_sep:"\t"}) ⇒ Object
edition en csv des membres d’un organisme dont l’id est transmis en argument.
-
.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.
Instance Method Summary collapse
-
#a_jour? ⇒ Boolean
booléen indiquant si l’adhérent est à jour de ces cotisations.
-
#m_to_date ⇒ Object
ici on aurait pu utiliser pick_date_for mais cela pose le problème des dates non remplies.
-
#montant_du ⇒ Object
montant dû par l’adhérent pour ses adhésions.
Class Method Details
.column(name, sql_type = nil, default = nil, null = true) ⇒ Object
19 20 21 |
# File 'app/models/adherent/query_member.rb', line 19 def self.column(name, sql_type = nil, default = nil, null = true) columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) end |
.columns ⇒ Object
17 |
# File 'app/models/adherent/query_member.rb', line 17 def self.columns() @columns ||= []; end |
.query_members(organism) ⇒ Object
64 65 66 |
# File 'app/models/adherent/query_member.rb', line 64 def self.query_members(organism) find_by_sql(query_sql(organism)) end |
.query_sql(organism) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/adherent/query_member.rb', line 45 def self.query_sql(organism) %Q(SELECT adherent_members.id, organism_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 WHERE organism_id = #{organism.id}; ) end |
.to_csv(organism, options = {col_sep:"\t"}) ⇒ Object
edition en csv des membres d’un organisme dont l’id est transmis en argument
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/adherent/query_member.rb', line 85 def self.to_csv(organism, = {col_sep:"\t"}) ms = query_members(organism) CSV.generate() do |csv| csv << ['Numero', 'Nom', 'Prénom', 'Date de naissance', 'Mail', 'Tél', 'Doit', 'Fin Adh.'] ms.each do |m| csv << [m.number, m.name, m.forname, m.birthdate, m.mail, m.tel, 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
100 101 102 |
# File 'app/models/adherent/query_member.rb', line 100 def self.to_xls(organism, = {col_sep:"\t"}) to_csv(organism, ).encode("windows-1252") end |
Instance Method Details
#a_jour? ⇒ Boolean
booléen indiquant si l’adhérent est à jour de ces cotisations
41 42 43 |
# File 'app/models/adherent/query_member.rb', line 41 def a_jour? montant_du <= 0.001 end |
#m_to_date ⇒ Object
ici on aurait pu utiliser pick_date_for mais cela pose le problème des dates non remplies. Ce qui a son tour est gênant pour le tri dans les tables.
71 72 73 74 |
# File 'app/models/adherent/query_member.rb', line 71 def m_to_date td = read_attribute(:m_to_date) td.is_a?(Date) ? (I18n::l td) : '31/12/2099' end |
#montant_du ⇒ Object
montant dû par l’adhérent pour ses adhésions
77 78 79 80 81 |
# File 'app/models/adherent/query_member.rb', line 77 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 |