class ESA::Account
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
Public Class Methods
namespaced_type(type)
click to toggle source
# 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)
click to toggle source
# File app/models/esa/account.rb, line 58 def self.valid_type?(type) type.in? ["Asset", "Liability", "Equity", "Revenue", "Expense"] end
Public Instance Methods
balance()
click to toggle source
The balance of the account.
@example
>> account.balance => #<BigDecimal:103259bb8,'0.2E4',4(12)>
@return [BigDecimal] The decimal value balance
# 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
Private Instance Methods
initialize_defaults()
click to toggle source
# File app/models/esa/account.rb, line 72 def initialize_defaults self.chart ||= Chart.where(:name => 'Chart of Accounts').first_or_create if self.chart_id.nil? self.normal_balance ||= :none end
update_normal_balance()
click to toggle source
The normal balance for the account. Must be overridden in implementations.
# File app/models/esa/account.rb, line 78 def update_normal_balance self.normal_balance = :none end