plutus 0.10.1 → 0.15

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 (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
@@ -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>
@@ -1,6 +1,9 @@
1
1
  Plutus::Engine.routes.draw do
2
- root :to => "accounts#index"
2
+ root :to => 'reports#balance_sheet'
3
3
 
4
- resources :accounts
5
- resources :entries
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]
6
9
  end
@@ -1,9 +1,9 @@
1
- class CreatePlutusTables < ActiveRecord::Migration
2
- def self.up
1
+ class CreatePlutusTables < ActiveRecord::Migration[4.2]
2
+ def change
3
3
  create_table :plutus_accounts do |t|
4
4
  t.string :name
5
5
  t.string :type
6
- t.boolean :contra
6
+ t.boolean :contra, default: false
7
7
 
8
8
  t.timestamps
9
9
  end
@@ -11,11 +11,13 @@ class CreatePlutusTables < ActiveRecord::Migration
11
11
 
12
12
  create_table :plutus_entries do |t|
13
13
  t.string :description
14
+ t.date :date
14
15
  t.integer :commercial_document_id
15
16
  t.string :commercial_document_type
16
17
 
17
18
  t.timestamps
18
19
  end
20
+ add_index :plutus_entries, :date
19
21
  add_index :plutus_entries, [:commercial_document_id, :commercial_document_type], :name => "index_entries_on_commercial_doc"
20
22
 
21
23
  create_table :plutus_amounts do |t|
@@ -23,15 +25,9 @@ class CreatePlutusTables < ActiveRecord::Migration
23
25
  t.references :account
24
26
  t.references :entry
25
27
  t.decimal :amount, :precision => 20, :scale => 10
26
- end
28
+ end
27
29
  add_index :plutus_amounts, :type
28
30
  add_index :plutus_amounts, [:account_id, :entry_id]
29
31
  add_index :plutus_amounts, [:entry_id, :account_id]
30
32
  end
31
-
32
- def self.down
33
- drop_table :plutus_accounts
34
- drop_table :plutus_entries
35
- drop_table :plutus_amounts
36
- end
37
33
  end
@@ -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
@@ -1,26 +1,12 @@
1
1
  # lib/generators/plutus/plutus_generator.rb
2
2
  require 'rails/generators'
3
3
  require 'rails/generators/migration'
4
-
5
- class PlutusGenerator < Rails::Generators::Base
6
- include Rails::Generators::Migration
7
-
8
- def self.source_root
9
- @source_root ||= File.join(File.dirname(__FILE__), 'templates')
10
- end
11
-
12
- # Implement the required interface for Rails::Generators::Migration.
13
- # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
14
- def self.next_migration_number(dirname)
15
- if ActiveRecord::Base.timestamped_migrations
16
- Time.now.utc.strftime("%Y%m%d%H%M%S")
17
- else
18
- "%.3d" % (current_migration_number(dirname) + 1)
19
- end
20
- end
21
-
22
- def create_migration_file
23
- migration_template 'migration.rb', 'db/migrate/create_plutus_tables.rb'
24
- end
25
-
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
26
12
  end
@@ -0,0 +1,12 @@
1
+ class AddDateToPlutusEntries < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :plutus_entries, :date, :date
4
+ add_index :plutus_entries, :date
5
+
6
+ execute <<-SQL
7
+ UPDATE plutus_entries
8
+ SET date = created_at
9
+ WHERE date is null
10
+ SQL
11
+ end
12
+ end
@@ -1,4 +1,4 @@
1
- class TenantPlutusTables < ActiveRecord::Migration
1
+ class TenantPlutusTables < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  # add a tenant column to plutus accounts table.
4
4
  add_column :plutus_accounts, :tenant_id, :integer, index: true
@@ -5,10 +5,10 @@ class UpdatePlutusTables < ActiveRecord::Migration
5
5
  remove_index :plutus_amounts, [:account_id, :transaction_id]
6
6
  remove_index :plutus_amounts, [:transaction_id, :account_id]
7
7
  remove_index :plutus_transactions, column: [:commercial_document_id, :commercial_document_type], :name => "index_transactions_on_commercial_doc"
8
-
8
+
9
9
  rename_table :plutus_transactions, :plutus_entries
10
10
  rename_column :plutus_amounts, :transaction_id, :entry_id
11
-
11
+
12
12
  # adding the indexes back
13
13
  add_index :plutus_amounts, [:account_id, :entry_id]
14
14
  add_index :plutus_amounts, [:entry_id, :account_id]
@@ -1,25 +1,10 @@
1
1
  # lib/generators/plutus/plutus_generator.rb
2
2
  require 'rails/generators'
