plutus 0.10.1 → 0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +5 -5
  2. data/README.markdown +172 -99
  3. data/app/assets/javascripts/plutus/application.js +5 -4
  4. data/app/assets/javascripts/plutus/reports.js +5 -0
  5. data/app/assets/stylesheets/bootstrap-theme.min.css +5 -0
  6. data/app/assets/stylesheets/bootstrap.min.css +5 -0
  7. data/app/assets/stylesheets/plutus/application.css +11 -5
  8. data/app/controllers/plutus/accounts_controller.rb +1 -16
  9. data/app/controllers/plutus/application_controller.rb +4 -0
  10. data/app/controllers/plutus/entries_controller.rb +7 -17
  11. data/app/controllers/plutus/reports_controller.rb +40 -0
  12. data/app/models/plutus/account.rb +92 -7
  13. data/app/models/plutus/amount.rb +11 -1
  14. data/app/models/plutus/amounts_extension.rb +31 -6
  15. data/app/models/plutus/asset.rb +21 -18
  16. data/app/models/plutus/entry.rb +28 -26
  17. data/app/models/plutus/equity.rb +22 -19
  18. data/app/models/plutus/expense.rb +21 -18
  19. data/app/models/plutus/liability.rb +27 -19
  20. data/app/models/plutus/revenue.rb +22 -19
  21. data/app/models/plutus/tenancy.rb +5 -1
  22. data/app/views/layouts/plutus/_messages.html.erb +9 -0
  23. data/app/views/layouts/plutus/_navigation.html.erb +19 -0
  24. data/app/views/layouts/plutus/_navigation_links.html.erb +5 -0
  25. data/app/views/layouts/plutus/application.html.erb +19 -0
  26. data/app/views/plutus/accounts/index.html.erb +9 -12
  27. data/app/views/plutus/entries/index.html.erb +22 -11
  28. data/app/views/plutus/reports/_account.html.erb +28 -0
  29. data/app/views/plutus/reports/balance_sheet.html.erb +21 -0
  30. data/app/views/plutus/reports/income_statement.html.erb +24 -0
  31. data/config/routes.rb +6 -3
  32. data/{lib/generators/plutus/templates/migration.rb → db/migrate/20160422010135_create_plutus_tables.rb} +6 -10
  33. data/lib/generators/plutus/add_date_upgrade_generator.rb +11 -0
  34. data/lib/generators/plutus/base_generator.rb +19 -0
  35. data/lib/generators/plutus/plutus_generator.rb +8 -22
  36. data/lib/generators/plutus/templates/add_date_migration.rb +12 -0
  37. data/lib/generators/plutus/templates/tenant_migration.rb +1 -1
  38. data/lib/generators/plutus/templates/update_migration.rb +2 -2
  39. data/lib/generators/plutus/tenancy_generator.rb +2 -17
  40. data/lib/generators/plutus/upgrade_plutus_generator.rb +6 -22
  41. data/lib/plutus.rb +2 -5
  42. data/lib/plutus/engine.rb +5 -0
  43. data/lib/plutus/version.rb +1 -1
  44. data/spec/controllers/accounts_controller_spec.rb +11 -20
  45. data/spec/controllers/entries_controller_spec.rb +11 -20
  46. data/spec/controllers/reports_controller_spec.rb +24 -0
  47. data/spec/factories/tenant_factory.rb +12 -0
  48. data/spec/models/account_spec.rb +79 -16
  49. data/spec/models/amount_spec.rb +6 -1
  50. data/spec/models/debit_amount_spec.rb +1 -1
  51. data/spec/models/entry_spec.rb +108 -29
  52. data/spec/models/tenancy_spec.rb +26 -8
  53. data/spec/routing/accounts_routing_spec.rb +6 -25
  54. data/spec/routing/entries_routing_spec.rb +6 -25
  55. data/spec/spec_helper.rb +5 -0
  56. data/spec/support/account_shared_examples.rb +14 -10
  57. data/spec/support/amount_shared_examples.rb +7 -7
  58. data/spec/support/shoulda_matchers.rb +8 -0
  59. metadata +100 -27
  60. data/app/views/plutus/accounts/show.html.erb +0 -59
  61. data/app/views/plutus/entries/show.html.erb +0 -46
  62. data/spec/schema.rb +0 -31
@@ -7,24 +7,29 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Equity_(finance) Equity
8
8
  #
9
9
  # @author Michael Bulat
10
- class Equity < Account
10
+ class Equity < Plutus::Account
11
+
12
+ self.normal_credit_balance = true
11
13
 
12
14
  # The balance of the account.
13
15
  #
14
16
  # Equity accounts have normal credit balances, so the debits are subtracted from the credits
15
17
  # unless this is a contra account, in which credits are subtracted from debits
16
18
  #
