Class: Adherent::Adhesion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Adherent::Adhesion
- Defined in:
- app/models/adherent/adhesion.rb
Class Method Summary collapse
-
.next_adh_values(montant = 0) ⇒ Object
partant d’une adhésion, retourne un hash avec les attributs correspondants à un renouvellement d’adhésion.
Instance Method Summary collapse
-
#add_reglement(payment_id, montant) ⇒ Object
ajoute un réglement provenant d’un payment pour un montant donné; renvoie le règlement qui a été ajouté.
-
#due ⇒ Object
retourne le montant dû sur l’adhésion.
-
#is_paid? ⇒ Boolean
indique si une adhésion a été réglée.
- #next_adh_values(montant = 0) ⇒ Object
- #received ⇒ Object
-
#to_s_for_select ⇒ Object
méthode mise en place pour assurer une mise en forme lisible dans la sélection des imputations.
Class Method Details
.next_adh_values(montant = 0) ⇒ Object
partant d’une adhésion, retourne un hash avec les attributs correspondants à
un renouvellement d’adhésion. S’il n’y pas d’adhésion, fonctionne avec des valeurs par défaut
20 21 22 23 24 25 |
# File 'app/models/adherent/adhesion.rb', line 20 def self.next_adh_values(montant = 0) {:from_date =>I18n.l(Date.today), :to_date=>I18n.l(Date.today.years_since(1) -1 ), amount: montant } end |
Instance Method Details
#add_reglement(payment_id, montant) ⇒ Object
ajoute un réglement provenant d’un payment pour un montant donné; renvoie le règlement qui a été ajouté.
69 70 71 72 73 74 75 76 77 |
# File 'app/models/adherent/adhesion.rb', line 69 def add_reglement(payment_id, montant) imputation = [montant, due].min r = reglements.new(amount:imputation) r.payment_id = payment_id puts r.errors. unless r.valid? r.save! r end |
#due ⇒ Object
retourne le montant dû sur l’adhésion
59 60 61 |
# File 'app/models/adherent/adhesion.rb', line 59 def due amount - received end |
#is_paid? ⇒ Boolean
indique si une adhésion a été réglée
54 55 56 |
# File 'app/models/adherent/adhesion.rb', line 54 def is_paid? sprintf('%0.02f',due) == '0.00' end |
#next_adh_values(montant = 0) ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/models/adherent/adhesion.rb', line 27 def next_adh_values(montant = 0) montant = amount if montant == 0 {:from_date =>I18n.l(read_attribute(:to_date)+1), :to_date=>I18n.l(read_attribute(:to_date).years_since(1)), amount: montant } end |
#received ⇒ Object
63 64 65 |
# File 'app/models/adherent/adhesion.rb', line 63 def received reglements.sum(:amount) end |
#to_s_for_select ⇒ Object
méthode mise en place pour assurer une mise en forme lisible dans la sélection des imputations
47 48 49 |
# File 'app/models/adherent/adhesion.rb', line 47 def to_s_for_select "#{member.to_s} - #{Adherent::ApplicationController.helpers.number_to_currency(due, locale: :fr)}" end |