3
3
  require 'rails/generators/migration'
4
+ require_relative 'base_generator'
4
5
 
5
6
  module Plutus
6
- class TenancyGenerator < Rails::Generators::Base
7
- include Rails::Generators::Migration
8
-
9
- def self.source_root
10
- @source_root ||= File.join(File.dirname(__FILE__), 'templates')
11
- end
12
-
13
- # Implement the required interface for Rails::Generators::Migration.
14
- # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
15
- def self.next_migration_number(dirname)
16
- if ActiveRecord::Base.timestamped_migrations
17
- Time.now.utc.strftime("%Y%m%d%H%M%S")
18
- else
19
- "%.3d" % (current_migration_number(dirname) + 1)
20
- end
21
- end
22
-
7
+ class TenancyGenerator < BaseGenerator
23
8
  def create_migration_file
24
9
  migration_template 'tenant_migration.rb', 'db/migrate/tenant_plutus_tables.rb'
25
10
  end
@@ -1,28 +1,12 @@
1
1
  # lib/generators/plutus/plutus_generator.rb
2
2
  require 'rails/generators'
3
3
  require 'rails/generators/migration'
4
+ require_relative 'base_generator'
4
5
 
5
6
  module Plutus
6
- class UpgradePlutusGenerator < Rails::Generators::Base
7
- include Rails::Generators::Migration
8
-
9
- def self.source_root
10
- @source_root ||= File.join(File.dirname(__FILE__), 'templates')
11
- end
12
-
13
- # Implement the required interface for Rails::Generators::Migration.
14
- # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
15
- def self.next_migration_number(dirname)
16
- if ActiveRecord::Base.timestamped_migrations
17
- Time.now.utc.strftime("%Y%m%d%H%M%S")
18
- else
19
- "%.3d" % (current_migration_number(dirname) + 1)
20
- end
21
- end
22
-
23
- def create_migration_file
24
- migration_template 'update_migration.rb', 'db/migrate/update_plutus_tables.rb'
25
- end
26
-
27
- end
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
28
12
  end
@@ -2,11 +2,6 @@
2
2
  require "rails"
3
3
 
4
4
  module Plutus
5
- class Engine < Rails::Engine
6
- isolate_namespace Plutus
7
- end
8
-
9
-
10
5
  # ------------------------------ tenancy ------------------------------
11
6
  # configuration to enable or disable tenancy
12
7
  mattr_accessor :enable_tenancy
@@ -21,3 +16,5 @@ module Plutus
21
16
  yield(self)
22
17
  end
23
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
@@ -1,3 +1,3 @@
1
1
  module Plutus
2
- VERSION = "0.10.1"
2
+ VERSION = "0.15"
3
3
  end
@@ -2,27 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  module Plutus
4
4
  describe AccountsController do
5
- # Run these tests if you enable routing in your rails app. See README
5
+ routes { Plutus::Engine.routes }
6
6
 
7
- #def mock_account(stubs={})
8
- #@mock_account ||= mock_model(Account, stubs)
9
- #end
10
-
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
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
7
+ def mock_account(stubs={})
8
+ @mock_account ||= FactoryGirl.create(:asset)
9
+ end
26
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
27
18
  end
28
19
  end
@@ -2,27 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  module Plutus
4
4
  describe EntriesController do
5
- # Run these tests if you enable routing in your rails app. See README
5
+ routes { Plutus::Engine.routes }
6
6
 
7
- #def mock_entry(stubs={})
8
- #@mock_entry ||= mock_model(Entry, stubs)
9
- #end
10
-
11
- #describe "GET index" do
12
- #it "assigns all entries as @entries" do
13
- #Entry.stub(:find).with(:all).and_return([mock_entry])
14
- #get :index
15
- #assigns[:entries].should == [mock_entry]
16
- #end
17
- #end
18
-
19
- #describe "GET show" do
20
- #it "assigns the requested entry as @entry" do
21
- #Entry.stub(:find).with("37").and_return(mock_entry)
22
- #get :show, :id => "37"
23
- #assigns[:entry].should equal(mock_entry)
24
- #end
25
- #end
7
+ def mock_entry(stubs={})
8
+ @mock_entry ||= FactoryGirl.create(:entry_with_credit_and_debit)
9
+ end
26
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
27
18
  end
28
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 ||= FactoryGirl.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,12 @@
1
+ module Plutus
2
+ class Tenant < ActiveRecord::Base
3
+ end
4
+ end
5
+
6
+ FactoryGirl.define do
7
+ factory :tenant, :class => Plutus::Tenant do
8
+ sequence :name do |n|
9
+ "Tenant #{n}"
10
+ end
11
+ end
12
+ end