Sha256: 4eb42261e54164d25a49d2813f56cdb16c223215247cf794c668f5689098235f

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'esa/associations/amounts_extension'
require 'esa/traits/extendable'

module ESA
  # The Chart class represents an organized set of accounts in the system.
  #
  # @author Lenno Nagel
  class Chart < ActiveRecord::Base
    include ESA::Traits::Extendable

    attr_accessible :name

    has_many :accounts
    has_many :rulesets

    has_many :events, :through => :rulesets, :uniq => true
    has_many :flags, :through => :rulesets, :uniq => true
    has_many :transactions, :through => :accounts, :uniq => true
    has_many :amounts, :through => :accounts, :uniq => true, :extend => ESA::Associations::AmountsExtension

    after_initialize :initialize_defaults

    validates_presence_of :name
    validates_uniqueness_of :name

    # The trial balance of all accounts in the system. This should always equal zero,
    # otherwise there is an error in the system.
    #
    # @example
    #   >> chart.trial_balance.to_i
    #   => 0
    #
    # @return [BigDecimal] The decimal value balance of all accounts
    def trial_balance
      self.amounts.balance
    end

    private

    def initialize_defaults
      self.name ||= "Chart of Accounts"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
event_sourced_accounting-0.2.6 app/models/esa/chart.rb
event_sourced_accounting-0.2.4 app/models/esa/chart.rb
event_sourced_accounting-0.2.3 app/models/esa/chart.rb
event_sourced_accounting-0.2.2 app/models/esa/chart.rb