blawzoo-plutus 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.yardopts +2 -0
  2. data/LICENSE +23 -0
  3. data/README.markdown +197 -0
  4. data/Rakefile +11 -0
  5. data/VERSION.yml +5 -0
  6. data/app/controllers/accounts_controller.rb +43 -0
  7. data/app/controllers/transactions_controller.rb +42 -0
  8. data/app/models/account.rb +57 -0
  9. data/app/models/asset.rb +81 -0
  10. data/app/models/equity.rb +82 -0
  11. data/app/models/expense.rb +81 -0
  12. data/app/models/liability.rb +76 -0
  13. data/app/models/revenue.rb +81 -0
  14. data/app/models/transaction.rb +27 -0
  15. data/app/views/accounts/index.html.erb +27 -0
  16. data/app/views/accounts/show.html.erb +69 -0
  17. data/app/views/layouts/accounts.html.erb +68 -0
  18. data/app/views/layouts/transactions.html.erb +68 -0
  19. data/app/views/transactions/index.html.erb +27 -0
  20. data/app/views/transactions/show.html.erb +24 -0
  21. data/doc/Account.html +300 -0
  22. data/doc/AccountsController.html +317 -0
  23. data/doc/Asset.html +610 -0
  24. data/doc/Equity.html +610 -0
  25. data/doc/Expense.html +610 -0
  26. data/doc/Liability.html +588 -0
  27. data/doc/Revenue.html +610 -0
  28. data/doc/Transaction.html +156 -0
  29. data/doc/TransactionsController.html +317 -0
  30. data/doc/_index.html +204 -0
  31. data/doc/class_list.html +36 -0
  32. data/doc/file.README.html +250 -0
  33. data/doc/file_list.html +38 -0
  34. data/doc/frames.html +13 -0
  35. data/doc/index.html +250 -0
  36. data/doc/js/app.js +202 -0
  37. data/doc/js/full_list.js +149 -0
  38. data/doc/js/jquery.js +154 -0
  39. data/doc/method_list.html +275 -0
  40. data/doc/top-level-namespace.html +90 -0
  41. data/lib/plutus.rb +6 -0
  42. data/plutus.gemspec +116 -0
  43. data/spec/controllers/accounts_controller_spec.rb +26 -0
  44. data/spec/controllers/transactions_controller_spec.rb +26 -0
  45. data/spec/factories/account_factory.rb +31 -0
  46. data/spec/factories/transaction_factory.rb +6 -0
  47. data/spec/lib/plutus_spec.rb +0 -0
  48. data/spec/models/account_spec.rb +43 -0
  49. data/spec/models/asset_spec.rb +46 -0
  50. data/spec/models/equity_spec.rb +46 -0
  51. data/spec/models/expense_spec.rb +46 -0
  52. data/spec/models/liability_spec.rb +46 -0
  53. data/spec/models/revenue_spec.rb +46 -0
  54. data/spec/models/transaction_spec.rb +48 -0
  55. data/spec/rcov.opts +2 -0
  56. data/spec/routing/accounts_routing_spec.rb +30 -0
  57. data/spec/routing/transactions_routing_spec.rb +30 -0
  58. data/spec/schema.rb +31 -0
  59. data/spec/spec.opts +4 -0
  60. data/spec/spec_helper.rb +14 -0
  61. data/tasks/plutus_tasks.rake +4 -0
  62. metadata +204 -0
