Class: Plutus::Account Abstract
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Plutus::Account
- Defined in:
- app/models/plutus/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:
Plutus::Equity.create(:name => "Drawing", contra => true)
At all times the balance of all accounts should conform to the “accounting equation”
Plutus::Assets = Liabilties + Owner's Equity
Each sublclass account acts as it’s own ledger. See the individual subclasses for a description.
Class Method Summary collapse
-
.balance(options = {}) ⇒ BigDecimal
This class method is used to return the balance of all accounts for a given class and is intended for use only on account subclasses.
-
.trial_balance ⇒ BigDecimal
The trial balance of all accounts in the system.
Instance Method Summary collapse
-
#balance(options = {}) ⇒ BigDecimal
The balance of the account.
-
#credits_balance(options = {}) ⇒ BigDecimal
The credit balance for the account.
-
#debits_balance(options = {}) ⇒ BigDecimal
The debit balance for the account.
Class Method Details
.balance(options = {}) ⇒ BigDecimal
This class method is used to return the balance of all accounts for a given class and is intended for use only on account subclasses.
Contra accounts are automatically subtracted from the balance.
Takes an optional hash specifying :from_date and :to_date for calculating balances during periods. :from_date and :to_date may be strings of the form “yyyy-mm-dd” or Ruby Date objects
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/models/plutus/account.rb', line 136 def self.balance(={}) if self.new.class == Plutus::Account raise(NoMethodError, "undefined method 'balance'") else accounts_balance = BigDecimal.new('0') accounts = self.all accounts.each do |account| if account.contra accounts_balance -= account.balance() else accounts_balance += account.balance() end end accounts_balance end end |
.trial_balance ⇒ BigDecimal
The trial balance of all accounts in the system. This should always equal zero, otherwise there is an error in the system.
161 162 163 164 165 166 167 |
# File 'app/models/plutus/account.rb', line 161 def self.trial_balance if self.new.class == Plutus::Account Plutus::Asset.balance - (Plutus::Liability.balance + Plutus::Equity.balance + Plutus::Revenue.balance - Plutus::Expense.balance) else raise(NoMethodError, "undefined method 'trial_balance'") end end |
Instance Method Details
#balance(options = {}) ⇒ BigDecimal
The balance of the account. This instance method is intended for use only on instances of account subclasses.
If the account has a normal credit balance, the debits are subtracted from the credits unless this is a contra account, in which case credits are substracted from debits.
For a normal debit balance, the credits are subtracted from the debits unless this is a contra account, in which case debits are subtracted from credits.
Takes an optional hash specifying :from_date and :to_date for calculating balances during periods. :from_date and :to_date may be strings of the form “yyyy-mm-dd” or Ruby Date objects
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/plutus/account.rb', line 71 def balance(={}) if self.class == Plutus::Account raise(NoMethodError, "undefined method 'balance'") else if self.normal_credit_balance ^ contra credits_balance() - debits_balance() else debits_balance() - credits_balance() end end end |
#credits_balance(options = {}) ⇒ BigDecimal
The credit balance for the account.
Takes an optional hash specifying :from_date and :to_date for calculating balances during periods. :from_date and :to_date may be strings of the form “yyyy-mm-dd” or Ruby Date objects
97 98 99 |
# File 'app/models/plutus/account.rb', line 97 def credits_balance(={}) credit_amounts.balance() end |
#debits_balance(options = {}) ⇒ BigDecimal
The debit balance for the account.
Takes an optional hash specifying :from_date and :to_date for calculating balances during periods. :from_date and :to_date may be strings of the form “yyyy-mm-dd” or Ruby Date objects
115 116 117 |
# File 'app/models/plutus/account.rb', line 115 def debits_balance(={}) debit_amounts.balance() end |