Class: DoubleDouble::Account Abstract

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/double_double/account.rb

Overview

This class is abstract.

An account must be a subclass to be saved to the database. The Account class has a singleton method Account.trial_balance to calculate the balance on all Accounts.

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:

DoubleDouble::Equity.create(name: "Drawing", number: 2002, contra: true)

At all times the balance of all accounts should conform to the “accounting equation”

DoubleDouble::Assets = Liabilties + Owner's Equity

Each sublclass account acts as it’s own ledger. See the individual subclasses for a description.

Direct Known Subclasses

NormalCreditAccount, NormalDebitAccount

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.balanceObject

Raises:

  • (NoMethodError)


55
56
57
58
# File 'lib/double_double/account.rb', line 55

def balance
  raise(NoMethodError, "undefined method 'balance'") if self == DoubleDouble::Account
  accounts_balance = self.all.inject(Money.new(0)) {|sum, acct| acct.contra ? (sum - acct.balance) : (sum + acct.balance)}
end

.named(account_name) ⇒ Object



60
61
62
# File 'lib/double_double/account.rb', line 60

def named 
  self.where(name: .to_s).first
end

.numbered(account_number) ⇒ Object



64
65
66
# File 'lib/double_double/account.rb', line 64

def numbered 
  self.where(number: .to_i).first
end

.trial_balanceMoney

The trial balance of all accounts in the system. This should always equal zero, otherwise there is an error in the system.

Returns:

  • (Money)

    The value balance of all accounts

Raises:

  • (NoMethodError)


50
51
52
53
# File 'lib/double_double/account.rb', line 50

def trial_balance
  raise(NoMethodError, "undefined method 'trial_balance'") unless self == DoubleDouble::Account
  Asset.balance - (Liability.balance + Equity.balance + Revenue.balance - Expense.balance)
end

Instance Method Details

#credits_balance(hash = {}) ⇒ Object



69
70
71
# File 'lib/double_double/account.rb', line 69

def credits_balance(hash = {})
  side_balance(false, hash)
end

#debits_balance(hash = {}) ⇒ Object



73
74
75
# File 'lib/double_double/account.rb', line 73

def debits_balance(hash = {})
  side_balance(true, hash)
end