Class: ESA::Account

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Enumerize
Defined in:
app/models/esa/account.rb

Overview

The Account class represents accounts in the system. Each account must be subclassed as one of the following types:

TYPE        | NORMAL BALANCE    | DESCRIPTION
--------------------------------------------------------------------------
Asset       | Debit             | Resources owned by the Business Entity
Liability   | Credit            | Debts owed to outsiders
Equity      | Credit            | Owners rights to the Assets
Revenue     | Credit            | Increases in owners equity
Expense     | Debit             | Assets or services consumed in the generation of revenue

Each account can also be marked as a “Contra Account”. A contra account will have it’s normal balance swapped. For example, to remove equity, a “Drawing” account may be created as a contra equity account as follows:

ESA::Equity.create(:name => "Drawing", contra => true)

Author:

  • Lenno Nagel, Michael Bulat

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.namespaced_type(type) ⇒ Object



62
63
64
65
66
67
68
# File 'app/models/esa/account.rb', line 62

def self.namespaced_type(type)
  if valid_type?(type)
    "ESA::Accounts::#{type}"
  else
    type
  end
end

.valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/esa/account.rb', line 58

def self.valid_type?(type)
  type.in? ["Asset", "Liability", "Equity", "Revenue", "Expense"]
end

Instance Method Details

#balanceBigDecimal

The balance of the account.

Examples:

>> account.balance
=> #<BigDecimal:103259bb8,'0.2E4',4(12)>

Returns:

  • (BigDecimal)

    The decimal value balance



48
49
50
51
52
53
54
55
56
# File 'app/models/esa/account.rb', line 48

def balance
  if self.normal_balance.debit?
    self.amounts.balance
  elsif self.normal_balance.credit?
    - self.amounts.balance
  else
    nil
  end
end