This plutus plugin is a Ruby on Rails Engine which provides a double entry accounting system for your application.
-
install plugin
./script/plugin install git://github.com/mbulat/plutus.git
-
generate migration files
./script/generate plutus plutus
-
run migrations
rake db:migrate
The plutus plugin provides a complete double entry accounting system for use in any Ruby on Rails application. The plugin follows general Double Entry Bookkeeping practices. All calculations are done using BigDecimal in order to prevent floating point rounding errors. The plugin requires a decimal type on your database as well.
The system consists of a table that maintains your accounts and a table for recording transactions. The Account table uses single table inheritance to store information on each type of account (Asset, Liability, Equity, Revenue, Expense). The transaction table, which records your business transactions, is essentially your accounting Journal
Every account object has a 'has_many' association of credit and debit transactions, which means that each account object also acts as it's own Ledger, and exposes a method to calculate the balance of the account.
See the {Account} and {Transaction} classes for more information.
Let's assume the owner of the business wants to withdraw money from the business. First we'll assume that an asset account for "Cash" as well as a contra-equity account for "Drawings" has been setup
>> Equity.create(:name => "Drawing", :contra => true)
>> Asset.create(:name => "Cash")
In order to record cash being withdrawn from the business by the owner, we would create the following transaction
>> Transaction.create(:description => "Owner withdrawing cash",
:credit_account => Asset.find_by_name("Cash"),
:debit_account => Equity.find_by_name("Drawing"),
:amount => 1000)
Each account can report on it's own balance. This number should normally be positive. If the number is negative, you may have a problem.
>> cash = Asset.find_by_name("Cash")
>> cash.balance
=> #<BigDecimal:103259bb8,'0.2E4',4(12)>
Each subclass of accounts can report on the total balance of all the accounts of that type. This number should normally be positive. If the number is negative, you may have a problem.
>> Asset.balance
=> #<BigDecimal:103259bb8,'0.2E4',4(12)>
The Trial Balance for all accounts on the system can be found through the abstract Account class. This value should be 0 unless there is an error in the system.
>> Account.trial_balance
=> #<BigDecimal:1031c0d28,'0.0',4(12)>
The Engine provides controllers and views for viewing Accounts and Transactions via the {AccountsController} and {TransactionsController} classes. The controllers will render HTML, XML and JSON, and are compatible with ActiveResource
Routing is NOT supplied by the engine. You can add routes to your application in your config/routes.rb with something like the following
map.resources :transactions, :only => [:index, :show], :conditions => { :method => :get }
map.resources :accounts, :only => [:index, :show], :conditions => { :method => :get }
NOTE: If you enable routing, you should ensure that your ApplicationController enforces its own authentication and authorization, which this controller will inherit.
Rspec tests are provided. Install both the rpsec and rspec-rails gems, and install this plugin into a working rails application to run the tests.
Copyright (c) 2010 Michael Bulat