Skip to content

Commit

Permalink
updating doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mbulat committed May 15, 2012
1 parent 6cd464d commit 48a2433
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 382 deletions.
123 changes: 71 additions & 52 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ Plutus
=================
[![Build Status](https://secure.travis-ci.org/mbulat/plutus.png?branch=master)](http://travis-ci.org/mbulat/plutus)

This plutus plugin is a Ruby on Rails Engine which provides a double entry accounting system for your application.
The Plutus plugin is a Ruby on Rails Engine which provides a double entry accounting system for your application.

NOTE: This version of Plutus is compatible with RAILS 3.1
=========================================================
### NOTE: This version of Plutus is compatible with RAILS 3.1

For the rails 2 version, you can go here:

Expand All @@ -27,9 +26,9 @@ Overview

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](http://en.wikipedia.org/wiki/Double-entry_bookkeeping_system) practices. All calculations are done using [BigDecimal](http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/bigdecimal/rdoc/classes/BigDecimal.html) in order to prevent floating point rounding errors. The plugin requires a decimal type on your database as well.

The system consists of tables that maintains your account, transactions and debits and credits. Each transaction can have many debits and credits. The transaction table, which records your business transactions is, essentially, your accounting [Journal](http://en.wikipedia.org/wiki/Journal_entry)
The system consists of tables that maintains your accounts, transactions and debits and credits. Each transaction can have many debits and credits. The transaction table, which records your business transactions is, essentially, your accounting [Journal](http://en.wikipedia.org/wiki/Journal_entry).

Posting to a [Ledger](http://en.wikipedia.org/wiki/General_ledger) can be considered to happen automatically, since Accounts have the reverse `has_many` relationship to either its credit or debit transactions
Posting to a [Ledger](http://en.wikipedia.org/wiki/General_ledger) can be considered to happen automatically, since Accounts have the reverse `has_many` relationship to either its credit or debit transactions.

Accounts
--------
Expand All @@ -44,6 +43,17 @@ The Account class represents accounts in the system. The Account table uses sing
Revenue | Credit | Increases in owners equity
Expense | Debit | Assets or services consumed in the generation of revenue

Your Book of Accounts needs to be created prior to recording any transactions. The simplest method is to have a number of create methods in your db/seeds.rb file like so:

Plutus::Asset.create(:name => "Accounts Receivable")
Plutus::Asset.create(:name => "Cash")
Plutus::Revenue.create(:name => "Sales Revenue")
Plutus::Liability.create(:name => "Unearned Revenue")
Plutus::Liability.create(:name => "Sales Tax Payable")
etc...

Then simply run `rake db:seed`

Each account can also be marked as a "Contra Account". A contra account will have its normal balance swapped. For example, to remove equity, a "Drawing" account may be created as a contra equity account as follows:

Plutus::Equity.create(:name => "Drawing", contra => true)
Expand All @@ -57,8 +67,6 @@ Every account object has a `has_many` association of credit and debit transactio

See the {Plutus::Account}, {Plutus::Transaction}, and {Plutus::Amount} classes for more information.



Examples
========

Expand All @@ -67,47 +75,45 @@ Recording a Transaction

Let's assume we're accounting on an [Accrual basis](http://en.wikipedia.org/wiki/Accounting_methods). We've just taken a customer's order for some widgets, which we've also billed him for. At this point we've actually added a liability to the company until we deliver the goods. To record this transaction we'd need two accounts:

>> cash = Plutus::Asset.create(:name => "Cash")
>> unearned_revenue = Plutus::Liability.create(:name => "Unearned Revenue")
>> Plutus::Asset.create(:name => "Cash")
>> Plutus::Liability.create(:name => "Unearned Revenue")

Next we'll setup the transaction we want to record:
Next we'll build the transaction we want to record. Plutus provides a simple interface to build the transaction.

>> transaction = Plutus::Transaction.new(:description => "Order placed for widgets")
transaction = Plutus::Transaction.build(
:description => "Order placed for widgets",
:debits => [
{:account => "Cash", :amount => 100.00}],
:credits => [
{:account => "Unearned Revenue", :amount => 100.00}])

We then specify the amount that is debited and credited from each account for this transaction:
The build method takes a hash consisting of a description, and an array of debits and credits. Each debit and credit item is a hash that specifies the amount, and the account to be debited or credited. Simply pass in the string name you used when you created the account.

>> transaction.debit_amounts << Plutus::DebitAmount.new(:amount => 1000, account: cash, transaction: transaction)
>> transaction.credit_amounts << Plutus::CreditAmount.new(:amount => 1000, account: unearned_revenue, transaction: transaction)

Finally, save the transaction, which saves the corresponding credit and debit amounts.
Finally, save the transaction.

>> transaction.save

If there are any issues with your credit and debit amounts, the save will fail and return false. You can inspect the errors via `transaction.errors`. Because we are doing double-entry accounting, your credit and debit amounts must always cancel out to keep the accounts in balance.

Recording a Transaction with multiple accounts
----------------------------------------------

Often times a single transaction requires more than one type of account. A classic example would be a transaction in which a tax is charged. We'll assume that we have not yet received payment for the order, so we'll need an "Accounts Receivable" Asset:

>> accounts_receivable = Plutus::Asset.create(:name => "Accounts Receivable")
>> sales_revenue = Plutus::Revenue.create(:name => "Sales Revenue")
>> sales_tax_payable = Plutus::Liability.create(:name => "Sales Tax Payable")

Next we'll setup the transaction:

>> transaction = Plutus::Transaction.new(:description => "Sold some widgets")

And now we apply the amounts:
>> Plutus::Asset.create(:name => "Accounts Receivable")
>> Plutus::Revenue.create(:name => "Sales Revenue")
>> Plutus::Liability.create(:name => "Sales Tax Payable")

>> transaction.debit_amounts << Plutus::DebitAmount.new(:amount => 1060, account: accounts_receivable, transaction: transaction)
>> transaction.credit_amounts << Plutus::CreditAmount.new(:amount => 1000, account: sales_revenue, transaction: transaction)
>> transaction.credit_amounts << Plutus::CreditAmount.new(:amount => 60, account: sales_tax_payable, transaction: transaction)

Finally, save the transaction, which saves the corresponding credit and debit amounts.

>> transaction.save

Note, your credit and debit amounts must always cancel out to keep the accounts in balance.
And here's the transaction:

transaction = Plutus::Transaction.build(
:description => "Sold some widgets",
:debits => [
{:account => "Accounts Receivable", :amount => 50}],
:credits => [
{:account => "Sales Revenue", :amount => 45},
{:account => "Sales Tax Payable", :amount => 5}])
transaction.save
Associating Documents
---------------------
Expand All @@ -120,10 +126,15 @@ Suppose we pull up our latest invoice in order to generate a transaction for plu

Let's assume we're using the same transaction from the last example

>> transaction = Plutus::Transaction.new(:description => "Sold some widgets", :commercial_document => invoice)
>> transaction.debit_amounts << Plutus::DebitAmount.new(:amount => invoice.total_amount, account: accounts_receivable, transaction: transaction)
>> transaction.credit_amounts << Plutus::CreditAmount.new(:amount => invoice.sales_amount, account: sales_revenue, transaction: transaction)
>> transaction.credit_amounts << Plutus::CreditAmount.new(:amount => invoice.tax_amount, account: sales_tax_payable, transaction: transaction)
transaction = Plutus::Transaction.build(
:description => "Sold some widgets",
:commercial_document => invoice,
:debits => [
{:account => "Accounts Receivable", :amount => invoice.total_amount}],
:credits => [
{:account => "Sales Revenue", :amount => invoice.sales_amount},
{:account => "Sales Tax Payable", :amount => invoice.tax_amount}])
transaction.save

The commercial document attribute on the transaction is a polymorphic association allowing you to associate any record from your models with a transaction (i.e. Bills, Invoices, Receipts, Returns, etc.)

Expand Down Expand Up @@ -162,27 +173,33 @@ For complex transaction, you should always ensure that you are balancing your ac

For example, let's assume the owner of a business wants to withdraw cash. First we'll assume that we have an asset account for "Cash" which the funds will be drawn from. We'll then need an Equity account to record where the funds are going, however, in this case, we can't simply create a regular Equity account. The "Cash" account must be credited for the decrease in its balance since it's an Asset. Likewise, Equity accounts are typically credited when there is an increase in their balance. Equity is considered an owner's rights to Assets in the business. In this case however, we are not simply increasing the owner's rights to assets within the business; we are actually removing capital from the business altogether. Hence both sides of our accounting equation will see a decrease. In order to accomplish this, we need to create a Contra-Equity account we'll call "Drawings". Since Equity accounts normally have credit balances, a Contra-Equity account will have a debit balance, which is what we need for our transaction.

>> drawing = Plutus::Equity.create(:name => "Drawing", :contra => true)
>> cash = Plutus::Asset.create(:name => "Cash")
>> Plutus::Equity.create(:name => "Drawing", :contra => true)
>> Plutus::Asset.create(:name => "Cash")

We would then create the following transaction:

>> transaction = Plutus::Transaction.new(:description => "Owner withdrawing cash")
>> transaction.debit_amounts << Plutus::DebitAmount.new(:amount => 1000, account: drawing, transaction: transaction)
>> transaction.credit_amounts << Plutus::CreditAmount.new(:amount => 1000, account: cash, transaction: transaction)
>> transaction.save
transaction = Plutus::Transaction.build(
:description => "Owner withdrawing cash",
:debits => [
{:account => "Drawing", :amount => 1000}],
:credits => [
{:account => "Cash", :amount => 1000}])
transaction.save

To make the example clearer, imagine instead that the owner decides to invest his money into the business in exchange for some type of equity security. In this case we might have the following accounts:

>> common_stock = Plutus::Equity.create(:name => "Common Stock")
>> cash = Plutus::Asset.create(:name => "Cash")
>> Plutus::Equity.create(:name => "Common Stock")
>> Plutus::Asset.create(:name => "Cash")

And out transaction would be:

>> transaction = Plutus::Transaction.new(:description => "Owner investing cash")
>> transaction.debit_amounts << Plutus::DebitAmount.new(:amount => 1000, account: cash, transaction: transaction)
>> transaction.credit_amounts << Plutus::CreditAmount.new(:amount => 1000, account: common_stock, transaction: transaction)
>> transaction.save
transaction = Plutus::Transaction.build(
:description => "Owner investing cash",
:debits => [
{:account => "Cash", :amount => 1000}],
:credits => [
{:account => "Common Stock", :amount => 1000}])
transaction.save

In this case, we've increase our cash Asset, and simultaneously increased the other side of our accounting equation in
Equity, keeping everything balanced.
Expand All @@ -192,6 +209,8 @@ Access & Security

The Engine provides controllers and views for viewing Accounts and Transactions via the {Plutus::AccountsController} and {Plutus::TransactionsController} classes. The controllers will render HTML, XML and JSON, and are compatible with [ActiveResource](http://api.rubyonrails.org/classes/ActiveResource/Base.html)

These controllers are read-only for reporting purposes. It is assumed transaction creation will occur within your applications code.

Routing is supplied via an engine mount point. Plutus can be mounted on a subpath in your existing Rails 3 app by adding the following to your routes.rb:

mount Plutus::Engine => "/plutus", :as => "plutus"
Expand All @@ -218,4 +237,4 @@ For a complete reference on Accounting principles, we recommend the following te

* * *

Copyright (c) 2010 Michael Bulat
Copyright (c) 2010-2012 Michael Bulat
2 changes: 1 addition & 1 deletion doc/Plutus.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h2>Defined Under Namespace</h2>
</div>

<div id="footer">
Generated on Mon May 14 16:58:45 2012 by
Generated on Tue May 15 12:38:13 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
8 changes: 4 additions & 4 deletions doc/Plutus/Account.html
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ <h3 class="signature first" id="trial_balance-class_method">
<pre class="lines">


48
49
50
51
52
53
54</pre>
54
55</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'app/models/plutus/account.rb', line 48</span>
<pre class="code"><span class="info file"># File 'app/models/plutus/account.rb', line 49</span>

<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_trial_balance'>trial_balance</span>
<span class='kw'>unless</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>==</span> <span class='const'>Account</span>
Expand All @@ -304,7 +304,7 @@ <h3 class="signature first" id="trial_balance-class_method">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/AccountsController.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ <h3 class="signature " id="show-instance_method">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/Amount.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ <h2>Direct Known Subclasses</h2>
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:13 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/Asset.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ <h3 class="signature " id="debits_balance-instance_method">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:13 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/CreditAmount.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ <h2>Overview</h2><div class="docstring">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/DebitAmount.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h2>Overview</h2><div class="docstring">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/Equity.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ <h3 class="signature " id="debits_balance-instance_method">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/Expense.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ <h3 class="signature " id="debits_balance-instance_method">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/Liability.html
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ <h3 class="signature " id="debits_balance-instance_method">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/Plutus/Revenue.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ <h3 class="signature " id="debits_balance-instance_method">
</div>

<div id="footer">
Generated on Mon May 14 16:58:46 2012 by
Generated on Tue May 15 12:38:14 2012 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.1 (ruby-1.9.3).
</div>
Expand Down
Loading

0 comments on commit 48a2433

Please sign in to comment.