Sha256: dee4e8be35ae449a74a332079133b6b3530e25ddc0ae5133e123fc61fdc07d25

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

module Adherent
  class Member < ActiveRecord::Base
    
    
    pick_date_for :birthdate
    
    belongs_to :organism, class_name: '::Organism'
    has_one :coord, dependent: :destroy
    has_many :adhesions, dependent: :destroy
    has_many :payments
    
    # TODO rajouter un before_destroy sur les paiements
    
    validates :number, :name, :forname , :organism_id, :presence=>true
    validates_uniqueness_of  :number, :scope=>:organism_id
    
    # arel des adhésions impayées par ordre de date
    def unpaid_adhesions
      adhesions.order(:to_date).unpaid
    end
    
    # indique s'il y a des adhésions impayées pour ce membre
    def unpaid_adhesions?
      unpaid_adhesions.any?
    end
    
    # donne le montant total des adhésions impayées
    def unpaid_amount
      unpaid_adhesions.to_a.sum(&:due)
    end
    
    # renvoie le prenom NOM
    def to_s
      [forname, name.upcase].join(' ')
    end
    
    # 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
    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
    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
adherent-0.2.3 app/models/adherent/member.rb
adherent-0.2.2.4 app/models/adherent/member.rb
adherent-0.2.2.3 app/models/adherent/member.rb
adherent-0.2.2.2 app/models/adherent/member.rb
adherent-0.2.2.1 app/models/adherent/member.rb
adherent-0.2.2 app/models/adherent/member.rb