Class: Adherent::Adhesion

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

Class Method Summary collapse

Instance Method Summary collapse

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



25
26
27
28
29
30
# File 'app/models/adherent/adhesion.rb', line 25

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é.



75
76
77
78
79
80
81
82
83
# File 'app/models/adherent/adhesion.rb', line 75

def add_reglement(payment_id, montant)
  imputation = [montant, due].min 
  r = reglements.new(amount:imputation)
  r.payment_id = payment_id
  puts r.errors.messages unless r.valid?
  r.save!
  r

end

#dueObject

retourne le montant dû sur l’adhésion



65
66
67
# File 'app/models/adherent/adhesion.rb', line 65

def due
  amount - received
end

#is_paid?Boolean

indique si une adhésion a été réglée

Returns:

  • (Boolean)


60
61
62
# File 'app/models/adherent/adhesion.rb', line 60

def is_paid?
  sprintf('%0.02f',due) == '0.00'
end

#next_adh_values(montant = 0) ⇒ Object



32
33
34
35
36
37
38
# File 'app/models/adherent/adhesion.rb', line 32

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

#receivedObject



69
70
71
# File 'app/models/adherent/adhesion.rb', line 69

def received
  reglements.sum(:amount)
end

#to_s_for_selectObject

méthode mise en place pour assurer une mise en forme lisible dans la sélection des imputations



51
52
53
# File 'app/models/adherent/adhesion.rb', line 51

def to_s_for_select
  "#{member.to_s} - #{Adherent::ApplicationController.helpers.number_to_currency(due, locale: :fr)}"
end