tyche 0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +23 -0
  3. data/README.markdown +392 -0
  4. data/Rakefile +11 -0
  5. data/app/assets/javascripts/plutus/application.js +16 -0
  6. data/app/assets/javascripts/plutus/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/plutus/application.css +19 -0
  10. data/app/controllers/plutus/accounts_controller.rb +30 -0
  11. data/app/controllers/plutus/application_controller.rb +4 -0
  12. data/app/controllers/plutus/entries_controller.rb +34 -0
  13. data/app/controllers/plutus/reports_controller.rb +40 -0
  14. data/app/models/plutus/account.rb +172 -0
  15. data/app/models/plutus/amount.rb +24 -0
  16. data/app/models/plutus/amounts_extension.rb +42 -0
  17. data/app/models/plutus/asset.rb +56 -0
  18. data/app/models/plutus/balance_finders/base_balance_finder.rb +13 -0
  19. data/app/models/plutus/credit_amount.rb +10 -0
  20. data/app/models/plutus/debit_amount.rb +10 -0
  21. data/app/models/plutus/entry.rb +77 -0
  22. data/app/models/plutus/equity.rb +56 -0
  23. data/app/models/plutus/expense.rb +56 -0
  24. data/app/models/plutus/liability.rb +56 -0
  25. data/app/models/plutus/no_tenancy.rb +9 -0
  26. data/app/models/plutus/revenue.rb +56 -0
  27. data/app/models/plutus/tenancy.rb +15 -0
  28. data/app/views/layouts/plutus/_messages.html.erb +9 -0
  29. data/app/views/layouts/plutus/_navigation.html.erb +19 -0
  30. data/app/views/layouts/plutus/_navigation_links.html.erb +5 -0
  31. data/app/views/layouts/plutus/application.html.erb +19 -0
  32. data/app/views/plutus/accounts/index.html.erb +26 -0
  33. data/app/views/plutus/entries/index.html.erb +59 -0
  34. data/app/views/plutus/reports/_account.html.erb +28 -0
  35. data/app/views/plutus/reports/balance_sheet.html.erb +21 -0
  36. data/app/views/plutus/reports/income_statement.html.erb +24 -0
  37. data/config/backtrace_silencers.rb +7 -0
  38. data/config/database.yml +5 -0
  39. data/config/inflections.rb +10 -0
  40. data/config/mime_types.rb +5 -0
  41. data/config/routes.rb +9 -0
  42. data/config/secret_token.rb +7 -0
  43. data/config/session_store.rb +8 -0
  44. data/db/migrate/20160422010135_create_plutus_tables.rb +35 -0
  45. data/lib/generators/plutus/USAGE +22 -0
  46. data/lib/generators/plutus/add_date_upgrade_generator.rb +11 -0
  47. data/lib/generators/plutus/base_generator.rb +19 -0
  48. data/lib/generators/plutus/plutus_generator.rb +12 -0
  49. data/lib/generators/plutus/templates/tenant_migration.rb +6 -0
  50. data/lib/generators/plutus/tenancy_generator.rb +12 -0
  51. data/lib/generators/plutus/upgrade_plutus_generator.rb +12 -0
  52. data/lib/plutus.rb +20 -0
  53. data/lib/plutus/engine.rb +5 -0
  54. data/lib/plutus/version.rb +3 -0
  55. data/spec/controllers/accounts_controller_spec.rb +19 -0
  56. data/spec/controllers/entries_controller_spec.rb +19 -0
  57. data/spec/controllers/reports_controller_spec.rb +24 -0
  58. data/spec/factories/account_factory.rb +35 -0
  59. data/spec/factories/amount_factory.rb +20 -0
  60. data/spec/factories/entry_factory.rb +11 -0
  61. data/spec/lib/plutus_spec.rb +0 -0
  62. data/spec/models/account_spec.rb +133 -0
  63. data/spec/models/amount_spec.rb +13 -0
  64. data/spec/models/asset_spec.rb +7 -0
  65. data/spec/models/credit_amount_spec.rb +7 -0
  66. data/spec/models/debit_amount_spec.rb +7 -0
  67. data/spec/models/entry_spec.rb +182 -0
  68. data/spec/models/equity_spec.rb +7 -0
  69. data/spec/models/expense_spec.rb +7 -0
  70. data/spec/models/liability_spec.rb +7 -0
  71. data/spec/models/revenue_spec.rb +7 -0
  72. data/spec/models/tenancy_spec.rb +45 -0
  73. data/spec/rcov.opts +2 -0
  74. data/spec/routing/accounts_routing_spec.rb +13 -0
  75. data/spec/routing/entries_routing_spec.rb +13 -0
  76. data/spec/spec.opts +4 -0
  77. data/spec/spec_helper.rb +30 -0
  78. data/spec/support/account_shared_examples.rb +62 -0
  79. data/spec/support/active_support_helpers.rb +13 -0
  80. data/spec/support/amount_shared_examples.rb +21 -0
  81. data/spec/support/factory_girl_helpers.rb +8 -0
  82. data/spec/support/shoulda_matchers.rb +8 -0
  83. metadata +240 -0
