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
data/.yardopts
DELETED
data/VERSION.yml
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# This controller provides restful route handling for Accounts.
|
2
|
-
#
|
3
|
-
# The controller supports ActiveResource, and provides for
|
4
|
-
# HMTL, XML, and JSON presentation.
|
5
|
-
#
|
6
|
-
# == Security:
|
7
|
-
# Only GET requests are supported. You should ensure that your application
|
8
|
-
# controller enforces its own authentication and authorization, which this
|
9
|
-
# controller will inherit.
|
10
|
-
#
|
11
|
-
# @author Michael Bulat
|
12
|
-
class AccountsController < ApplicationController
|
13
|
-
unloadable
|
14
|
-
|
15
|
-
# @example
|
16
|
-
# GET /accounts
|
17
|
-
# GET /accounts.xml
|
18
|
-
# GET /accounts.json
|
19
|
-
def index
|
20
|
-
@accounts = Account.all
|
21
|
-
|
22
|
-
respond_to do |format|
|
23
|
-
format.html # index.html.erb
|
24
|
-
format.xml { render :xml => @accounts }
|
25
|
-
format.json { render :json => @accounts }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# @example
|
30
|
-
# GET /accounts/1
|
31
|
-
# GET /accounts/1.xml
|
32
|
-
# GET /accounts/1.json
|
33
|
-
def show
|
34
|
-
@account = Account.find(params[:id])
|
35
|
-
|
36
|
-
respond_to do |format|
|
37
|
-
format.html # show.html.erb
|
38
|
-
format.xml { render :xml => @account }
|
39
|
-
format.json { render :json => @account }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# This controller provides restful route handling for Transactions.
|
2
|
-
#
|
3
|
-
# The controller supports ActiveResource, and provides for
|
4
|
-
# HMTL, XML, and JSON presentation.
|
5
|
-
#
|
6
|
-
# == Security:
|
7
|
-
# Only GET requests are supported. You should ensure that your application
|
8
|
-
# controller enforces its own authentication and authorization, which this
|
9
|
-
# controller will inherit.
|
10
|
-
#
|
11
|
-
# @author Michael Bulat
|
12
|
-
class TransactionsController < ApplicationController
|
13
|
-
unloadable
|
14
|
-
# @example
|
15
|
-
# GET /transactions
|
16
|
-
# GET /transactions.xml
|
17
|
-
# GET /transactions.json
|
18
|
-
def index
|
19
|
-
@transactions = Transaction.all
|
20
|
-
|
21
|
-
respond_to do |format|
|
22
|
-
format.html # index.html.erb
|
23
|
-
format.xml { render :xml => @transactions }
|
24
|
-
format.json { render :json => @transactions }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# @example
|
29
|
-
# GET /transactions/1
|
30
|
-
# GET /transactions/1.xml
|
31
|
-
# GET /transactions/1.json
|
32
|
-
def show
|
33
|
-
@transaction = Transaction.find(params[:id])
|
34
|
-
|
35
|
-
respond_to do |format|
|
36
|
-
format.html # show.html.erb
|
37
|
-
format.xml { render :xml => @transaction }
|
38
|
-
format.json { render :json => @transaction }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
data/app/models/account.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# == Overview:
|
3
|
-
#
|
4
|
-
# The Account class represents accounts in the system. Each account must be subclassed as one of the following types:
|
5
|
-
#
|
6
|
-
# TYPE | NORMAL BALANCE | DESCRIPTION
|
7
|
-
# --------------------------------------------------------------------------
|
8
|
-
# Asset | Debit | Resources owned by the Business Entity
|
9
|
-
# Liability | Credit | Debts owed to outsiders
|
10
|
-
# Equity | Credit | Owners rights to the Assets
|
11
|
-
# Revenue | Credit | Increases in owners equity
|
12
|
-
# Expense | Debit | Assets or services consumed in the generation of revenue
|
13
|
-
#
|
14
|
-
# Each account can also be marked as a "Contra Account". A contra account will have it's
|
15
|
-
# normal balance swapped. For example, to remove equity, a "Drawing" account may be created
|
16
|
-
# as a contra equity account as follows:
|
17
|
-
#
|
18
|
-
# Equity.create(:name => "Drawing", contra => true)
|
19
|
-
#
|
20
|
-
# At all times the balance of all accounts should conform to the "accounting equation"
|
21
|
-
# Assets = Liabilties + Owner's Equity
|
22
|
-
#
|
23
|
-
# Each sublclass account acts as it's own ledger. See the individual subclasses for a
|
24
|
-
# description.
|
25
|
-
#
|
26
|
-
# @abstract
|
27
|
-
# An account must be a subclass to be saved to the database. The Account class
|
28
|
-
# has a singleton method {trial_balance} to calculate the balance on all Accounts.
|
29
|
-
#
|
30
|
-
# @see http://en.wikipedia.org/wiki/Accounting_equation Accounting Equation
|
31
|
-
# @see http://en.wikipedia.org/wiki/Debits_and_credits Debits, Credits, and Contra Accounts
|
32
|
-
#
|
33
|
-
# @author Michael Bulat
|
34
|
-
class Account < ActiveRecord::Base
|
35
|
-
|
36
|
-
validates_presence_of :type, :name
|
37
|
-
|
38
|
-
has_many :credit_transactions, :class_name => "Transaction", :foreign_key => "credit_account_id"
|
39
|
-
has_many :debit_transactions, :class_name => "Transaction", :foreign_key => "debit_account_id"
|
40
|
-
|
41
|
-
# The trial balance of all accounts in the system. This should always equal zero,
|
42
|
-
# otherwise there is an error in the system.
|
43
|
-
#
|
44
|
-
# @example
|
45
|
-
# >> Account.trial_balance.to_i
|
46
|
-
# => 0
|
47
|
-
#
|
48
|
-
# @return [BigDecimal] The decimal value balance of all accounts
|
49
|
-
def self.trial_balance
|
50
|
-
unless self.new.class == Account
|
51
|
-
raise(NoMethodError, "undefined method 'trial_balance'")
|
52
|
-
else
|
53
|
-
Asset.balance - (Liability.balance + Equity.balance + Revenue.balance - Expense.balance)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
data/app/models/asset.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# The Asset class is an account type used to represents resources owned by the business entity.
|
2
|
-
#
|
3
|
-
# === Normal Balance
|
4
|
-
# The normal balance on Asset accounts is a *Debit*.
|
5
|
-
#
|
6
|
-
# @see http://en.wikipedia.org/wiki/Asset Assets
|
7
|
-
#
|
8
|
-
# @author Michael Bulat
|
9
|
-
class Asset < Account
|
10
|
-
|
11
|
-
# The credit balance for the account.
|
12
|
-
#
|
13
|
-
# @example
|
14
|
-
# >> asset.credits_balance
|
15
|
-
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
16
|
-
#
|
17
|
-
# @return [BigDecimal] The decimal value credit balance
|
18
|
-
def credits_balance
|
19
|
-
credits_balance = BigDecimal.new('0')
|
20
|
-
credit_transactions.each do |credit_transaction|
|
21
|
-
credits_balance += credit_transaction.amount
|
22
|
-
end
|
23
|
-
return credits_balance
|
24
|
-
end
|
25
|
-
|
26
|
-
# The debit balance for the account.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# >> asset.debits_balance
|
30
|
-
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
31
|
-
#
|
32
|
-
# @return [BigDecimal] The decimal value credit balance
|
33
|
-
def debits_balance
|
34
|
-
debits_balance = BigDecimal.new('0')
|
35
|
-
debit_transactions.each do |debit_transaction|
|
36
|
-
debits_balance += debit_transaction.amount
|
37
|
-
end
|
38
|
-
return debits_balance
|
39
|
-
end
|
40
|
-
|
41
|
-
# The balance of the account.
|
42
|
-
#
|
43
|
-
# Assets have normal debit balances, so the credits are subtracted from the debits
|
44
|
-
# unless this is a contra account, in which debits are subtracted from credits
|
45
|
-
#
|
46
|
-
# @example
|
47
|
-
# >> asset.balance
|
48
|
-
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
|
49
|
-
#
|
50
|
-
# @return [BigDecimal] The decimal value balance
|
51
|
-
def balance
|
52
|
-
unless contra
|
53
|
-
debits_balance - credits_balance
|
54
|
-
else
|
55
|
-
credits_balance - debits_balance
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# This class method is used to return
|
60
|
-
# the balance of all Asset accounts.
|
61
|
-
#
|
62
|
-
# Contra accounts are automatically subtracted from the balance.
|
63
|
-
#
|
64
|
-
# @example
|
65
|
-
# >> Asset.balance
|
66
|
-
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
|
67
|
-
#
|
68
|
-
# @return [BigDecimal] The decimal value balance
|
69
|
-
def self.balance
|
70
|
-
accounts_balance = BigDecimal.new('0')
|
71
|
-
accounts = self.find(:all)
|
72
|
-
accounts.each do |asset|
|
73
|
-
unless asset.contra
|
74
|
-
accounts_balance += asset.balance
|
75
|
-
else
|
76
|
-
accounts_balance -= asset.balance
|
77
|
-
end
|
78
|
-
end
|
79
|
-
accounts_balance
|
80
|
-
end
|
81
|
-
end
|
data/app/models/equity.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# The Equity class is an account type used to represents owners rights to the assets.
|
2
|
-
#
|
3
|
-
# === Normal Balance
|
4
|
-
# The normal balance on Equity accounts is a *Credit*.
|
5
|
-
#
|
6
|
-
# @see http://en.wikipedia.org/wiki/Equity_(finance) Equity
|
7
|
-
#
|
8
|
-
# @author Michael Bulat
|
9
|
-
class Equity < Account
|
10
|
-
|
11
|
-
# The credit balance for the account.
|
12
|
-
#
|
13
|
-
# @example
|
14
|
-
# >> equity.credits_balance
|
15
|
-
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
16
|
-
#
|
17
|
-
# @return [BigDecimal] The decimal value credit balance
|
18
|
-
def credits_balance
|
19
|
-
credits_balance = BigDecimal.new('0')
|
20
|
-
credit_transactions.each do |credit_transaction|
|
21
|
-
credits_balance = credits_balance + credit_transaction.amount
|
22
|
-
end
|
23
|
-
return credits_balance
|
24
|
-
end
|
25
|
-
|
26
|
-
# The debit balance for the account.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# >> equity.debits_balance
|
30
|
-
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
31
|
-
#
|
32
|
-
# @return [BigDecimal] The decimal value credit balance
|
33
|
-
def debits_balance
|
34
|
-
debits_balance = BigDecimal.new('0')
|
35
|
-
debit_transactions.each do |debit_transaction|
|
36
|
-
debits_balance = debits_balance + debit_transaction.amount
|
37
|
-
end
|
38
|
-
return debits_balance
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
# The balance of the account.
|
43
|
-
#
|
44
|
-
# Equity 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
|
-
# >> asset.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
|
-
# This class method is used to return
|
61
|
-
# the balance of all Equity accounts.
|
62
|
-
#
|
63
|
-
# Contra accounts are automatically subtracted from the balance.
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# >> Equity.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 |equity|
|
74
|
-
unless equity.contra
|
75
|
-
accounts_balance += equity.balance
|
76
|
-
else
|
77
|
-
accounts_balance -= equity.balance
|
78
|
-
end
|
79
|
-
end
|
80
|
-
accounts_balance
|
81
|
-
end
|
82
|
-
end
|
data/app/models/expense.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# The Expense class is an account type used to represents assets or services consumed in the generation of revenue.
|
2
|
-
#
|
3
|
-
# === Normal Balance
|
4
|
-
# The normal balance on Expense accounts is a *Debit*.
|
5
|
-
#
|
6
|
-
# @see http://en.wikipedia.org/wiki/Expense Expenses
|
7
|
-
#
|
8
|
-
# @author Michael Bulat
|
9
|
-
class Expense < Account
|
10
|
-
|
11
|
-
# The credit balance for the account.
|
12
|
-
#
|
13
|
-
# @example
|
14
|
-
# >> expense.credits_balance
|
15
|
-
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
16
|
-
#
|
17
|
-
# @return [BigDecimal] The decimal value credit balance
|
18
|
-
def credits_balance
|
19
|
-
credits_balance = BigDecimal.new('0')
|
20
|
-
credit_transactions.each do |credit_transaction|
|
21
|
-
credits_balance = credits_balance + credit_transaction.amount
|
22
|
-
end
|
23
|
-
return credits_balance
|
24
|
-
end
|
25
|
-
|
26
|
-
# The debit balance for the account.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# >> expense.debits_balance
|
30
|
-
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
31
|
-
#
|
32
|
-
# @return [BigDecimal] The decimal value credit balance
|
33
|
-
def debits_balance
|
34
|
-
debits_balance = BigDecimal.new('0')
|
35
|
-
debit_transactions.each do |debit_transaction|
|
36
|
-
debits_balance = debits_balance + debit_transaction.amount
|
37
|
-
end
|
38
|
-
return debits_balance
|
39
|
-
end
|
40
|
-
|
41
|
-
# The balance of the account.
|
42
|
-
#
|
43
|
-
# Expenses have normal debit balances, so the credits are subtracted from the debits
|
44
|
-
# unless this is a contra account, in which debits are subtracted from credits
|
45
|
-
#
|
46
|
-
# @example
|
47
|
-
# >> expense.balance
|
48
|
-
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
|
49
|
-
#
|
50
|
-
# @return [BigDecimal] The decimal value balance
|
51
|
-
def balance
|
52
|
-
unless contra
|
53
|
-
debits_balance - credits_balance
|
54
|
-
else
|
55
|
-
credits_balance - debits_balance
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# This class method is used to return
|
60
|
-
# the balance of all Expense accounts.
|
61
|
-
#
|
62
|
-
# Contra accounts are automatically subtracted from the balance.
|
63
|
-
#
|
64
|
-
# @example
|
65
|
-
# >> Expense.balance
|
66
|
-
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
|
67
|
-
#
|
68
|
-
# @return [BigDecimal] The decimal value balance
|
69
|
-
def self.balance
|
70
|
-
accounts_balance = BigDecimal.new('0')
|
71
|
-
accounts = self.find(:all)
|
72
|
-
accounts.each do |expense|
|
73
|
-
unless expense.contra
|
74
|
-
accounts_balance += expense.balance
|
75
|
-
else
|
76
|
-
accounts_balance -= expense.balance
|
77
|
-
end
|
78
|
-
end
|
79
|
-
accounts_balance
|
80
|
-
end
|
81
|
-
end
|
data/app/models/liability.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# The Liability class is an account type used to represents debts owed to outsiders.
|
2
|
-
#
|
3
|
-
# === Normal Balance
|
4
|
-
# The normal balance on Liability accounts is a *Credit*.
|
5
|
-
#
|
6
|
-
# @see http://en.wikipedia.org/wiki/Liability_(financial_accounting) Liability
|
7
|
-
#
|
8
|
-
# @author Michael Bulat
|
9
|
-
class Liability < Account
|
10
|
-
|
11
|
-
# The credit balance for the account.
|
12
|
-
#
|
13
|
-
# @example
|
14
|
-
# >> liability.credits_balance
|
15
|
-
# => #<BigDecimal:103259bb8,'0.3E4',4(12)>
|
16
|
-
#
|
17
|
-
# @return [BigDecimal] The decimal value credit balance
|
18
|
-
def credits_balance
|
19
|
-
credits_balance = BigDecimal.new('0')
|
20
|
-
credit_transactions.each do |credit_transaction|
|
21
|
-
credits_balance = credits_balance + credit_transaction.amount
|
22
|
-
end
|
23
|
-
return credits_balance
|
24
|
-
end
|
25
|
-
|
26
|
-
# The debit balance for the account.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# >> liability.debits_balance
|
30
|
-
# => #<BigDecimal:103259bb8,'0.1E4',4(12)>
|
31
|
-
#
|
32
|
-
# @return [BigDecimal] The decimal value credit balance
|
33
|
-
def debits_balance
|
34
|
-
debits_balance = BigDecimal.new('0')
|
35
|
-
debit_transactions.each do |debit_transaction|
|
36
|
-
debits_balance = debits_balance + debit_transaction.amount
|
37
|
-
end
|
38
|
-
return debits_balance
|
39
|
-
end
|
40
|
-
|
41
|
-
# The balance of the account.
|
42
|
-
#
|
43
|
-
# Liability accounts have normal credit balances, so the debits are subtracted from the credits
|
44
|
-
# unless this is a contra account, in which credits are subtracted from debits
|
45
|
-
#
|
46
|
-
# @example
|
47
|
-
# >> liability.balance
|
48
|
-
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
|
49
|
-
#
|
50
|
-
# @return [BigDecimal] The decimal value balance
|
51
|
-
def balance
|
52
|
-
unless contra
|
53
|
-
credits_balance - debits_balance
|
54
|
-
else
|
55
|
-
debits_balance - credits_balance
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Balance of all Liability accounts
|
60
|
-
#
|
61
|
-
# @example
|
62
|
-
# >> Liability.balance
|
63
|
-
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
|
64
|
-
def self.balance
|
65
|
-
accounts_balance = BigDecimal.new('0')
|
66
|
-
accounts = self.find(:all)
|
67
|
-
accounts.each do |liability|
|
68
|
-
unless liability.contra
|
69
|
-
accounts_balance += liability.balance
|
70
|
-
else
|
71
|
-
accounts_balance -= liability.balance
|
72
|
-
end
|
73
|
-
end
|
74
|
-
accounts_balance
|
75
|
-
end
|
76
|
-
end
|