borutus 0.1.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.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +346 -0
  4. data/Rakefile +11 -0
  5. data/app/assets/javascripts/borutus/application.js +16 -0
  6. data/app/assets/javascripts/borutus/reports.js +5 -0
  7. data/app/assets/stylesheets/bootstrap-theme.min.css +5 -0
  8. data/app/assets/stylesheets/bootstrap.min.css +5 -0
  9. data/app/assets/stylesheets/borutus/application.css +19 -0
  10. data/app/controllers/borutus/accounts_controller.rb +30 -0
  11. data/app/controllers/borutus/application_controller.rb +4 -0
  12. data/app/controllers/borutus/entries_controller.rb +34 -0
  13. data/app/controllers/borutus/reports_controller.rb +40 -0
  14. data/app/models/borutus/account.rb +180 -0
  15. data/app/models/borutus/amount.rb +24 -0
  16. data/app/models/borutus/amounts_extension.rb +42 -0
  17. data/app/models/borutus/asset.rb +56 -0
  18. data/app/models/borutus/credit_amount.rb +10 -0
  19. data/app/models/borutus/debit_amount.rb +10 -0
  20. data/app/models/borutus/entry.rb +77 -0
  21. data/app/models/borutus/equity.rb +56 -0
  22. data/app/models/borutus/expense.rb +56 -0
  23. data/app/models/borutus/liability.rb +56 -0
  24. data/app/models/borutus/no_tenancy.rb +9 -0
  25. data/app/models/borutus/revenue.rb +56 -0
  26. data/app/models/borutus/tenancy.rb +15 -0
  27. data/app/views/borutus/accounts/index.html.erb +26 -0
  28. data/app/views/borutus/entries/index.html.erb +59 -0
  29. data/app/views/borutus/reports/_account.html.erb +28 -0
  30. data/app/views/borutus/reports/balance_sheet.html.erb +21 -0
  31. data/app/views/borutus/reports/income_statement.html.erb +24 -0
  32. data/app/views/layouts/borutus/_messages.html.erb +9 -0
  33. data/app/views/layouts/borutus/_navigation.html.erb +19 -0
  34. data/app/views/layouts/borutus/_navigation_links.html.erb +5 -0
  35. data/app/views/layouts/borutus/application.html.erb +19 -0
  36. data/config/backtrace_silencers.rb +7 -0
  37. data/config/database.yml +5 -0
  38. data/config/inflections.rb +10 -0
  39. data/config/mime_types.rb +5 -0
  40. data/config/routes.rb +9 -0
  41. data/config/secret_token.rb +7 -0
  42. data/config/session_store.rb +8 -0
  43. data/db/migrate/20160422010135_create_borutus_tables.rb +33 -0
  44. data/lib/borutus.rb +20 -0
  45. data/lib/borutus/engine.rb +5 -0
  46. data/lib/borutus/version.rb +3 -0
  47. data/lib/generators/borutus/USAGE +13 -0
  48. data/lib/generators/borutus/add_date_upgrade_generator.rb +11 -0
  49. data/lib/generators/borutus/base_generator.rb +19 -0
  50. data/lib/generators/borutus/borutus_generator.rb +12 -0
  51. data/lib/generators/borutus/templates/tenant_migration.rb +6 -0
  52. data/lib/generators/borutus/tenancy_generator.rb +12 -0
  53. data/lib/generators/borutus/upgrade_borutus_generator.rb +12 -0
  54. data/spec/controllers/accounts_controller_spec.rb +19 -0
  55. data/spec/controllers/entries_controller_spec.rb +19 -0
  56. data/spec/controllers/reports_controller_spec.rb +24 -0
  57. data/spec/factories/account_factory.rb +35 -0
  58. data/spec/factories/amount_factory.rb +19 -0
  59. data/spec/factories/entry_factory.rb +11 -0
  60. data/spec/lib/borutus_spec.rb +0 -0
  61. data/spec/models/account_spec.rb +140 -0
  62. data/spec/models/amount_spec.rb +13 -0
  63. data/spec/models/asset_spec.rb +7 -0
  64. data/spec/models/credit_amount_spec.rb +7 -0
  65. data/spec/models/debit_amount_spec.rb +7 -0
  66. data/spec/models/entry_spec.rb +170 -0
  67. data/spec/models/equity_spec.rb +7 -0
  68. data/spec/models/expense_spec.rb +7 -0
  69. data/spec/models/liability_spec.rb +7 -0
  70. data/spec/models/revenue_spec.rb +7 -0
  71. data/spec/models/tenancy_spec.rb +45 -0
  72. data/spec/rcov.opts +2 -0
  73. data/spec/routing/accounts_routing_spec.rb +13 -0
  74. data/spec/routing/entries_routing_spec.rb +13 -0
  75. data/spec/spec.opts +4 -0
  76. data/spec/spec_helper.rb +26 -0
  77. data/spec/support/account_shared_examples.rb +60 -0
  78. data/spec/support/active_support_helpers.rb +13 -0
  79. data/spec/support/amount_shared_examples.rb +21 -0
  80. data/spec/support/factory_girl_helpers.rb +8 -0
  81. data/spec/support/shoulda_matchers.rb +8 -0
  82. metadata +243 -0