@@ -0,0 +1,82 @@
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
@@ -0,0 +1,81 @@
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
@@ -0,0 +1,76 @@
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
@@ -0,0 +1,81 @@
1
+ # The Revenue class is an account type used to represents increases in owners equity.
2
+ #
3
+ # === Normal Balance
4
+ # The normal balance on Revenue accounts is a *Credit*.
5
+ #
6
+ # @see http://en.wikipedia.org/wiki/Revenue Revenue
7
+ #
8
+ # @author Michael Bulat
9
+ class Revenue < Account
10
+
11
+ # The credit balance for the account.
12
+ #
13
+ # @example
14
+ # >> revenue.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
+ # >> revenue.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
+ # Revenue 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
+ # >> asset.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
+ # This class method is used to return
60
+ # the balance of all Revenue accounts.
61
+ #
62
+ # Contra accounts are automatically subtracted from the balance.
63
+ #
64
+ # @example
65
+ # >> Revenue.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 |revenue|
73
+ unless revenue.contra
74
+ accounts_balance += revenue.balance
75
+ else
76
+ accounts_balance -= revenue.balance
77
+ end
78
+ end
79
+ accounts_balance
80
+ end
81
+ end
@@ -0,0 +1,27 @@
1
+ # Transactions are the recording of debits and credits to various accounts.
2
+ # This table can be thought of as a traditional accounting Journal.
3
+ #
4
+ # Posting to a Ledger can be considered to happen automatically, since
5
+ # Accounts have the reverse 'has_many' relationship to either it's credit or
6
+ # debit transactions
7
+ #
8
+ # @example
9
+ # cash = Asset.find_by_name('Cash')
10
+ # accounts_receivable = Asset.find_by_name('Accounts Receivable')
11
+ #
12
+ # Transaction.create(:description => "Receiving payment on an invoice" ,
13
+ # :debit_account => cash,
14
+ # :credit_account => accounts_receivable,
15
+ # :amount => 1000)
16
+ #
17
+ # @see http://en.wikipedia.org/wiki/Journal_entry Journal Entry
18
+ #
19
+ # @author Michael Bulat
20
+ class Transaction < ActiveRecord::Base
21
+ belongs_to :commercial_document, :polymorphic => true
22
+ belongs_to :credit_account, :class_name => "Account"
23
+ belongs_to :debit_account, :class_name => "Account"
24
+
25
+ validates_presence_of :credit_account, :debit_account, :amount, :description
26
+ validates_associated :credit_account, :debit_account
27
+ end
@@ -0,0 +1,27 @@
1
+ <h1>Listing Accounts</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th class="nobg">ID</th>
6
+ <th>Name</th>
7
+ <th>Type</th>
8
+ <th>Credit Balance</th>
9
+ <th>Debit Balance</th>
10
+ <th>Balance</td>
11
+ </tr>
12
+
13
+ <% @accounts.each do |account| %>
14
+ <tr class="<%= cycle("even", "odd") -%>">
15
+ <td><%=h account.id %></td>
16
+ <td><%=h account.name %></td>
17
+ <td><%=h account.type %></td>
18
+ <td><%=h account.credits_balance %></td>
19
+ <td><%=h account.debits_balance %></td>
20
+ <td><%=h account.balance %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <h3>Go to <%= link_to 'Transactions', transactions_path %></h3>
@@ -0,0 +1,69 @@
1
+ <h1><%=h @account.name %> Account</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th class="nobg">ID</th>
6
+ <th>Name</th>
7
+ <th>Type</th>
8
+ <th>Credit Balance</th>
9
+ <th>Debit Balance</th>
10
+ <th>Balance</td>
11
+ </tr>
12
+
13
+ <tr class="odd">
14
+ <td><%=h @account.id %></td>
15
+ <td><%=h @account.name %></td>
16
+ <td><%=h @account.type %></td>
17
+ <td><%=h @account.credits_balance %></td>
18
+ <td><%=h @account.debits_balance %></td>
19
+ <td><%=h @account.balance %></td>
20
+ </tr>
21
+ </table>
22
+
23
+ <h1>Credit Transactions</h1>
24
+
25
+ <table>
26
+ <tr>
27
+ <th class="nobg">ID</th>
28
+ <th>Description</th>
29
+ <th>Credit Account</th>
30
+ <th>Debit Account</th>
31
+ <th>Amount</th>
32
+ <th>Date</th>
33
+ </tr>
34
+
35
+ <% @account.credit_transactions.each do |transaction| %>
36
+ <tr class="<%= cycle("even", "odd") -%>">
37
+ <td><%=h transaction.id %></td>
38
+ <td><%=h transaction.description %></td>
39
+ <td><%=h transaction.credit_account.name %></td>
40
+ <td><%=h transaction.debit_account.name %></td>
41
+ <td><%=h transaction.amount %></td>
42
+ <td><%=h transaction.created_at %></td>
43
+ </tr>
44
+ <% end %>
45
+ </table>
46
+
47
+ <h1>Debit Transactions</h1>
48
+
49
+ <table>
50
+ <tr>
51
+ <th class="nobg">ID</th>
52
+ <th>Description</th>
53
+ <th>Credit Account</th>
54
+ <th>Debit Account</th>
55
+ <th>Amount</th>
56
+ <th>Date</th>
57
+ </tr>
58
+
59
+ <% @account.debit_transactions.each do |transaction| %>
60
+ <tr class="<%= cycle("even", "odd") -%>">
61
+ <td><%=h transaction.id %></td>
62
+ <td><%=h transaction.description %></td>
63
+ <td><%=h transaction.credit_account.name %></td>
64
+ <td><%=h transaction.debit_account.name %></td>
65
+ <td><%=h transaction.amount %></td>
66
+ <td><%=h transaction.created_at %></td>
67
+ </tr>
68
+ <% end %>
69
+ </table>