module Plutus # The Equity class is an account type used to represents owners rights to the assets. # # === Normal Balance # The normal balance on Equity accounts is a *Credit*. # # @see http://en.wikipedia.org/wiki/Equity_(finance) Equity # # @author Michael Bulat class Equity < Account # The balance of the account. # # Equity accounts have normal credit balances, so the debits are subtracted from the credits # unless this is a contra account, in which credits are subtracted from debits # # @example # >> asset.balance # => # # # @return [BigDecimal] The decimal value balance def balance unless contra credits_balance - debits_balance else debits_balance - credits_balance end end # This class method is used to return # the balance of all Equity accounts. # # Contra accounts are automatically subtracted from the balance. # # @example # >> Plutus::Equity.balance # => # # # @return [BigDecimal] The decimal value balance def self.balance accounts_balance = BigDecimal.new('0') accounts = self.find(:all) accounts.each do |equity| unless equity.contra accounts_balance += equity.balance else accounts_balance -= equity.balance end end accounts_balance end end end