19
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
20
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
21
+ #
22
+ # @example
23
+ # >> equity.balance({:from_date => "2000-01-01", :to_date => Date.today})
24
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
25
+ #
17
26
  # @example
18
- # >> asset.balance
27
+ # >> equity.balance
19
28
  # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
20
29
  #
21
30
  # @return [BigDecimal] The decimal value balance
22
- def balance
23
- unless contra
24
- credits_balance - debits_balance
25
- else
26
- debits_balance - credits_balance
27
- end
31
+ def balance(options={})
32
+ super
28
33
  end
29
34
 
30
35
  # This class method is used to return
@@ -32,22 +37,20 @@ module Plutus
32
37
  #
33
38
  # Contra accounts are automatically subtracted from the balance.
34
39
  #
40
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
41
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
42
+ #
43
+ # @example
44
+ # >> Plutus::Equity.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
46
+ #
35
47
  # @example
36
48
  # >> Plutus::Equity.balance
37
49
  # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
38
50
  #
39
51
  # @return [BigDecimal] The decimal value balance
40
- def self.balance
41
- accounts_balance = BigDecimal.new('0')
42
- accounts = self.all
43
- accounts.each do |equity|
44
- unless equity.contra
45
- accounts_balance += equity.balance
46
- else
47
- accounts_balance -= equity.balance
48
- end
49
- end
50
- accounts_balance
52
+ def self.balance(options={})
53
+ super
51
54
  end
52
55
  end
53
56
  end
@@ -7,24 +7,29 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Expense Expenses
8
8
  #
9
9
  # @author Michael Bulat
10
- class Expense < Account
10
+ class Expense < Plutus::Account
11
+
12
+ self.normal_credit_balance = false
11
13
 
12
14
  # The balance of the account.
13
15
  #
14
16
  # Expenses have normal debit balances, so the credits are subtracted from the debits
15
17
  # unless this is a contra account, in which debits are subtracted from credits
16
18
  #
19
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
20
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
21
+ #
22
+ # @example
23
+ # >> expense.balance({:from_date => "2000-01-01", :to_date => Date.today})
24
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
25
+ #
17
26
  # @example
18
27
  # >> expense.balance
19
28
  # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
20
29
  #
21
30
  # @return [BigDecimal] The decimal value balance
22
- def balance
23
- unless contra
24
- debits_balance - credits_balance
25
- else
26
- credits_balance - debits_balance
27
- end
31
+ def balance(options={})
32
+ super
28
33
  end
29
34
 
30
35
  # This class method is used to return
@@ -32,22 +37,20 @@ module Plutus
32
37
  #
33
38
  # Contra accounts are automatically subtracted from the balance.
34
39
  #
40
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
41
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
42
+ #
43
+ # @example
44
+ # >> Plutus::Expense.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
46
+ #
35
47
  # @example
36
48
  # >> Plutus::Expense.balance
37
49
  # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
38
50
  #
39
51
  # @return [BigDecimal] The decimal value balance
40
- def self.balance
41
- accounts_balance = BigDecimal.new('0')
42
- accounts = self.all
43
- accounts.each do |expense|
44
- unless expense.contra
45
- accounts_balance += expense.balance
46
- else
47
- accounts_balance -= expense.balance
48
- end
49
- end
50
- accounts_balance
52
+ def self.balance(options={})
53
+ super
51
54
  end
52
55
  end
53
56
  end
@@ -7,42 +7,50 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Liability_(financial_accounting) Liability
8
8
  #
9
9
  # @author Michael Bulat
10
- class Liability < Account
10
+ class Liability < Plutus::Account
11
+
12
+ self.normal_credit_balance = true
11
13
 
12
14
  # The balance of the account.
13
15
  #
14
16
  # Liability accounts have normal credit balances, so the debits are subtracted from the credits
15
17
  # unless this is a contra account, in which credits are subtracted from debits
16
18
  #
19
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
20
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
21
+ #
22
+ # @example
23
+ # >> liability.balance({:from_date => "2000-01-01", :to_date => Date.today})
24
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
25
+ #
17
26
  # @example
18
27
  # >> liability.balance
19
28
  # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
20
29
  #
21
30
  # @return [BigDecimal] The decimal value balance
22
- def balance
23
- unless contra
24
- credits_balance - debits_balance
25
- else
26
- debits_balance - credits_balance
27
- end
31
+ def balance(options={})
32
+ super
28
33
  end
29
34
 
30
- # Balance of all Liability accounts
35
+ # This class method is used to return
36
+ # the balance of all Liability accounts.
37
+ #
38
+ # Contra accounts are automatically subtracted from the balance.
39
+ #
40
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
41
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
42
+ #
43
+ # @example
44
+ # >> Plutus::Liability.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
31
46
  #
32
47
  # @example