@@ -0,0 +1,56 @@
1
+ module Borutus
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 < ::Borutus::Account
11
+
12
+ self.normal_credit_balance = true
13
+
14
+ # The balance of the account.
15
+ #
16
+ # Equity accounts have normal credit balances, so the debits are subtracted from the credits
17
+ # unless this is a contra account, in which credits are subtracted from debits
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
+ #
26
+ # @example
27
+ # >> equity.balance
28
+ # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
29
+ #
30
+ # @return [BigDecimal] The decimal value balance
31
+ def balance(options={})
32
+ super
33
+ end
34
+
35
+ # This class method is used to return
36
+ # the balance of all Equity 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
+ # >> Borutus::Equity.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
46
+ #
47
+ # @example
48
+ # >> Borutus::Equity.balance
49
+ # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
50
+ #
51
+ # @return [BigDecimal] The decimal value balance
52
+ def self.balance(options={})
53
+ super
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,56 @@
1
+ module Borutus
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 < ::Borutus::Account
11
+
12
+ self.normal_credit_balance = false
13
+
14
+ # The balance of the account.
15
+ #
16
+ # Expenses have normal debit balances, so the credits are subtracted from the debits
17
+ # unless this is a contra account, in which debits are subtracted from credits
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
+ #
26
+ # @example
27
+ # >> expense.balance
28
+ # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
29
+ #
30
+ # @return [BigDecimal] The decimal value balance
31
+ def balance(options={})
32
+ super
33
+ end
34
+
35
+ # This class method is used to return
36
+ # the balance of all Expense 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
+ # >> Borutus::Expense.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
46
+ #
47
+ # @example
48
+ # >> Borutus::Expense.balance
49
+ # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
50
+ #
51
+ # @return [BigDecimal] The decimal value balance
52
+ def self.balance(options={})
53
+ super
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,56 @@
1
+ module Borutus
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 < ::Borutus::Account
11
+
12
+ self.normal_credit_balance = true
13
+
14
+ # The balance of the account.
15
+ #
16
+ # Liability accounts have normal credit balances, so the debits are subtracted from the credits
17
+ # unless this is a contra account, in which credits are subtracted from debits
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
+ #
26
+ # @example
27
+ # >> liability.balance
28
+ # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
29
+ #
30
+ # @return [BigDecimal] The decimal value balance
31
+ def balance(options={})
32
+ super
33
+ end
34
+
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
+ # >> Borutus::Liability.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
46
+ #
47
+ # @example
48
+ # >> Borutus::Liability.balance
49
+ # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
50
+ #
51
+ # @return [BigDecimal] The decimal value balance
52
+ def self.balance(options={})
53
+ super
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ module Borutus
2
+ module NoTenancy
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ validates :name, presence: true, uniqueness: true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,56 @@
1
+ module Borutus
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 < ::Borutus::Account
11
+
12
+ self.normal_credit_balance = true
13
+
14
+ # The balance of the account.
15
+ #
16
+ # Revenue accounts have normal credit balances, so the debits are subtracted from the credits
17
+ # unless this is a contra account, in which credits are subtracted from debits
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
+ #
26
+ # @example
27
+ # >> revenue.balance
28
+ # => #<BigDecimal:103259bb8,'0.2E4',4(12)>
29
+ #
30
+ # @return [BigDecimal] The decimal value balance
31
+ def balance(options={})
32
+ super
33
+ end
34
+
35
+ # This class method is used to return
36
+ # the balance of all Revenue 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
+ # >> Borutus::Revenue.balance({:from_date => "2000-01-01", :to_date => Date.today})
45
+ # => #<BigDecimal:103259bb8,'0.1E4',4(12)>
46
+ #
47
+ # @example
48
+ # >> Borutus::Revenue.balance
49
+ # => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
50
+ #
51
+ # @return [BigDecimal] The decimal value balance
52
+ def self.balance(options={})
53
+ super
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ module Borutus
2
+ module Tenancy
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ validates :name, presence: true, uniqueness: { scope: :tenant_id }
7
+
8
+ if ActiveRecord::VERSION::MAJOR > 4
9
+ belongs_to :tenant, class_name: Borutus.tenant_class, optional: true
10
+ else
11
+ belongs_to :tenant, class_name: Borutus.tenant_class
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ <div class="container">
2
+ <center>
3
+ <h1>General Ledger</h1>
4
+ <br>
5
+ </center>
6
+
7
+ <table class="table table-striped table-hover">
8
+ <tr>
9
+ <th>Name</th>
10
+ <th>Type</th>
11
+ <th>Credit Balance</th>
12
+ <th>Debit Balance</th>
13
+ <th>Balance</td>
14
+ </tr>
15
+
16
+ <% @accounts.each do |account| %>
17
+ <tr class="<%= cycle("even", "odd") -%>">
18
+ <td><%=h account.name %></td>
19
+ <td><%=h account.type.sub('Borutus::','') %></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>
23
+ </tr>
24
+ <% end %>
25
+ </table>
26
+ </div>
@@ -0,0 +1,59 @@
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>
13
+
14
+ <table class="table table-striped table-hover">
15
+ <thead>
16
+ <tr>
17
+ <th>Description</th>
18
+ <th>Debits</th>
19
+ <th>Credits</th>
20
+ <th>Date</th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <% @entries.each do |entry| %>
25
+ <tr class="<%= cycle("even", "odd") -%>">
26
+ <td><%=h entry.description %></td>
27
+ <td></td>
28
+ <td></td>
29
+ <td><%=h entry.created_at %></td>
30
+ </tr>
31
+ <% entry.debit_amounts.each do |debit_amount| %>
32
+ <tr class="<%= cycle("odd", "odd") -%>">
33
+ <td>&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{debit_amount.account.name}" %></td>
34
+ <td><%=h debit_amount.amount.round(2) %></td>
35
+ <td></td>
36
+ <td></td>
37
+ </tr>
38
+ <% end %>
39
+ <% entry.credit_amounts.each do |credit_amount| %>
40
+ <tr class="<%= cycle("odd", "odd") -%>">
41
+ <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{credit_amount.account.name}" %></td>
42
+ <td></td>
43
+ <td><%=h credit_amount.amount.round(2) %></td>
44
+ <td></td>
45
+ </tr>
46
+ <% end %>
47
+ <tr class="<%= cycle("odd", "odd") -%>">
48
+ <td></td>
49
+ <td></td>
50
+ <td></td>
51
+ <td></td>
52
+ </tr>
53
+ <% end %>
54
+ </tbody>
55
+ </table>
56
+
57
+ <%= paginate @entries %>
58
+
59
+ </div>
@@ -0,0 +1,28 @@
1
+ <table class="table table-striped table-hover">
2
+ <caption class="text-left"><b><%=name%></b></caption>
3
+ <thead>
4
+ <tr>
5
+ <th></th>
6
+ <th></th>
7
+ </tr>
8
+ </thead>
9
+ <% if accounts.count > 0%>
10
+ <tbody>
11
+ <% running_total = 0 %>
12
+ <% accounts.each do |account| %>
13
+ <% balance = account.balance(:from_date => @from_date, :to_date => @to_date) %>
14
+ <tr class="<%= cycle("even", "odd") -%>">
15
+ <td><%=h account.name %></td>
16
+ <td><%=h balance.round(2) %></td>
17
+ <% running_total += balance %>
18
+ </tr>
19
+ <% end %>
20
+ <tr class="<%= cycle("even", "odd") -%>">
21
+ <strong>
22
+ <td>Total <%= name %></td>
23
+ <td><%= running_total.round(2) %></td>
24
+ </strong>
25
+ </tr>
26
+ </tbody>
27
+ <% end %>
28
+ </table>
@@ -0,0 +1,21 @@
1
+ <div class="container">
2
+ <center>
3
+ <h1>Balance Sheet</h1>
4
+
5
+ <%= form_tag({:action => 'balance_sheet'}, {:method => :get, :class => 'form-inline'}) do%>
6
+ <div class="form-group">
7
+ <%= label_tag :date, nil, class: 'sr-only'%>
8
+ <%= text_field_tag :date, @to_date, :class => 'datepicker form-control' %>
9
+ </div>
10
+ <button type="submit" class="btn btn-default">Get Report</button>
11
+ <% end %>
12
+ </center>
13
+
14
+ <br>
15
+
16
+ <%= render 'account', :name => "Assets", :accounts => @assets %>
17
+ <%= render 'account', :name => "Liabilities", :accounts => @liabilities %>
18
+ <%= render 'account', :name => "Equity", :accounts => @equity %>
19
+
20
+
21
+ </div>
@@ -0,0 +1,24 @@
1
+ <div class="container">
2
+ <center>
3
+ <h1>Income Statement</h1>
4
+
5
+ <%= form_tag({:action => 'income_statement'}, {:method => :get, :class => 'form-inline'}) do%>
6
+ <div class="form-group">
7
+ <%= label_tag :from_date, nil, class: 'sr-only'%>
8
+ <%= text_field_tag :from_date, @from_date, :class => 'datepicker form-control', :placeholder => "Date" %>
9
+ </div>
10
+ <div class="form-group">
11
+ <%= label_tag :to_date, nil, class: 'sr-only'%>
12
+ <%= text_field_tag :to_date, @to_date, :class => 'datepicker form-control', :placeholder => "Date" %>
13
+ </div>
14
+ <button type="submit" class="btn btn-default">Get Report</button>
15
+ <% end %>
16
+ </center>
17
+
18
+ <br>
19
+
20
+ <%= render 'account', :name => "Revenues", :accounts => @revenues %>
21
+ <%= render 'account', :name => "Expenses", :accounts => @expenses %>
22
+
23
+
24
+ </div>
@@ -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;Borutus</a>
12
+ </div>
13
+ <div class="collapse navbar-collapse">
14
+ <ul class="nav navbar-nav">
15
+ <%= render 'layouts/borutus/navigation_links' %>
16
+ </ul>
17
+ </div>
18
+ </div>
19
+ </nav>