plutus 0.5.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,83 @@
|
|
|
1
|
+
module Plutus
|
|
2
|
+
# The Revenue class is an account type used to represents increases in owners equity.
|
|
3
|
+
#
|
|
4
|
+
# === Normal Balance
|
|
5
|
+
# The normal balance on Revenue accounts is a *Credit*.
|
|
6
|
+
#
|
|
7
|
+
# @see http://en.wikipedia.org/wiki/Revenue Revenue
|
|
8
|
+
#
|
|
9
|
+
# @author Michael Bulat
|
|
10
|
+
class Revenue < Account
|
|
11
|
+
|
|
12
|
+
# The credit balance for the account.
|
|
13
|
+
#
|
|
14
|
+
# @example
|
|
15
|
+
# >> revenue.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
|
+
# >> revenue.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
|
+
# Revenue 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 Revenue accounts.
|
|
62
|
+
#
|
|
63
|
+
# Contra accounts are automatically subtracted from the balance.
|
|
64
|
+
#
|
|
65
|
+
# @example
|
|
66
|
+
# >> Plutus::Revenue.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 |revenue|
|
|
74
|
+
unless revenue.contra
|
|
75
|
+
accounts_balance += revenue.balance
|
|
76
|
+
else
|
|
77
|
+
accounts_balance -= revenue.balance
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
accounts_balance
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Plutus
|
|
2
|
+
# Transactions are the recording of debits and credits to various accounts.
|
|
3
|
+
# This table can be thought of as a traditional accounting Journal.
|
|
4
|
+
#
|
|
5
|
+
# Posting to a Ledger can be considered to happen automatically, since
|
|
6
|
+
# Accounts have the reverse 'has_many' relationship to either it's credit or
|
|
7
|
+
# debit transactions
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# cash = Plutus::Asset.find_by_name('Cash')
|
|
11
|
+
# accounts_receivable = Plutus::Asset.find_by_name('Accounts Receivable')
|
|
12
|
+
#
|
|
13
|
+
# debit_amount = Plutus::DebitAmount.new(:account => cash, :amount => 1000)
|
|
14
|
+
# credit_amount = Plutus::CreditAmount.new(:account => accounts_receivable, :amount => 1000)
|
|
15
|
+
#
|
|
16
|
+
# transaction = Plutus::Transaction.new(:description => "Receiving payment on an invoice")
|
|
17
|
+
# transaction.debit_amounts << debit_amount
|
|
18
|
+
# transaction.credit_amounts << credit_amount
|
|
19
|
+
# transaction.save
|
|
20
|
+
#
|
|
21
|
+
# @see http://en.wikipedia.org/wiki/Journal_entry Journal Entry
|
|
22
|
+
#
|
|
23
|
+
# @author Michael Bulat
|
|
24
|
+
class Transaction < ActiveRecord::Base
|
|
25
|
+
attr_accessible :description, :commercial_document
|
|
26
|
+
|
|
27
|
+
belongs_to :commercial_document, :polymorphic => true
|
|
28
|
+
has_many :credit_amounts
|
|
29
|
+
has_many :debit_amounts
|
|
30
|
+
has_many :credit_accounts, :through => :credit_amounts, :source => :account
|
|
31
|
+
has_many :debit_accounts, :through => :debit_amounts, :source => :account
|
|
32
|
+
|
|
33
|
+
validates_presence_of :description
|
|
34
|
+
validate :has_credit_amounts?
|
|
35
|
+
validate :has_debit_amounts?
|
|
36
|
+
validate :amounts_cancel?
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Simple API for building a transaction and associated debit and credit amounts
|
|
40
|
+
#
|
|
41
|
+
# @example
|
|
42
|
+
# transaction = Plutus::Transaction.build(
|
|
43
|
+
# description: "Sold some widgets",
|
|
44
|
+
# debits: [
|
|
45
|
+
# {account: "Accounts Receivable", amount: 50}],
|
|
46
|
+
# credits: [
|
|
47
|
+
# {account: "Sales Revenue", amount: 45},
|
|
48
|
+
# {account: "Sales Tax Payable", amount: 5}])
|
|
49
|
+
#
|
|
50
|
+
# @return [Plutus::Transaction] A Transaction with built credit and debit objects ready for saving
|
|
51
|
+
def self.build(hash)
|
|
52
|
+
transaction = Transaction.new(:description => hash[:description], :commercial_document => hash[:commercial_document])
|
|
53
|
+
hash[:debits].each do |debit|
|
|
54
|
+
a = Account.find_by_name(debit[:account])
|
|
55
|
+
transaction.debit_amounts << DebitAmount.new(:account => a, :amount => debit[:amount], :transaction => transaction)
|
|
56
|
+
end
|
|
57
|
+
hash[:credits].each do |credit|
|
|
58
|
+
a = Account.find_by_name(credit[:account])
|
|
59
|
+
transaction.credit_amounts << CreditAmount.new(:account => a, :amount => credit[:amount], :transaction => transaction)
|
|
60
|
+
end
|
|
61
|
+
transaction
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
def has_credit_amounts?
|
|
66
|
+
errors[:base] << "Transaction must have at least one credit amount" if self.credit_amounts.blank?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def has_debit_amounts?
|
|
70
|
+
errors[:base] << "Transaction must have at least one debit amount" if self.debit_amounts.blank?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def amounts_cancel?
|
|
74
|
+
errors[:base] << "The credit and debit amounts are not equal" if difference_of_amounts != 0
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def difference_of_amounts
|
|
78
|
+
credit_amount_total = credit_amounts.inject(0) {|sum, credit_amount| sum + credit_amount.amount.to_i}
|
|
79
|
+
debit_amount_total = debit_amounts.inject(0) {|sum, debit_amount| sum + debit_amount.amount.to_i}
|
|
80
|
+
credit_amount_total - debit_amount_total
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<div class="plutus_container">
|
|
1
2
|
<h1>Listing Accounts</h1>
|
|
2
3
|
|
|
3
4
|
<table>
|
|
@@ -12,9 +13,9 @@
|
|
|
12
13
|
|
|
13
14
|
<% @accounts.each do |account| %>
|
|
14
15
|
<tr class="<%= cycle("even", "odd") -%>">
|
|
15
|
-
<td><%=
|
|
16
|
+
<td><%=link_to(account.id, account_path(account.id)) %></td>
|
|
16
17
|
<td><%=h account.name %></td>
|
|
17
|
-
<td><%=h account.type %></td>
|
|
18
|
+
<td><%=h account.type.sub('Plutus::','') %></td>
|
|
18
19
|
<td><%=h account.credits_balance %></td>
|
|
19
20
|
<td><%=h account.debits_balance %></td>
|
|
20
21
|
<td><%=h account.balance %></td>
|
|
@@ -25,3 +26,4 @@
|
|
|
25
26
|
<br />
|
|
26
27
|
|
|
27
28
|
<h3>Go to <%= link_to 'Transactions', transactions_path %></h3>
|
|
29
|
+
</div>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<div class="plutus_container">
|
|
1
2
|
<h1><%=h @account.name %> Account</h1>
|
|
2
3
|
|
|
3
4
|
<table>
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
<tr class="odd">
|
|
14
15
|
<td><%=h @account.id %></td>
|
|
15
16
|
<td><%=h @account.name %></td>
|
|
16
|
-
<td><%=h @account.type %></td>
|
|
17
|
+
<td><%=h @account.type.sub('Plutus::','') %></td>
|
|
17
18
|
<td><%=h @account.credits_balance %></td>
|
|
18
19
|
<td><%=h @account.debits_balance %></td>
|
|
19
20
|
<td><%=h @account.balance %></td>
|
|
@@ -26,9 +27,6 @@
|
|
|
26
27
|
<tr>
|
|
27
28
|
<th class="nobg">ID</th>
|
|
28
29
|
<th>Description</th>
|
|
29
|
-
<th>Credit Account</th>
|
|
30
|
-
<th>Debit Account</th>
|
|
31
|
-
<th>Amount</th>
|
|
32
30
|
<th>Date</th>
|
|
33
31
|
</tr>
|
|
34
32
|
|
|
@@ -36,9 +34,6 @@
|
|
|
36
34
|
<tr class="<%= cycle("even", "odd") -%>">
|
|
37
35
|
<td><%=h transaction.id %></td>
|
|
38
36
|
<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
37
|
<td><%=h transaction.created_at %></td>
|
|
43
38
|
</tr>
|
|
44
39
|
<% end %>
|
|
@@ -50,20 +45,15 @@
|
|
|
50
45
|
<tr>
|
|
51
46
|
<th class="nobg">ID</th>
|
|
52
47
|
<th>Description</th>
|
|
53
|
-
<th>Credit Account</th>
|
|
54
|
-
<th>Debit Account</th>
|
|
55
|
-
<th>Amount</th>
|
|
56
48
|
<th>Date</th>
|
|
57
49
|
</tr>
|
|
58
50
|
|
|
59
|
-
<% @account.debit_transactions.each do |
|
|
51
|
+
<% @account.debit_transactions.each do |tr| %>
|
|
60
52
|
<tr class="<%= cycle("even", "odd") -%>">
|
|
61
|
-
<td><%=h
|
|
62
|
-
<td><%=h
|
|
63
|
-
<td><%=h
|
|
64
|
-
<td><%=h transaction.debit_account.name %></td>
|
|
65
|
-
<td><%=h transaction.amount %></td>
|
|
66
|
-
<td><%=h transaction.created_at %></td>
|
|
53
|
+
<td><%=h tr.id %></td>
|
|
54
|
+
<td><%=h tr.description %></td>
|
|
55
|
+
<td><%=h tr.created_at %></td>
|
|
67
56
|
</tr>
|
|
68
57
|
<% end %>
|
|
69
|
-
</table>
|
|
58
|
+
</table>
|
|
59
|
+
</div>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<div class="plutus_container">
|
|
2
|
+
<h1>Transactions</h1>
|
|
3
|
+
|
|
4
|
+
<table cellspacing="0">
|
|
5
|
+
<thead>
|
|
6
|
+
<tr>
|
|
7
|
+
<th class="nobg">ID</th>
|
|
8
|
+
<th>Description</th>
|
|
9
|
+
<th>Debits</th>
|
|
10
|
+
<th>Credits</th>
|
|
11
|
+
<th>Date</th>
|
|
12
|
+
</tr>
|
|
13
|
+
</thead>
|
|
14
|
+
<tbody>
|
|
15
|
+
<% @transactions.each do |transaction| %>
|
|
16
|
+
<tr class="<%= cycle("even", "odd") -%>">
|
|
17
|
+
<td><%=link_to(transaction.id, transaction_path(transaction)) %></td>
|
|
18
|
+
<td><%=h transaction.description %></td>
|
|
19
|
+
<td></td>
|
|
20
|
+
<td></td>
|
|
21
|
+
<td><%=h transaction.created_at %></td>
|
|
22
|
+
</tr>
|
|
23
|
+
<% transaction.debit_amounts.each do |debit_amount| %>
|
|
24
|
+
<tr class="<%= cycle("odd", "odd") -%>">
|
|
25
|
+
<td></td>
|
|
26
|
+
<td> <%=h "#{debit_amount.account.name}" %></td>
|
|
27
|
+
<td><%=h debit_amount.amount %></td>
|
|
28
|
+
<td></td>
|
|
29
|
+
<td></td>
|
|
30
|
+
</tr>
|
|
31
|
+
<% end %>
|
|
32
|
+
<% transaction.credit_amounts.each do |credit_amount| %>
|
|
33
|
+
<tr class="<%= cycle("odd", "odd") -%>">
|
|
34
|
+
<td></td>
|
|
35
|
+
<td> <%=h "#{credit_amount.account.name}" %></td>
|
|
36
|
+
<td></td>
|
|
37
|
+
<td><%=h credit_amount.amount %></td>
|
|
38
|
+
<td></td>
|
|
39
|
+
</tr>
|
|
40
|
+
<% end %>
|
|
41
|
+
<% end %>
|
|
42
|
+
</tbody>
|
|
43
|
+
</table>
|
|
44
|
+
|
|
45
|
+
<br />
|
|
46
|
+
|
|
47
|
+
<h3>Go to <%= link_to 'Accounts', accounts_path %></h3>
|
|
48
|
+
</div>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<div class="plutus_container">
|
|
2
|
+
<h1><%=h @transaction.description %> Transaction</h1>
|
|
3
|
+
|
|
4
|
+
<table cellspacing="0">
|
|
5
|
+
<thead>
|
|
6
|
+
<tr>
|
|
7
|
+
<th class="nobg">ID</th>
|
|
8
|
+
<th>Description</th>
|
|
9
|
+
<th>Debits</th>
|
|
10
|
+
<th>Credits</th>
|
|
11
|
+
<th>Date</th>
|
|
12
|
+
</tr>
|
|
13
|
+
</thead>
|
|
14
|
+
<tbody>
|
|
15
|
+
<tr class="<%= cycle("even", "odd") -%>">
|
|
16
|
+
<td><%=link_to(@transaction.id, transaction_path(@transaction)) %></td>
|
|
17
|
+
<td><%=h @transaction.description %></td>
|
|
18
|
+
<td></td>
|
|
19
|
+
<td></td>
|
|
20
|
+
<td><%=h @transaction.created_at %></td>
|
|
21
|
+
</tr>
|
|
22
|
+
<% @transaction.debit_amounts.each do |debit_amount| %>
|
|
23
|
+
<tr class="<%= cycle("odd", "odd") -%>">
|
|
24
|
+
<td></td>
|
|
25
|
+
<td> <%=h "#{debit_amount.account.name}" %></td>
|
|
26
|
+
<td><%=h debit_amount.amount %></td>
|
|
27
|
+
<td></td>
|
|
28
|
+
<td></td>
|
|
29
|
+
</tr>
|
|
30
|
+
<% end %>
|
|
31
|
+
<% @transaction.credit_amounts.each do |credit_amount| %>
|
|
32
|
+
<tr class="<%= cycle("odd", "odd") -%>">
|
|
33
|
+
<td></td>
|
|
34
|
+
<td> <%=h "#{credit_amount.account.name}" %></td>
|
|
35
|
+
<td></td>
|
|
36
|
+
<td><%=h credit_amount.amount %></td>
|
|
37
|
+
<td></td>
|
|
38
|
+
</tr>
|
|
39
|
+
<% end %>
|
|
40
|
+
</tbody>
|
|
41
|
+
</table>
|
|
42
|
+
|
|
43
|
+
<br />
|
|
44
|
+
|
|
45
|
+
<h3>Go to <%= link_to 'Accounts', accounts_path %></h3>
|
|
46
|
+
</div>
|
data/config/database.yml
ADDED
data/config/routes.rb
ADDED
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
class CreatePlutusTables < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
|
3
|
-
create_table :
|
|
3
|
+
create_table :plutus_accounts do |t|
|
|
4
4
|
t.string :name
|
|
5
5
|
t.string :type
|
|
6
6
|
t.boolean :contra
|
|
7
7
|
|
|
8
8
|
t.timestamps
|
|
9
9
|
end
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
create_table :transactions do |t|
|
|
10
|
+
add_index :plutus_accounts, [:name, :type]
|
|
11
|
+
|
|
12
|
+
create_table :plutus_transactions do |t|
|
|
14
13
|
t.string :description
|
|
15
|
-
t.integer :credit_account_id
|
|
16
|
-
t.integer :debit_account_id
|
|
17
|
-
t.decimal :amount, :precision => 20, :scale => 10
|
|
18
14
|
t.integer :commercial_document_id
|
|
19
15
|
t.string :commercial_document_type
|
|
20
16
|
|
|
21
17
|
t.timestamps
|
|
22
18
|
end
|
|
19
|
+
add_index :plutus_transactions, [:commercial_document_id, :commercial_document_type], :name => "index_transactions_on_commercial_doc"
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
create_table :plutus_amounts do |t|
|
|
22
|
+
t.string :type
|
|
23
|
+
t.references :account
|
|
24
|
+
t.references :transaction
|
|
25
|
+
t.decimal :amount, :precision => 20, :scale => 10
|
|
26
|
+
end
|
|
27
|
+
add_index :plutus_amounts, :type
|
|
28
|
+
add_index :plutus_amounts, [:account_id, :transaction_id]
|
|
29
|
+
add_index :plutus_amounts, [:transaction_id, :account_id]
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
def self.down
|
|
30
|
-
drop_table :
|
|
31
|
-
drop_table :
|
|
33
|
+
drop_table :plutus_accounts
|
|
34
|
+
drop_table :plutus_transactions
|
|
35
|
+
drop_table :plutus_amounts
|
|
32
36
|
end
|
|
33
37
|
end
|
data/lib/plutus.rb
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module Plutus
|
|
4
|
+
describe AccountsController do
|
|
5
|
+
# Run these tests if you enable routing in your rails app. See README
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
describe "GET index" do
|
|
10
|
-
it "assigns all accounts as @accounts" do
|
|
11
|
-
Account.stub(:find).with(:all).and_return([mock_account])
|
|
12
|
-
get :index
|
|
13
|
-
assigns[:accounts].should == [mock_account]
|
|
14
|
-
end
|
|
15
|
-
end
|
|
7
|
+
#def mock_account(stubs={})
|
|
8
|
+
#@mock_account ||= mock_model(Account, stubs)
|
|
9
|
+
#end
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
#describe "GET index" do
|
|
12
|
+
#it "assigns all accounts as @accounts" do
|
|
13
|
+
#Account.stub(:find).with(:all).and_return([mock_account])
|
|
14
|
+
#get :index
|
|
15
|
+
#assigns[:accounts].should == [mock_account]
|
|
16
|
+
#end
|
|
17
|
+
#end
|
|
24
18
|
|
|
19
|
+
#describe "GET show" do
|
|
20
|
+
#it "assigns the requested account as @account" do
|
|
21
|
+
#Account.stub(:find).with("37").and_return(mock_account)
|
|
22
|
+
#get :show, :id => "37"
|
|
23
|
+
#assigns[:account].should equal(mock_account)
|
|
24
|
+
#end
|
|
25
|
+
#end
|
|
26
|
+
|
|
27
|
+
end
|
|
25
28
|
end
|