Class: DoubleDouble::Account Abstract
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DoubleDouble::Account
- Defined in:
- lib/double_double/account.rb
Overview
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
Class Method Summary collapse
- .balance ⇒ Object
- .named(account_name) ⇒ Object
- .numbered(account_number) ⇒ Object
-
.trial_balance ⇒ Money
The trial balance of all accounts in the system.
Instance Method Summary collapse
Class Method Details
.balance ⇒ Object
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 account_name self.where(name: account_name.to_s).first end |
.numbered(account_number) ⇒ Object
64 65 66 |
# File 'lib/double_double/account.rb', line 64 def numbered account_number self.where(number: account_number.to_i).first end |
.trial_balance ⇒ Money
The trial balance of all accounts in the system. This should always equal zero, otherwise there is an error in the system.
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 |