plutus 0.5.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +116 -69
- data/Rakefile +7 -20
- data/app/assets/javascripts/plutus/application.js +15 -0
- data/app/assets/stylesheets/plutus/application.css +13 -0
- data/app/assets/stylesheets/plutus/main.css.scss +86 -0
- data/app/controllers/plutus/accounts_controller.rb +45 -0
- data/app/controllers/plutus/transactions_controller.rb +44 -0
- data/app/models/plutus/account.rb +60 -0
- data/app/models/plutus/amount.rb +16 -0
- data/app/models/plutus/asset.rb +83 -0
- data/app/models/plutus/credit_amount.rb +10 -0
- data/app/models/plutus/debit_amount.rb +10 -0
- data/app/models/plutus/equity.rb +84 -0
- data/app/models/plutus/expense.rb +83 -0
- data/app/models/plutus/liability.rb +78 -0
- data/app/models/plutus/revenue.rb +83 -0
- data/app/models/plutus/transaction.rb +83 -0
- data/app/views/{accounts → plutus/accounts}/index.html.erb +4 -2
- data/app/views/{accounts → plutus/accounts}/show.html.erb +8 -18
- data/app/views/plutus/transactions/index.html.erb +48 -0
- data/app/views/plutus/transactions/show.html.erb +46 -0
- data/config/database.yml +5 -0
- data/config/routes.rb +6 -0
- data/lib/generators/plutus/templates/migration.rb +17 -13
- data/lib/plutus.rb +3 -2
- data/lib/plutus/version.rb +3 -0
- data/spec/controllers/accounts_controller_spec.rb +22 -19
- data/spec/controllers/transactions_controller_spec.rb +23 -20
- data/spec/factories/account_factory.rb +30 -24
- data/spec/factories/amount_factory.rb +19 -0
- data/spec/factories/transaction_factory.rb +11 -6
- data/spec/models/account_spec.rb +61 -40
- data/spec/models/amount_spec.rb +12 -0
- data/spec/models/asset_spec.rb +46 -39
- data/spec/models/credit_amount_spec.rb +22 -0
- data/spec/models/debit_amount_spec.rb +22 -0
- data/spec/models/equity_spec.rb +51 -43
- data/spec/models/expense_spec.rb +49 -41
- data/spec/models/liability_spec.rb +48 -40
- data/spec/models/revenue_spec.rb +48 -41
- data/spec/models/transaction_spec.rb +77 -42
- data/spec/routing/accounts_routing_spec.rb +23 -20
- data/spec/routing/transactions_routing_spec.rb +23 -20
- data/spec/spec_helper.rb +3 -1
- metadata +208 -139
- data/.yardopts +0 -2
- data/VERSION.yml +0 -5
- data/app/controllers/accounts_controller.rb +0 -43
- data/app/controllers/transactions_controller.rb +0 -42
- data/app/models/account.rb +0 -57
- data/app/models/asset.rb +0 -81
- data/app/models/equity.rb +0 -82
- data/app/models/expense.rb +0 -81
- data/app/models/liability.rb +0 -76
- data/app/models/revenue.rb +0 -81
- data/app/models/transaction.rb +0 -27
- data/app/views/layouts/accounts.html.erb +0 -68
- data/app/views/layouts/transactions.html.erb +0 -68
- data/app/views/transactions/index.html.erb +0 -27
- data/app/views/transactions/show.html.erb +0 -24
- data/doc/Account.html +0 -300
- data/doc/AccountsController.html +0 -317
- data/doc/Asset.html +0 -610
- data/doc/CreatePlutusTables.html +0 -265
- data/doc/Equity.html +0 -610
- data/doc/Expense.html +0 -610
- data/doc/Liability.html +0 -588
- data/doc/Plutus.html +0 -91
- data/doc/Plutus/Engine.html +0 -100
- data/doc/PlutusGenerator.html +0 -312
- data/doc/Revenue.html +0 -610
- data/doc/Transaction.html +0 -156
- data/doc/TransactionsController.html +0 -317
- data/doc/_index.html +0 -204
- data/doc/class_list.html +0 -36
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -53
- data/doc/css/style.css +0 -310
- data/doc/file.README.html +0 -250
- data/doc/file_list.html +0 -38
- data/doc/frames.html +0 -13
- data/doc/index.html +0 -250
- data/doc/js/app.js +0 -202
- data/doc/js/full_list.js +0 -149
- data/doc/js/jquery.js +0 -154
- data/doc/method_list.html +0 -275
- data/doc/top-level-namespace.html +0 -90
- data/fixture_rails_root/.gitignore +0 -4
- data/fixture_rails_root/Gemfile +0 -38
- data/fixture_rails_root/Gemfile.lock +0 -98
- data/fixture_rails_root/README +0 -256
- data/fixture_rails_root/Rakefile +0 -7
- data/fixture_rails_root/app/controllers/application_controller.rb +0 -3
- data/fixture_rails_root/app/helpers/application_helper.rb +0 -2
- data/fixture_rails_root/app/views/layouts/application.html.erb +0 -14
- data/fixture_rails_root/config.ru +0 -4
- data/fixture_rails_root/config/application.rb +0 -42
- data/fixture_rails_root/config/boot.rb +0 -13
- data/fixture_rails_root/config/database.yml +0 -22
- data/fixture_rails_root/config/environment.rb +0 -5
- data/fixture_rails_root/config/environments/development.rb +0 -26
- data/fixture_rails_root/config/environments/production.rb +0 -49
- data/fixture_rails_root/config/environments/test.rb +0 -35
- data/fixture_rails_root/config/initializers/backtrace_silencers.rb +0 -7
- data/fixture_rails_root/config/initializers/inflections.rb +0 -10
- data/fixture_rails_root/config/initializers/mime_types.rb +0 -5
- data/fixture_rails_root/config/initializers/secret_token.rb +0 -7
- data/fixture_rails_root/config/initializers/session_store.rb +0 -8
- data/fixture_rails_root/config/locales/en.yml +0 -5
- data/fixture_rails_root/config/routes.rb +0 -58
- data/fixture_rails_root/db/migrate/20101203193439_create_plutus_tables.rb +0 -33
- data/fixture_rails_root/db/schema.rb +0 -40
- data/fixture_rails_root/db/seeds.rb +0 -7
- data/fixture_rails_root/doc/README_FOR_APP +0 -2
- data/fixture_rails_root/lib/tasks/.gitkeep +0 -0
- data/fixture_rails_root/public/404.html +0 -26
- data/fixture_rails_root/public/422.html +0 -26
- data/fixture_rails_root/public/500.html +0 -26
- data/fixture_rails_root/public/favicon.ico +0 -0
- data/fixture_rails_root/public/images/rails.png +0 -0
- data/fixture_rails_root/public/index.html +0 -239
- data/fixture_rails_root/public/javascripts/application.js +0 -2
- data/fixture_rails_root/public/javascripts/controls.js +0 -965
- data/fixture_rails_root/public/javascripts/dragdrop.js +0 -974
- data/fixture_rails_root/public/javascripts/effects.js +0 -1123
- data/fixture_rails_root/public/javascripts/prototype.js +0 -6001
- data/fixture_rails_root/public/javascripts/rails.js +0 -175
- data/fixture_rails_root/public/robots.txt +0 -5
- data/fixture_rails_root/public/stylesheets/.gitkeep +0 -0
- data/fixture_rails_root/script/rails +0 -6
- data/fixture_rails_root/test/performance/browsing_test.rb +0 -9
- data/fixture_rails_root/test/test_helper.rb +0 -13
- data/fixture_rails_root/vendor/plugins/.gitkeep +0 -0
- data/plutus.gemspec +0 -176
- data/tasks/plutus_tasks.rake +0 -4
@@ -0,0 +1,44 @@
|
|
1
|
+
module Plutus
|
2
|
+
# This controller provides restful route handling for Transactions.
|
3
|
+
#
|
4
|
+
# The controller supports ActiveResource, and provides for
|
5
|
+
# HMTL, XML, and JSON presentation.
|
6
|
+
#
|
7
|
+
# == Security:
|
8
|
+
# Only GET requests are supported. You should ensure that your application
|
9
|
+
# controller enforces its own authentication and authorization, which this
|
10
|
+
# controller will inherit.
|
11
|
+
#
|
12
|
+
# @author Michael Bulat
|
13
|
+
class TransactionsController < ApplicationController
|
14
|
+
unloadable
|
15
|
+
# @example
|
16
|
+
# GET /transactions
|
17
|
+
# GET /transactions.xml
|
18
|
+
# GET /transactions.json
|
19
|
+
def index
|
20
|
+
@transactions = Transaction.all
|
21
|
+
|
22
|
+
respond_to do |format|
|
23
|
+
format.html # index.html.erb
|
24
|
+
format.xml { render :xml => @transactions }
|
25
|
+
format.json { render :json => @transactions }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @example
|
30
|
+
# GET /transactions/1
|
31
|
+
# GET /transactions/1.xml
|
32
|
+
# GET /transactions/1.json
|
33
|
+
def show
|
34
|
+
@transaction = Transaction.find(params[:id])
|
35
|
+
|
36
|
+
respond_to do |format|
|
37
|
+
format.html # show.html.erb
|
38
|
+
format.xml { render :xml => @transaction }
|
39
|
+
format.json { render :json => @transaction }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Plutus
|
2
|
+
# The Account class represents accounts in the system. Each account must be subclassed as one of the following types:
|
3
|
+
#
|
4
|
+
# TYPE | NORMAL BALANCE | DESCRIPTION
|
5
|
+
# --------------------------------------------------------------------------
|
6
|
+
# Asset | Debit | Resources owned by the Business Entity
|
7
|
+
# Liability | Credit | Debts owed to outsiders
|
8
|
+
# Equity | Credit | Owners rights to the Assets
|
9
|
+
# Revenue | Credit | Increases in owners equity
|
10
|
+
# Expense | Debit | Assets or services consumed in the generation of revenue
|
11
|
+
#
|
12
|
+
# Each account can also be marked as a "Contra Account". A contra account will have it's
|
13
|
+
# normal balance swapped. For example, to remove equity, a "Drawing" account may be created
|
14
|
+
# as a contra equity account as follows:
|
15
|
+
#
|
16
|
+
# Plutus::Equity.create(:name => "Drawing", contra => true)
|
17
|
+
#
|
18
|
+
# At all times the balance of all accounts should conform to the "accounting equation"
|
19
|
+
# Plutus::Assets = Liabilties + Owner's Equity
|
20
|
+
#
|
21
|
+
# Each sublclass account acts as it's own ledger. See the individual subclasses for a
|
22
|
+
# description.
|
23
|
+
#
|
24
|
+
# @abstract
|
25
|
+
# An account must be a subclass to be saved to the database. The Account class
|
26
|
+
# has a singleton method {trial_balance} to calculate the balance on all Accounts.
|
27
|
+
#
|
28
|
+
# @see http://en.wikipedia.org/wiki/Accounting_equation Accounting Equation
|
29
|
+
# @see http://en.wikipedia.org/wiki/Debits_and_credits Debits, Credits, and Contra Accounts
|
30
|
+
#
|
31
|
+
# @author Michael Bulat
|
32
|
+
class Account < ActiveRecord::Base
|
33
|
+
attr_accessible :name
|
34
|
+
|
35
|
+
has_many :credit_amounts
|
36
|
+
has_many :debit_amounts
|
37
|
+
has_many :credit_transactions, :through => :credit_amounts, :source => :transaction
|
38
|
+
has_many :debit_transactions, :through => :debit_amounts, :source => :transaction
|
39
|
+
|
40
|
+
validates_presence_of :type, :name
|
41
|
+
validates_uniqueness_of :name
|
42
|
+
|
43
|
+
# The trial balance of all accounts in the system. This should always equal zero,
|
44
|
+
# otherwise there is an error in the system.
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# >> Account.trial_balance.to_i
|
48
|
+
# => 0
|
49
|
+
#
|
50
|
+
# @return [BigDecimal] The decimal value balance of all accounts
|
51
|
+
def self.trial_balance
|
52
|
+
unless self.new.class == Account
|
53
|
+
raise(NoMethodError, "undefined method 'trial_balance'")
|
54
|
+
else
|
55
|
+
Asset.balance - (Liability.balance + Equity.balance + Revenue.balance - Expense.balance)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Plutus
|
2
|
+
# The Amount class represents debit and credit amounts in the system.
|
3
|
+
#
|
4
|
+
# @abstract
|
5
|
+
# An amount must be a subclass as either a debit or a credit to be saved to the database.
|
6
|
+
#
|
7
|
+
# @author Michael Bulat
|
8
|
+
class Amount < ActiveRecord::Base
|
9
|
+
attr_accessible :account, :amount, :transaction
|
10
|
+
|
11
|
+
belongs_to :transaction
|
12
|
+
belongs_to :account
|
13
|
+
|
14
|
+
validates_presence_of :type, :amount, :transaction, :account
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Plutus
|
2
|
+
# The Asset class is an account type used to represents resources owned by the business entity.
|
3
|
+
#
|
4
|
+
# === Normal Balance
|
5
|
+
# The normal balance on Asset accounts is a *Debit*.
|
6
|
+
#
|
7
|
+
# @see http://en.wikipedia.org/wiki/Asset Assets
|
8
|
+
#
|
9
|
+
# @author Michael Bulat
|
10
|
+
class Asset < Account
|
11
|
+
|
12
|
+
# The credit balance for the account.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# >> asset.credits_balance
|
16
|
+
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
17
|
+
#
|
18
|
+
# @return [BigDecimal] The decimal value credit balance
|
19
|
+
def credits_balance
|
20
|
+
credits_balance = BigDecimal.new('0')
|
21
|
+
credit_amounts.each do |credit_amount|
|
22
|
+
credits_balance += credit_amount.amount
|
23
|
+
end
|
24
|
+
return credits_balance
|
25
|
+
end
|
26
|
+
|
27
|
+
# The debit balance for the account.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# >> asset.debits_balance
|
31
|
+
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
32
|
+
#
|
33
|
+
# @return [BigDecimal] The decimal value credit balance
|
34
|
+
def debits_balance
|
35
|
+
debits_balance = BigDecimal.new('0')
|
36
|
+
debit_amounts.each do |debit_amount|
|
37
|
+
debits_balance += debit_amount.amount
|
38
|
+
end
|
39
|
+
return debits_balance
|
40
|
+
end
|
41
|
+
|
42
|
+
# The balance of the account.
|
43
|
+
#
|
44
|
+
# Assets have normal debit balances, so the credits are subtracted from the debits
|
45
|
+
# unless this is a contra account, in which debits are subtracted from credits
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# >> asset.balance
|
49
|
+
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
|
50
|
+
#
|
51
|
+
# @return [BigDecimal] The decimal value balance
|
52
|
+
def balance
|
53
|
+
unless contra
|
54
|
+
debits_balance - credits_balance
|
55
|
+
else
|
56
|
+
credits_balance - debits_balance
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# This class method is used to return
|
61
|
+
# the balance of all Asset accounts.
|
62
|
+
#
|
63
|
+
# Contra accounts are automatically subtracted from the balance.
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# >> Plutus::Asset.balance
|
67
|
+
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
|
68
|
+
#
|
69
|
+
# @return [BigDecimal] The decimal value balance
|
70
|
+
def self.balance
|
71
|
+
accounts_balance = BigDecimal.new('0')
|
72
|
+
accounts = self.find(:all)
|
73
|
+
accounts.each do |asset|
|
74
|
+
unless asset.contra
|
75
|
+
accounts_balance += asset.balance
|
76
|
+
else
|
77
|
+
accounts_balance -= asset.balance
|
78
|
+
end
|
79
|
+
end
|
80
|
+
accounts_balance
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Plutus
|
2
|
+
# The CreditAmount class represents credit entries in the transaction journal.
|
3
|
+
#
|
4
|
+
# @example
|
5
|
+
# credit_amount = Plutus::CreditAmount.new(:account => revenue, :amount => 1000)
|
6
|
+
#
|
7
|
+
# @author Michael Bulat
|
8
|
+
class CreditAmount < Amount
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Plutus
|
2
|
+
# The Equity class is an account type used to represents owners rights to the assets.
|
3
|
+
#
|
4
|
+
# === Normal Balance
|
5
|
+
# The normal balance on Equity accounts is a *Credit*.
|
6
|
+
#
|
7
|
+
# @see http://en.wikipedia.org/wiki/Equity_(finance) Equity
|
8
|
+
#
|
9
|
+
# @author Michael Bulat
|
10
|
+
class Equity < Account
|
11
|
+
|
12
|
+
# The credit balance for the account.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# >> equity.credits_balance
|
16
|
+
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
17
|
+
#
|
18
|
+
# @return [BigDecimal] The decimal value credit balance
|
19
|
+
def credits_balance
|
20
|
+
credits_balance = BigDecimal.new('0')
|
21
|
+
credit_amounts.each do |credit_amount|
|
22
|
+
credits_balance = credits_balance + credit_amount.amount
|
23
|
+
end
|
24
|
+
return credits_balance
|
25
|
+
end
|
26
|
+
|
27
|
+
# The debit balance for the account.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# >> equity.debits_balance
|
31
|
+
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
32
|
+
#
|
33
|
+
# @return [BigDecimal] The decimal value credit balance
|
34
|
+
def debits_balance
|
35
|
+
debits_balance = BigDecimal.new('0')
|
36
|
+
debit_amounts.each do |debit_amount|
|
37
|
+
debits_balance = debits_balance + debit_amount.amount
|
38
|
+
end
|
39
|
+
return debits_balance
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# The balance of the account.
|
44
|
+
#
|
45
|
+
# Equity accounts have normal credit balances, so the debits are subtracted from the credits
|
46
|
+
# unless this is a contra account, in which credits are subtracted from debits
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# >> asset.balance
|
50
|
+
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
|
51
|
+
#
|
52
|
+
# @return [BigDecimal] The decimal value balance
|
53
|
+
def balance
|
54
|
+
unless contra
|
55
|
+
credits_balance - debits_balance
|
56
|
+
else
|
57
|
+
debits_balance - credits_balance
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# This class method is used to return
|
62
|
+
# the balance of all Equity accounts.
|
63
|
+
#
|
64
|
+
# Contra accounts are automatically subtracted from the balance.
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# >> Plutus::Equity.balance
|
68
|
+
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
|
69
|
+
#
|
70
|
+
# @return [BigDecimal] The decimal value balance
|
71
|
+
def self.balance
|
72
|
+
accounts_balance = BigDecimal.new('0')
|
73
|
+
accounts = self.find(:all)
|
74
|
+
accounts.each do |equity|
|
75
|
+
unless equity.contra
|
76
|
+
accounts_balance += equity.balance
|
77
|
+
else
|
78
|
+
accounts_balance -= equity.balance
|
79
|
+
end
|
80
|
+
end
|
81
|
+
accounts_balance
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Plutus
|
2
|
+
# The Expense class is an account type used to represents assets or services consumed in the generation of revenue.
|
3
|
+
#
|
4
|
+
# === Normal Balance
|
5
|
+
# The normal balance on Expense accounts is a *Debit*.
|
6
|
+
#
|
7
|
+
# @see http://en.wikipedia.org/wiki/Expense Expenses
|
8
|
+
#
|
9
|
+
# @author Michael Bulat
|
10
|
+
class Expense < Account
|
11
|
+
|
12
|
+
# The credit balance for the account.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# >> expense.credits_balance
|
16
|
+
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
17
|
+
#
|
18
|
+
# @return [BigDecimal] The decimal value credit balance
|
19
|
+
def credits_balance
|
20
|
+
credits_balance = BigDecimal.new('0')
|
21
|
+
credit_amounts.each do |credit_amount|
|
22
|
+
credits_balance = credits_balance + credit_amount.amount
|
23
|
+
end
|
24
|
+
return credits_balance
|
25
|
+
end
|
26
|
+
|
27
|
+
# The debit balance for the account.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# >> expense.debits_balance
|
31
|
+
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
32
|
+
#
|
33
|
+
# @return [BigDecimal] The decimal value credit balance
|
34
|
+
def debits_balance
|
35
|
+
debits_balance = BigDecimal.new('0')
|
36
|
+
debit_amounts.each do |debit_amount|
|
37
|
+
debits_balance = debits_balance + debit_amount.amount
|
38
|
+
end
|
39
|
+
return debits_balance
|
40
|
+
end
|
41
|
+
|
42
|
+
# The balance of the account.
|
43
|
+
#
|
44
|
+
# Expenses have normal debit balances, so the credits are subtracted from the debits
|
45
|
+
# unless this is a contra account, in which debits are subtracted from credits
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# >> expense.balance
|
49
|
+
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
|
50
|
+
#
|
51
|
+
# @return [BigDecimal] The decimal value balance
|
52
|
+
def balance
|
53
|
+
unless contra
|
54
|
+
debits_balance - credits_balance
|
55
|
+
else
|
56
|
+
credits_balance - debits_balance
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# This class method is used to return
|
61
|
+
# the balance of all Expense accounts.
|
62
|
+
#
|
63
|
+
# Contra accounts are automatically subtracted from the balance.
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# >> Plutus::Expense.balance
|
67
|
+
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
|
68
|
+
#
|
69
|
+
# @return [BigDecimal] The decimal value balance
|
70
|
+
def self.balance
|
71
|
+
accounts_balance = BigDecimal.new('0')
|
72
|
+
accounts = self.find(:all)
|
73
|
+
accounts.each do |expense|
|
74
|
+
unless expense.contra
|
75
|
+
accounts_balance += expense.balance
|
76
|
+
else
|
77
|
+
accounts_balance -= expense.balance
|
78
|
+
end
|
79
|
+
end
|
80
|
+
accounts_balance
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Plutus
|
2
|
+
# The Liability class is an account type used to represents debts owed to outsiders.
|
3
|
+
#
|
4
|
+
# === Normal Balance
|
5
|
+
# The normal balance on Liability accounts is a *Credit*.
|
6
|
+
#
|
7
|
+
# @see http://en.wikipedia.org/wiki/Liability_(financial_accounting) Liability
|
8
|
+
#
|
9
|
+
# @author Michael Bulat
|
10
|
+
class Liability < Account
|
11
|
+
|
12
|
+
# The credit balance for the account.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# >> liability.credits_balance
|
16
|
+
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
17
|
+
#
|
18
|
+
# @return [BigDecimal] The decimal value credit balance
|
19
|
+
def credits_balance
|
20
|
+
credits_balance = BigDecimal.new('0')
|
21
|
+
credit_amounts.each do |credit_amount|
|
22
|
+
credits_balance = credits_balance + credit_amount.amount
|
23
|
+
end
|
24
|
+
return credits_balance
|
25
|
+
end
|
26
|
+
|
27
|
+
# The debit balance for the account.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# >> liability.debits_balance
|
31
|
+
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
32
|
+
#
|
33
|
+
# @return [BigDecimal] The decimal value credit balance
|
34
|
+
def debits_balance
|
35
|
+
debits_balance = BigDecimal.new('0')
|
36
|
+
debit_amounts.each do |debit_amount|
|
37
|
+
debits_balance = debits_balance + debit_amount.amount
|
38
|
+
end
|
39
|
+
return debits_balance
|
40
|
+
end
|
41
|
+
|
42
|
+
# The balance of the account.
|
43
|
+
#
|
44
|
+
# Liability accounts have normal credit balances, so the debits are subtracted from the credits
|
45
|
+
# unless this is a contra account, in which credits are subtracted from debits
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# >> liability.balance
|
49
|
+
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
|
50
|
+
#
|
51
|
+
# @return [BigDecimal] The decimal value balance
|
52
|
+
def balance
|
53
|
+
unless contra
|
54
|
+
credits_balance - debits_balance
|
55
|
+
else
|
56
|
+
debits_balance - credits_balance
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Balance of all Liability accounts
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# >> Plutus::Liability.balance
|
64
|
+
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
|
65
|
+
def self.balance
|
66
|
+
accounts_balance = BigDecimal.new('0')
|
67
|
+
accounts = self.find(:all)
|
68
|
+
accounts.each do |liability|
|
69
|
+
unless liability.contra
|
70
|
+
accounts_balance += liability.balance
|
71
|
+
else
|
72
|
+
accounts_balance -= liability.balance
|
73
|
+
end
|
74
|
+
end
|
75
|
+
accounts_balance
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|