33
48
  # >> Plutus::Liability.balance
34
49
  # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
35
- def self.balance
36
- accounts_balance = BigDecimal.new('0')
37
- accounts = self.all
38
- accounts.each do |liability|
39
- unless liability.contra
40
- accounts_balance += liability.balance
41
- else
42
- accounts_balance -= liability.balance
43
- end
44
- end
45
- accounts_balance
50
+ #
51
+ # @return [BigDecimal] The decimal value balance
52
+ def self.balance(options={})
53
+ super
46
54
  end
47
55
  end
48
56
  end
@@ -7,24 +7,29 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Revenue Revenue
8
8
  #
9
9
  # @author Michael Bulat
10
- class Revenue < Account
10
+ class Revenue < Plutus::Account
11
+
12
+ self.normal_credit_balance = true
11
13
 
12
14
  # The balance of the account.
13
15
  #
14
16
  # Revenue accounts have normal credit balances, so the debits are subtracted from the credits
15
17
  # unless this is a contra account, in which credits are subtracted from debits
16
18
  #
19
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
20
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
21
+ #
22
+ # @example
23
+ # >> revenue.balance({:from_date => "2000-01-01", :to_date => Date.today})
24
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
25
+ #
17
26
  # @example
18
- # >> asset.balance
27
+ # >> revenue.balance
19
28
  # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
20
29
  #
21
30
  # @return [BigDecimal] The decimal value balance
22
- def balance
23
- unless contra
24
- credits_balance - debits_balance
25
- else
26
- debits_balance - credits_balance
27
- end
31
+ def balance(options={})
32
+ super
28
33
  end
29
34
 
30
35
  # This class method is used to return
@@ -32,22 +37,20 @@ module Plutus
32
37
  #
33
38
  # Contra accounts are automatically subtracted from the balance.
34
39
  #
40
+ # Takes an optional hash specifying :from_date and :to_date for calculating balances during periods.
41
+ # :from_date and :to_date may be strings of the form "yyyy-mm-dd" or Ruby Date objects
42
+ #
43
+ # @example
44
+ # >> Plutus::Revenue.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
46
+ #
35
47
  # @example
36
48
  # >> Plutus::Revenue.balance
37
49
  # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
38
50
  #
39
51
  # @return [BigDecimal] The decimal value balance
40
- def self.balance
41
- accounts_balance = BigDecimal.new('0')
42
- accounts = self.all
43
- accounts.each do |revenue|
44
- unless revenue.contra
45
- accounts_balance += revenue.balance
46
- else
47
- accounts_balance -= revenue.balance
48
- end
49
- end
50
- accounts_balance
52
+ def self.balance(options={})
53
+ super
51
54
  end
52
55
  end
53
56
  end
@@ -5,7 +5,11 @@ module Plutus
5
5
  included do
6
6
  validates :name, presence: true, uniqueness: { scope: :tenant_id }
7
7
 
8
- belongs_to :tenant, class_name: Plutus.tenant_class
8
+ if ActiveRecord::VERSION::MAJOR > 4
9
+ belongs_to :tenant, class_name: Plutus.tenant_class, optional: true
10
+ else
11
+ belongs_to :tenant, class_name: Plutus.tenant_class
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -0,0 +1,9 @@
1
+ <%# Rails flash messages styled for Bootstrap 3.0 %>
2
+ <% flash.each do |name, msg| %>
3
+ <% if msg.is_a?(String) %>
4
+ <div class="alert alert-<%= name.to_s == 'notice' ? 'success' : 'danger' %>">
5
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
6
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
7
+ </div>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <%# navigation styled for Bootstrap 3.0 %>
2
+ <nav class="navbar navbar-default navbar-fixed-top">
3
+ <div class="container">
4
+ <div class="navbar-header">
5
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
6
+ <span class="sr-only">Toggle navigation</span>
7
+ <span class="icon-bar"></span>
8
+ <span class="icon-bar"></span>
9
+ <span class="icon-bar"></span>
10
+ </button>
11
+ <a class="navbar-brand" href="/">&nbsp;Plutus</a>
12
+ </div>
13
+ <div class="collapse navbar-collapse">
14
+ <ul class="nav navbar-nav">
15
+ <%= render 'layouts/plutus/navigation_links' %>
16
+ </ul>
17
+ </div>
18
+ </div>
19
+ </nav>
@@ -0,0 +1,5 @@
1
+ <%# add navigation links to this file %>
2
+ <li><%= link_to "Balance Sheet", reports_balance_sheet_path%></li>
3
+ <li><%= link_to "Income Statement", reports_income_statement_path%></li>
4
+ <li><%= link_to "General Ledger", accounts_path%></li>
5
+ <li><%= link_to "Journal", entries_path%></li>
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
+ <title>Plutus</title>
6
+ <%= stylesheet_link_tag "plutus/application", media: "all" %>
7
+ <%= javascript_include_tag "plutus/application" %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+ <header>
12
+ <%= render 'layouts/plutus/navigation' %>
13
+ </header>
14
+ <main role="main">
15
+ <%= render 'layouts/plutus/messages' %>
16
+ <%= yield %>
17
+ </main>
18
+ </body>
19
+ </html>
@@ -1,9 +1,11 @@
1
- <div class="plutus_container">
2
- <h1>Listing Accounts</h1>
1
+ <div class="container">
2
+ <center>
3
+ <h1>General Ledger</h1>
4
+ <br>
5
+ </center>
3
6
 