@@ -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,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,5 @@
1
+ # config/database.yml in Rails
2
+ test:
3
+ adapter: sqlite3
4
+ database: ":memory:"
5
+ timeout: 500
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,9 @@
1
+ Plutus::Engine.routes.draw do
2
+ root :to => 'reports#balance_sheet'
3
+
4
+ get 'reports/balance_sheet' => 'reports#balance_sheet'
5
+ get 'reports/income_statement' => 'reports#income_statement'
6
+
7
+ resources :accounts, only: [:index]
8
+ resources :entries, only: [:index]
9
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Plutus::Application.config.secret_token = 'f6b9c48aaf200fda4bbcf1642319084d5e5cda2bd95ac0a43220aab19f4ee240f9cdab08b77c3284b3a6396b13b1fe8be12a227af04fc5f5a8b7a52b626c4fdd'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Plutus::Application.config.session_store :cookie_store, :key => '_plutus_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Testtest::Application.config.session_store :active_record_store
@@ -0,0 +1,35 @@
1
+ class CreatePlutusTables < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :plutus_accounts do |t|
4
+ t.string :name
5
+ t.string :type
6
+ t.boolean :contra, default: false
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :plutus_accounts, [:name, :type]
11
+
12
+ create_table :plutus_entries do |t|
13
+ t.string :description
14
+ t.date :date
15
+ t.integer :commercial_document_id
16
+ t.string :commercial_document_type
17
+
18
+ t.timestamps
19
+ end
20
+ add_index :plutus_entries, :date
21
+ add_index :plutus_entries, [:commercial_document_id, :commercial_document_type], :name => "index_entries_on_commercial_doc"
22
+
23
+ create_table :plutus_amounts do |t|
24
+ t.string :type
25
+ t.references :account
26
+ t.references :entry
27
+ t.decimal :amount, :precision => 20, :scale => 10
28
+
29
+ t.timestamps
30
+ end
31
+ add_index :plutus_amounts, :type
32
+ add_index :plutus_amounts, [:account_id, :entry_id]
33
+ add_index :plutus_amounts, [:entry_id, :account_id]
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ Description:
2
+ Generator for Plutus Plugin
3
+
4
+ Installation:
5
+ rails g plutus
6
+
7
+ This will:
8
+ Create a migration in the application for the "Account",
9
+ "Entry" and "Amount" tables.
10
+
11
+ Once generated, simply run:
12
+ rake db:migrate
13
+
14
+ Upgrade < 0.8 -> 0.9+:
15
+ rails g plutus:upgrade_plutus
16
+
17
+ This will:
18
+ Create a migration in the application for renaming the
19
+ "Transaction" table, columns and indexes to "Entry" tables.
20
+
21
+ Once generated, simply run:
22
+ rake db:migrate
@@ -0,0 +1,11 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require_relative 'base_generator'
4
+
5
+ module Plutus
6
+ class AddDateUpgradeGenerator < BaseGenerator
7
+ def create_migration_file
8
+ migration_template 'add_date_migration.rb', 'db/migrate/add_date_to_plutus_entries.rb'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Plutus
2
+ class BaseGenerator < Rails::Generators::Base
3
+ include Rails::Generators::Migration
4
+
5
+ def self.source_root
6
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
7
+ end
8
+
9
+ # Implement the required interface for Rails::Generators::Migration.
10
+ # See http://apidock.com/rails/ActiveRecord/Generators/Base/next_migration_number/class
11
+ def self.next_migration_number(dirname)
12
+ if ActiveRecord::Base.timestamped_migrations
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ # lib/generators/plutus/plutus_generator.rb
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+ require_relative 'base_generator'
5
+
6
+ module Plutus
7
+ class PlutusGenerator < BaseGenerator
8
+ def create_migration_file
9
+ migration_template 'migration.rb', 'db/migrate/create_plutus_tables.rb'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ class TenantPlutusTables < ActiveRecord::Migration[4.2]
2
+ def change
3
+ # add a tenant column to plutus accounts table.
4
+ add_column :plutus_accounts, :tenant_id, :integer, index: true
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ # lib/generators/plutus/plutus_generator.rb
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+ require_relative 'base_generator'
5
+
6
+ module Plutus
7
+ class TenancyGenerator < BaseGenerator
8
+ def create_migration_file
9
+ migration_template 'tenant_migration.rb', 'db/migrate/tenant_plutus_tables.rb'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # lib/generators/plutus/plutus_generator.rb
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+ require_relative 'base_generator'
5
+
6
+ module Plutus
7
+ class UpgradePlutusGenerator < BaseGenerator
8
+ def create_migration_file
9
+ migration_template 'update_migration.rb', 'db/migrate/update_plutus_tables.rb'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ # Plutus
2
+ require "rails"
3
+
4
+ module Plutus
5
+ # ------------------------------ tenancy ------------------------------
6
+ # configuration to enable or disable tenancy
7
+ mattr_accessor :enable_tenancy
8
+ enable_tenancy = false
9
+
10
+ mattr_accessor :tenant_class
11
+ tenant_class = nil
12
+
13
+
14
+ # provide hook to configure attributes
15
+ def self.config
16
+ yield(self)
17
+ end
18
+ end
19
+
20
+ require "plutus/engine"
@@ -0,0 +1,5 @@
1
+ module Plutus
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Plutus
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Plutus
2
+ VERSION = "0.14"
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Plutus
4
+ describe AccountsController do
5
+ routes { Plutus::Engine.routes }
6
+
7
+ def mock_account(stubs={})
8
+ @mock_account ||= FactoryBot.create(:asset)
9
+ end
10
+
11
+ describe "GET index" do
12
+ it "assigns all accounts as @accounts" do
13
+ allow(Account).to receive(:all).and_return([mock_account])
14
+ get :index
15
+ expect(assigns[:accounts]).to eq([mock_account])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Plutus
4
+ describe EntriesController do
5
+ routes { Plutus::Engine.routes }
6
+
7
+ def mock_entry(stubs={})
8
+ @mock_entry ||= FactoryBot.create(:entry_with_credit_and_debit)
9
+ end
10
+
11
+ describe "GET index" do
12
+ it "assigns all entries as @entries" do
13
+ allow(Entry).to receive_message_chain(:per, :order).and_return([mock_entry])
14
+ get :index
15
+ expect(assigns[:entries]).to eq([mock_entry])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Plutus
4
+ describe ReportsController do
5
+ routes { Plutus::Engine.routes }
6
+
7
+ def mock_entry(stubs={})
8
+ @mock_entry ||= FactoryBot.create(:entry_with_credit_and_debit)
9
+ end
10
+
11
+ describe "GET balance_sheet" do
12
+ it "renders when one entry exists" do
13
+ allow(Entry).to receive_message_chain(:order).and_return([mock_entry])
14
+ get :balance_sheet
15
+ expect(response).to be_success
16
+ end
17
+ it "renders when no entries exist" do
18
+ allow(Entry).to receive_message_chain(:order).and_return([])
19
+ get :balance_sheet
20
+ expect(response).to be_success
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ FactoryBot.define do
2
+ factory :account, :class => Plutus::Account do |account|
3
+ account.name
4
+ account.contra false
5
+ end
6
+
7
+ factory :asset, :class => Plutus::Asset do |account|
8
+ account.name
9
+ account.contra false
10
+ end
11
+
12
+ factory :equity, :class => Plutus::Equity do |account|
13
+ account.name
14
+ account.contra false
15
+ end
16
+
17
+ factory :expense, :class => Plutus::Expense do |account|
18
+ account.name
19
+ account.contra false
20
+ end
21
+
22
+ factory :liability, :class => Plutus::Liability do |account|
23
+ account.name
24
+ account.contra false
25
+ end
26
+
27
+ factory :revenue, :class => Plutus::Revenue do |account|
28
+ account.name
29
+ account.contra false
30
+ end
31
+
32
+ sequence :name do |n|
33
+ "Factory Name #{n}"
34
+ end
35
+ end