4
- <table>
7
+ <table class="table table-striped table-hover">
5
8
  <tr>
6
- <th class="nobg">ID</th>
7
9
  <th>Name</th>
8
10
  <th>Type</th>
9
11
  <th>Credit Balance</th>
@@ -13,17 +15,12 @@
13
15
 
14
16
  <% @accounts.each do |account| %>
15
17
  <tr class="<%= cycle("even", "odd") -%>">
16
- <td><%=link_to(account.id, account_path(account.id)) %></td>
17
18
  <td><%=h account.name %></td>
18
19
  <td><%=h account.type.sub('Plutus::','') %></td>
19
- <td><%=h account.credits_balance %></td>
20
- <td><%=h account.debits_balance %></td>
21
- <td><%=h account.balance %></td>
20
+ <td><%=h account.credits_balance.round(2) %></td>
21
+ <td><%=h account.debits_balance.round(2) %></td>
22
+ <td><%=h account.balance.round(2) %></td>
22
23
  </tr>
23
24
  <% end %>
24
25
  </table>
25
-
26
- <br />
27
-
28
- <h3>Go to <%= link_to 'Entries', entries_path %></h3>
29
26
  </div>
@@ -1,10 +1,19 @@
1
- <div class="plutus_container">
2
- <h1>Entries</h1>
1
+ <div class="container">
2
+ <center>
3
+ <h1>Journal</h1>
4
+ <br>
5
+ <%= form_tag({:action => 'index'}, {:method => :get, :class => 'form-inline'}) do%>
6
+ <div class="form-group">
7
+ Per page: <%= select_tag :limit, options_for_select([25, 100, 200, 300], selected: params[:limit]), class: 'form-control' %>
8
+ Order: <%= select_tag :order, options_for_select(['descending', 'ascending'], selected: params[:order]), class: 'form-control' %>
9
+ </div>
10
+ <button type="submit" class="btn btn-default">Refresh</button>
11
+ <% end %>
12
+ </center>
3
13
 
4
- <table cellspacing="0">
14
+ <table class="table table-striped table-hover">
5
15
  <thead>
6
16
  <tr>
7
- <th class="nobg">ID</th>
8
17
  <th>Description</th>
9
18
  <th>Debits</th>
10
19
  <th>Credits</th>
@@ -14,7 +23,6 @@
14
23
  <tbody>
15
24
  <% @entries.each do |entry| %>
16
25
  <tr class="<%= cycle("even", "odd") -%>">
17
- <td><%=link_to(entry.id, entry_path(entry)) %></td>
18
26
  <td><%=h entry.description %></td>
19
27
  <td></td>
20
28
  <td></td>
@@ -22,27 +30,30 @@
22
30
  </tr>
23
31
  <% entry.debit_amounts.each do |debit_amount| %>
24
32
  <tr class="<%= cycle("odd", "odd") -%>">
25
- <td></td>
26
33
  <td>&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{debit_amount.account.name}" %></td>
27
- <td><%=h debit_amount.amount %></td>
34
+ <td><%=h debit_amount.amount.round(2) %></td>
28
35
  <td></td>
29
36
  <td></td>
30
37
  </tr>
31
38
  <% end %>
32
39
  <% entry.credit_amounts.each do |credit_amount| %>
33
40
  <tr class="<%= cycle("odd", "odd") -%>">
34
- <td></td>
35
41
  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{credit_amount.account.name}" %></td>
36
42
  <td></td>
37
- <td><%=h credit_amount.amount %></td>
43
+ <td><%=h credit_amount.amount.round(2) %></td>
38
44
  <td></td>
39
45
  </tr>
40
46
  <% end %>
47
+ <tr class="<%= cycle("odd", "odd") -%>">
48
+ <td></td>
49
+ <td></td>
50
+ <td></td>
51
+ <td></td>
52
+ </tr>
41
53
  <% end %>
42
54
  </tbody>
43
55
  </table>
44
56
 
45
- <br />
57
+ <%= paginate @entries %>
46
58
 
47
- <h3>Go to <%= link_to 'Accounts', accounts_path %></h3>
48
59
  </div>