blawzoo-plutus 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.yardopts +2 -0
  2. data/LICENSE +23 -0
  3. data/README.markdown +197 -0
  4. data/Rakefile +11 -0
  5. data/VERSION.yml +5 -0
  6. data/app/controllers/accounts_controller.rb +43 -0
  7. data/app/controllers/transactions_controller.rb +42 -0
  8. data/app/models/account.rb +57 -0
  9. data/app/models/asset.rb +81 -0
  10. data/app/models/equity.rb +82 -0
  11. data/app/models/expense.rb +81 -0
  12. data/app/models/liability.rb +76 -0
  13. data/app/models/revenue.rb +81 -0
  14. data/app/models/transaction.rb +27 -0
  15. data/app/views/accounts/index.html.erb +27 -0
  16. data/app/views/accounts/show.html.erb +69 -0
  17. data/app/views/layouts/accounts.html.erb +68 -0
  18. data/app/views/layouts/transactions.html.erb +68 -0
  19. data/app/views/transactions/index.html.erb +27 -0
  20. data/app/views/transactions/show.html.erb +24 -0
  21. data/doc/Account.html +300 -0
  22. data/doc/AccountsController.html +317 -0
  23. data/doc/Asset.html +610 -0
  24. data/doc/Equity.html +610 -0
  25. data/doc/Expense.html +610 -0
  26. data/doc/Liability.html +588 -0
  27. data/doc/Revenue.html +610 -0
  28. data/doc/Transaction.html +156 -0
  29. data/doc/TransactionsController.html +317 -0
  30. data/doc/_index.html +204 -0
  31. data/doc/class_list.html +36 -0
  32. data/doc/file.README.html +250 -0
  33. data/doc/file_list.html +38 -0
  34. data/doc/frames.html +13 -0
  35. data/doc/index.html +250 -0
  36. data/doc/js/app.js +202 -0
  37. data/doc/js/full_list.js +149 -0
  38. data/doc/js/jquery.js +154 -0
  39. data/doc/method_list.html +275 -0
  40. data/doc/top-level-namespace.html +90 -0
  41. data/lib/plutus.rb +6 -0
  42. data/plutus.gemspec +116 -0
  43. data/spec/controllers/accounts_controller_spec.rb +26 -0
  44. data/spec/controllers/transactions_controller_spec.rb +26 -0
  45. data/spec/factories/account_factory.rb +31 -0
  46. data/spec/factories/transaction_factory.rb +6 -0
  47. data/spec/lib/plutus_spec.rb +0 -0
  48. data/spec/models/account_spec.rb +43 -0
  49. data/spec/models/asset_spec.rb +46 -0
  50. data/spec/models/equity_spec.rb +46 -0
  51. data/spec/models/expense_spec.rb +46 -0
  52. data/spec/models/liability_spec.rb +46 -0
  53. data/spec/models/revenue_spec.rb +46 -0
  54. data/spec/models/transaction_spec.rb +48 -0
  55. data/spec/rcov.opts +2 -0
  56. data/spec/routing/accounts_routing_spec.rb +30 -0
  57. data/spec/routing/transactions_routing_spec.rb +30 -0
  58. data/spec/schema.rb +31 -0
  59. data/spec/spec.opts +4 -0
  60. data/spec/spec_helper.rb +14 -0
  61. data/tasks/plutus_tasks.rake +4 -0
  62. metadata +204 -0
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html>
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=utf-8" />
6
+ <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
7
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
8
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
9
+ <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
10
+ <base id="base_target" target="_parent" />
11
+ </head>
12
+ <body>
13
+ <script type="text/javascript" charset="utf-8">
14
+ if (window.top.frames.main) {
15
+ document.getElementById('base_target').target = 'main';
16
+ document.body.className = 'frames';
17
+ }
18
+ </script>
19
+ <div id="content">
20
+ <h1 id="full_list_header">File List</h1>
21
+ <div id="nav">
22
+ <a target="_self" href="class_list.html">Classes</a> |
23
+ <a target="_self" href="method_list.html">Methods</a> |
24
+ <a target="_self" href="file_list.html">Files</a>
25
+ </div>
26
+ <div id="search">Search: <input type="text" /></div>
27
+
28
+ <ul id="full_list" class="files">
29
+
30
+
31
+ <li class="r1"><a href="index.html" title="README">README</a></li>
32
+
33
+
34
+ </ul>
35
+ </div>
36
+ </body>
37
+ </html>
38
+
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+ <title>Documentation by YARD 0.6.2</title>
8
+ </head>
9
+ <frameset cols="20%,*">
10
+ <frame name="list" src="class_list.html" />
11
+ <frame name="main" src="index.html" />
12
+ </frameset>
13
+ </html>
@@ -0,0 +1,250 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta name="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>Documentation by YARD 0.6.2</title>
7
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
8
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
9
+
10
+ <script type="text/javascript" charset="utf-8">
11
+ relpath = '';
12
+ if (relpath != '') relpath += '/';
13
+ </script>
14
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
15
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
16
+
17
+ </head>
18
+ <body>
19
+ <script type="text/javascript" charset="utf-8">
20
+ if (window.top.frames.main) document.body.className = 'frames';
21
+ </script>
22
+
23
+ <div id="header">
24
+ <div id="menu">
25
+
26
+ <a href="_index.html" title="Index">Index</a> &raquo;
27
+ <span class="title">File: README</span>
28
+
29
+
30
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
31
+ </div>
32
+
33
+ <div id="search">
34
+ <a id="class_list_link" href="#">Class List</a>
35
+ <a id="method_list_link" href="#">Method List</a>
36
+ <a id ="file_list_link" href="#">File List</a>
37
+ </div>
38
+
39
+ <div class="clear"></div>
40
+ </div>
41
+
42
+ <iframe id="search_frame"></iframe>
43
+
44
+ <div id="content"><div id='filecontents'><h1>Plutus</h1>
45
+
46
+ <p>This plutus plugin is a Ruby on Rails Engine which provides a double entry accounting system for your application.</p>
47
+
48
+ <h1>NOTE: This version of Plutus is compatable with RAILS 3</h1>
49
+
50
+ <p>For the rails 2 version, you can go here:</p>
51
+
52
+ <p><a href="https://github.com/mbulat/plutus/tree/rails2">https://github.com/mbulat/plutus/tree/rails2</a></p>
53
+
54
+ <p>Gems in RubyGems.org >= 0.5.0 support Rails 3</p>
55
+
56
+ <h1>Installation</h1>
57
+
58
+ <ul>
59
+ <li><p>Add the gem to your Gemfile <code>gem "plutus"</code></p></li>
60
+ <li><p>generate migration files <code>rails g plutus</code></p></li>
61
+ <li><p>run migrations <code>rake db:migrate</code></p></li>
62
+ </ul>
63
+
64
+
65
+ <h1>Overview</h1>
66
+
67
+ <p>The plutus plugin provides a complete double entry accounting system for use in any Ruby on Rails application. The plugin follows general <a href="http://en.wikipedia.org/wiki/Double-entry_bookkeeping_system">Double Entry Bookkeeping</a> practices. All calculations are done using <a href="http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/bigdecimal/rdoc/classes/BigDecimal.html">BigDecimal</a> in order to prevent floating point rounding errors. The plugin requires a decimal type on your database as well.</p>
68
+
69
+ <p>The system consists of a table that maintains your accounts and a table for recording transactions. Transactions are the recording of debits and credits to various accounts. The transaction table, which records your business transactions is, essentially, your accounting <a href="http://en.wikipedia.org/wiki/Journal_entry">Journal</a></p>
70
+
71
+ <p>Posting to a <a href="http://en.wikipedia.org/wiki/General_ledger">Ledger</a> can be considered to happen automatically, since Accounts have the reverse <code>has_many</code> relationship to either its credit or debit transactions</p>
72
+
73
+ <h2>Accounts</h2>
74
+
75
+ <p>The Account class represents accounts in the system. The Account table uses single table inheritance to store information on each type of account (Asset, Liability, Equity, Revenue, Expense). Each account must be subclassed as one of the following types:</p>
76
+
77
+ <pre class="code"><span class='TYPE constant id'>TYPE</span> <span class='bitor op'>|</span> <span class='NORMAL constant id'>NORMAL</span> <span class='BALANCE constant id'>BALANCE</span> <span class='bitor op'>|</span> <span class='DESCRIPTION constant id'>DESCRIPTION</span>
78
+ <span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span><span class='minus op'>-</span>
79
+ <span class='Asset constant id'>Asset</span> <span class='bitor op'>|</span> <span class='Debit constant id'>Debit</span> <span class='bitor op'>|</span> <span class='Resources constant id'>Resources</span> <span class='owned identifier id'>owned</span> <span class='by identifier id'>by</span> <span class='the identifier id'>the</span> <span class='Business constant id'>Business</span> <span class='Entity constant id'>Entity</span>
80
+ <span class='Liability constant id'>Liability</span> <span class='bitor op'>|</span> <span class='Credit constant id'>Credit</span> <span class='bitor op'>|</span> <span class='Debts constant id'>Debts</span> <span class='owed identifier id'>owed</span> <span class='to identifier id'>to</span> <span class='outsiders identifier id'>outsiders</span>
81
+ <span class='Equity constant id'>Equity</span> <span class='bitor op'>|</span> <span class='Credit constant id'>Credit</span> <span class='bitor op'>|</span> <span class='Owners constant id'>Owners</span> <span class='rights identifier id'>rights</span> <span class='to identifier id'>to</span> <span class='the identifier id'>the</span> <span class='Assets constant id'>Assets</span>
82
+ <span class='Revenue constant id'>Revenue</span> <span class='bitor op'>|</span> <span class='Credit constant id'>Credit</span> <span class='bitor op'>|</span> <span class='Increases constant id'>Increases</span> <span class='in in kw'>in</span> <span class='owners identifier id'>owners</span> <span class='equity identifier id'>equity</span>
83
+ <span class='Expense constant id'>Expense</span> <span class='bitor op'>|</span> <span class='Debit constant id'>Debit</span> <span class='bitor op'>|</span> <span class='Assets constant id'>Assets</span> <span class='or or kw'>or</span> <span class='services identifier id'>services</span> <span class='consumed identifier id'>consumed</span> <span class='in in kw'>in</span> <span class='the identifier id'>the</span> <span class='generation identifier id'>generation</span> <span class='of identifier id'>of</span> <span class='revenue identifier id'>revenue</span>
84
+ </pre>
85
+
86
+ <p>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:</p>
87
+
88
+ <pre class="code"><span class='Equity constant id'>Equity</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Drawing&quot;</span><span class='comma token'>,</span> <span class='contra identifier id'>contra</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='true true kw'>true</span><span class='rparen token'>)</span>
89
+ </pre>
90
+
91
+ <p>At all times the balance of all accounts should conform to the <a href="http://en.wikipedia.org/wiki/Accounting_equation">Accounting
92
+ Equation</a></p>
93
+
94
+ <pre class="code"><span class='Assets constant id'>Assets</span> <span class='assign token'>=</span> <span class='Liabilties constant id'>Liabilties</span> <span class='plus op'>+</span> <span class='Owner constant id'>Owner</span><span class='string val'>'s Equity
95
+ </span></pre>
96
+
97
+ <p>Every account object has a <code>has_many</code> association of credit and debit transactions, which means that each account object also acts as its own <a href="http://en.wikipedia.org/wiki/General_ledger">Ledger</a>, and exposes a method to calculate the balance of the account.</p>
98
+
99
+ <p>See the <span class='object_link'><a href="Account.html" title="Account (class)">Account</a></span> and <span class='object_link'><a href="Transaction.html" title="Transaction (class)">Transaction</a></span> classes for more information.</p>
100
+
101
+ <h1>Examples</h1>
102
+
103
+ <h2>Recording a Transaction</h2>
104
+
105
+ <p>Let's assume we're accounting on an <a href="http://en.wikipedia.org/wiki/Accounting_methods">Accrual basis</a>. 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.</p>
106
+
107
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Liability constant id'>Liability</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Unearned Revenue&quot;</span><span class='rparen token'>)</span>
108
+ <span class='rshft op'>&gt;&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Cash&quot;</span><span class='rparen token'>)</span>
109
+ </pre>
110
+
111
+ <p>We'd then record the following transaction.</p>
112
+
113
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Transaction constant id'>Transaction</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:description</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Order placed for widgets&quot;</span><span class='comma token'>,</span>
114
+ <span class='symbol val'>:credit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Liability constant id'>Liability</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Unearned Revenue&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
115
+ <span class='symbol val'>:debit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Cash&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
116
+ <span class='symbol val'>:amount</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='integer val'>1000</span><span class='rparen token'>)</span>
117
+ </pre>
118
+
119
+ <h2>Associating Documents</h2>
120
+
121
+ <p>Although Plutus does not provide a mechanism for generating invoices or orders, it is possible to associate any such commercial document with a given transaction.</p>
122
+
123
+ <p>Suppose we pull up our latest invoice in order to generate a transaction for plutus (we'll assume you already have an Invoice model):</p>
124
+
125
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='invoice identifier id'>invoice</span> <span class='assign token'>=</span> <span class='Invoice constant id'>Invoice</span><span class='dot token'>.</span><span class='last identifier id'>last</span>
126
+ </pre>
127
+
128
+ <p>We'll also assume that we have not yet received payment for the order, so we'll need an "Accounts Receivable" Asset:</p>
129
+
130
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Accounts Receivable&quot;</span><span class='rparen token'>)</span>
131
+ </pre>
132
+
133
+ <p>Next, we'll go ahead and create a transaction for this invoice:</p>
134
+
135
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Transaction constant id'>Transaction</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:description</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Order placed for widgets&quot;</span><span class='comma token'>,</span>
136
+ <span class='symbol val'>:credit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Liability constant id'>Liability</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Unearned Revenue&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
137
+ <span class='symbol val'>:debit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Accounts Receivable&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
138
+ <span class='symbol val'>:amount</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='invoice identifier id'>invoice</span><span class='dot token'>.</span><span class='amount identifier id'>amount</span><span class='comma token'>,</span>
139
+ <span class='symbol val'>:commercial_document</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='invoice identifier id'>invoice</span><span class='rparen token'>)</span>
140
+ </pre>
141
+
142
+ <p>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.)</p>
143
+
144
+ <h2>Checking the Balance of an Individual Account</h2>
145
+
146
+ <p>Each account can report on its own balance. This number should normally be positive. If the number is negative, you may have a problem.</p>
147
+
148
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='cash identifier id'>cash</span> <span class='assign token'>=</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Cash&quot;</span><span class='rparen token'>)</span>
149
+ <span class='rshft op'>&gt;&gt;</span> <span class='cash identifier id'>cash</span><span class='dot token'>.</span><span class='balance identifier id'>balance</span>
150
+ <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='comment val'>#&lt;BigDecimal:103259bb8,'0.2E4',4(12)&gt;</span>
151
+ </pre>
152
+
153
+ <h2>Checking the Balance of an Account Type</h2>
154
+
155
+ <p>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.</p>
156
+
157
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='balance identifier id'>balance</span>
158
+ <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='comment val'>#&lt;BigDecimal:103259bb8,'0.2E4',4(12)&gt; </span>
159
+ </pre>
160
+
161
+ <h2>Calculating the Trial Balance</h2>
162
+
163
+ <p>The <a href="http://en.wikipedia.org/wiki/Trial_balance">Trial Balance</a> 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.</p>
164
+
165
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Account constant id'>Account</span><span class='dot token'>.</span><span class='trial_balance identifier id'>trial_balance</span>
166
+ <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='comment val'>#&lt;BigDecimal:1031c0d28,'0.0',4(12)&gt;</span>
167
+ </pre>
168
+
169
+ <h2>Contra Accounts and Complex Transactions</h2>
170
+
171
+ <p>For complex transaction, you should always ensure that you are balancing your accounts via the <a href="http://en.wikipedia.org/wiki/Accounting_equation">Accounting Equation</a>.</p>
172
+
173
+ <pre class="code"><span class='Assets constant id'>Assets</span> <span class='assign token'>=</span> <span class='Liabilties constant id'>Liabilties</span> <span class='plus op'>+</span> <span class='Owner constant id'>Owner</span><span class='string val'>'s Equity
174
+ </span></pre>
175
+
176
+ <p>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 owners right's 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.</p>
177
+
178
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Equity constant id'>Equity</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Drawing&quot;</span><span class='comma token'>,</span> <span class='symbol val'>:contra</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='true true kw'>true</span><span class='rparen token'>)</span>
179
+ <span class='rshft op'>&gt;&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Cash&quot;</span><span class='rparen token'>)</span>
180
+ </pre>
181
+
182
+ <p>We would then create the following transaction:</p>
183
+
184
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Transaction constant id'>Transaction</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:description</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Owner withdrawing cash&quot;</span><span class='comma token'>,</span>
185
+ <span class='symbol val'>:credit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Cash&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
186
+ <span class='symbol val'>:debit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Equity constant id'>Equity</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Drawing&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
187
+ <span class='symbol val'>:amount</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='float val'>1000.00</span><span class='rparen token'>)</span>
188
+ </pre>
189
+
190
+ <p>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:</p>
191
+
192
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Equity constant id'>Equity</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Common Stock&quot;</span><span class='rparen token'>)</span>
193
+ <span class='rshft op'>&gt;&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:name</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Cash&quot;</span><span class='rparen token'>)</span>
194
+ </pre>
195
+
196
+ <p>And out transaction would be:</p>
197
+
198
+ <pre class="code"><span class='rshft op'>&gt;&gt;</span> <span class='Transaction constant id'>Transaction</span><span class='dot token'>.</span><span class='create identifier id'>create</span><span class='lparen token'>(</span><span class='symbol val'>:description</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='string val'>&quot;Owner investing cash&quot;</span><span class='comma token'>,</span>
199
+ <span class='symbol val'>:credit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Equity constant id'>Equity</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Common Stock&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
200
+ <span class='symbol val'>:debit_account</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='Asset constant id'>Asset</span><span class='dot token'>.</span><span class='find_by_name identifier id'>find_by_name</span><span class='lparen token'>(</span><span class='string val'>&quot;Cash&quot;</span><span class='rparen token'>)</span><span class='comma token'>,</span>
201
+ <span class='symbol val'>:amount</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='float val'>1000.00</span><span class='rparen token'>)</span>
202
+ </pre>
203
+
204
+ <p>In this case, we've increase our cash Asset, and simultaneously increased the other side of our accounting equation in
205
+ Equity, keeping everything balanced.</p>
206
+
207
+ <h1>Access &amp; Security</h1>
208
+
209
+ <p>The Engine provides controllers and views for viewing Accounts and Transactions via the <span class='object_link'><a href="AccountsController.html" title="AccountsController (class)">AccountsController</a></span> and <span class='object_link'><a href="TransactionsController.html" title="TransactionsController (class)">TransactionsController</a></span> classes. The controllers will render HTML, XML and JSON, and are compatible with <a href="http://api.rubyonrails.org/classes/ActiveResource/Base.html">ActiveResource</a></p>
210
+
211
+ <p>Routing is NOT supplied by the engine. You can add routes to your application in your config/routes.rb with something like the following</p>
212
+
213
+ <pre class="code"><span class='map identifier id'>map</span><span class='dot token'>.</span><span class='resources identifier id'>resources</span> <span class='symbol val'>:transactions</span><span class='comma token'>,</span> <span class='symbol val'>:only</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrack token'>[</span><span class='symbol val'>:index</span><span class='comma token'>,</span> <span class='symbol val'>:show</span><span class='rbrack token'>]</span><span class='comma token'>,</span> <span class='symbol val'>:conditions</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrace token'>{</span> <span class='symbol val'>:method</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='symbol val'>:get</span> <span class='rbrace token'>}</span>
214
+ <span class='map identifier id'>map</span><span class='dot token'>.</span><span class='resources identifier id'>resources</span> <span class='symbol val'>:accounts</span><span class='comma token'>,</span> <span class='symbol val'>:only</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrack token'>[</span><span class='symbol val'>:index</span><span class='comma token'>,</span> <span class='symbol val'>:show</span><span class='rbrack token'>]</span><span class='comma token'>,</span> <span class='symbol val'>:conditions</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='lbrace token'>{</span> <span class='symbol val'>:method</span> <span class='assign token'>=</span><span class='gt op'>&gt;</span> <span class='symbol val'>:get</span> <span class='rbrace token'>}</span>
215
+ </pre>
216
+
217
+ <p><em>NOTE: If you enable routing, you should ensure that your ApplicationController enforces its own authentication and authorization, which this controller will inherit.</em></p>
218
+
219
+ <h1>Testing</h1>
220
+
221
+ <p><a href="http://rspec.info/">Rspec</a> tests are provided. Install both the rpsec and rspec-rails gems, and install this plugin
222
+ into a working rails application to run the tests.</p>
223
+
224
+ <h1>ToDo</h1>
225
+
226
+ <ul>
227
+ <li>Better views, including paging and ledgers</li>
228
+ <li>Namespacing to allow overriding engine classes</li>
229
+ <li>Reference for common accounting transactions</li>
230
+ </ul>
231
+
232
+
233
+ <h1>Reference</h1>
234
+
235
+ <p>For a complete reference on Accounting principles, we recommend the following textbook</p>
236
+
237
+ <p><a href="http://amzn.com/0324662963">http://amzn.com/0324662963</a></p>
238
+
239
+ <hr />
240
+
241
+ <p>Copyright (c) 2010 Michael Bulat</p></div></div>
242
+
243
+ <div id="footer">
244
+ Generated on Fri Dec 3 14:35:06 2010 by
245
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
246
+ 0.6.2 (ruby-1.8.7).
247
+ </div>
248
+
249
+ </body>
250
+ </html>
@@ -0,0 +1,202 @@
1
+ function createSourceLinks() {
2
+ $('.method_details_list .source_code').
3
+ before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
4
+ $('.toggleSource').toggle(function() {
5
+ $(this).parent().next().slideDown(100);
6
+ $(this).text("Hide source");
7
+ },
8
+ function() {
9
+ $(this).parent().next().slideUp(100);
10
+ $(this).text("View source");
11
+ });
12
+ }
13
+
14
+ function createDefineLinks() {
15
+ var tHeight = 0;
16
+ $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
17
+ $('.toggleDefines').toggle(function() {
18
+ tHeight = $(this).parent().prev().height();
19
+ $(this).prev().show();
20
+ $(this).parent().prev().height($(this).parent().height());
21
+ $(this).text("(less)");
22
+ },
23
+ function() {
24
+ $(this).prev().hide();
25
+ $(this).parent().prev().height(tHeight);
26
+ $(this).text("more...")
27
+ });
28
+ }
29
+
30
+ function createFullTreeLinks() {
31
+ var tHeight = 0;
32
+ $('.inheritanceTree').toggle(function() {
33
+ tHeight = $(this).parent().prev().height();
34
+ $(this).parent().toggleClass('showAll');
35
+ $(this).text("(hide)");
36
+ $(this).parent().prev().height($(this).parent().height());
37
+ },
38
+ function() {
39
+ $(this).parent().toggleClass('showAll');
40
+ $(this).parent().prev().height(tHeight);
41
+ $(this).text("show all")
42
+ });
43
+ }
44
+
45
+ function fixBoxInfoHeights() {
46
+ $('dl.box dd.r1, dl.box dd.r2').each(function() {
47
+ $(this).prev().height($(this).height());
48
+ });
49
+ }
50
+
51
+ function searchFrameLinks() {
52
+ $('#method_list_link').click(function() {
53
+ toggleSearchFrame(this, relpath + 'method_list.html');
54
+ });
55
+
56
+ $('#class_list_link').click(function() {
57
+ toggleSearchFrame(this, relpath + 'class_list.html');
58
+ });
59
+
60
+ $('#file_list_link').click(function() {
61
+ toggleSearchFrame(this, relpath + 'file_list.html');
62
+ });
63
+ }
64
+
65
+ function toggleSearchFrame(id, link) {
66
+ var frame = $('#search_frame');
67
+ $('#search a').removeClass('active').addClass('inactive');
68
+ if (frame.attr('src') == link && frame.css('display') != "none") {
69
+ frame.slideUp(100);
70
+ $('#search a').removeClass('active inactive');
71
+ }
72
+ else {
73
+ $(id).addClass('active').removeClass('inactive');
74
+ frame.attr('src', link).slideDown(100);
75
+ }
76
+ }
77
+
78
+ function linkSummaries() {
79
+ $('.summary_signature').click(function() {
80
+ document.location = $(this).find('a').attr('href');
81
+ });
82
+ }
83
+
84
+ function framesInit() {
85
+ if (window.top.frames.main) {
86
+ document.body.className = 'frames';
87
+ $('#menu .noframes a').attr('href', document.location);
88
+ $('html head title', window.parent.document).text($('html head title').text());
89
+ }
90
+ }
91
+
92
+ function keyboardShortcuts() {
93
+ if (window.top.frames.main) return;
94
+ $(document).keypress(function(evt) {
95
+ if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) return;
96
+ if (evt.originalTarget.nodeName == "INPUT" ||
97
+ evt.originalTarget.nodeName == "TEXTAREA") return;
98
+ switch (evt.charCode) {
99
+ case 67: case 99: $('#class_list_link').click(); break; // 'c'
100
+ case 77: case 109: $('#method_list_link').click(); break; // 'm'
101
+ case 70: case 102: $('#file_list_link').click(); break; // 'f'
102
+ }
103
+ });
104
+ }
105
+
106
+ function summaryToggle() {
107
+ $('.summary_toggle').click(function() {
108
+ localStorage.summaryCollapsed = $(this).text();
109
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
110
+ var next = $(this).parent().parent().next();
111
+ if (next.hasClass('compact')) {
112
+ next.toggle();
113
+ next.next().toggle();
114
+ }
115
+ else if (next.hasClass('summary')) {
116
+ var list = $('<ul class="summary compact" />');
117
+ list.html(next.html());
118
+ list.find('.summary_desc, .note').remove();
119
+ list.find('a').each(function() {
120
+ $(this).html($(this).find('strong').html());
121
+ $(this).parent().html($(this)[0].outerHTML);
122
+ });
123
+ next.before(list);
124
+ next.toggle();
125
+ }
126
+ return false;
127
+ });
128
+ if (localStorage) {
129
+ if (localStorage.summaryCollapsed == "collapse") $('.summary_toggle').click();
130
+ else localStorage.summaryCollapsed = "expand";
131
+ }
132
+ }
133
+
134
+ function fixOutsideWorldLinks() {
135
+ $('a').each(function() {
136
+ if (window.location.host != this.host) this.target = '_parent';
137
+ });
138
+ }
139
+
140
+ function generateTOC() {
141
+ if ($('#filecontents').length == 0) return;
142
+ var _toc = $('<ol class="top"></ol>');
143
+ var show = false;
144
+ var toc = _toc;
145
+ var counter = 0;
146
+ var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
147
+ if ($('#filecontents h1').length > 1) tags.unshift('h1');
148
+ for (i in tags) { tags[i] = '#filecontents ' + tags[i] }
149
+ var lastTag = parseInt(tags[0][1]);
150
+ $(tags.join(', ')).each(function() {
151
+ if (this.id == "filecontents") return;
152
+ show = true;
153
+ var thisTag = parseInt(this.tagName[1]);
154
+ if (this.id.length == 0) {
155
+ var proposedId = $(this).text().replace(/[^a-z0-9:\.()=-]/ig, '_');
156
+ if ($('#' + proposedId).length > 0) proposedId += counter++;
157
+ this.id = proposedId;
158
+ }
159
+ if (thisTag > lastTag) {
160
+ for (var i = 0; i < thisTag - lastTag; i++) {
161
+ var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
162
+ }
163
+ }
164
+ if (thisTag < lastTag) {
165
+ for (var i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
166
+ }
167
+ toc.append('<li><a href="#' + this.id + '">' + $(this).text() + '</a></li>');
168
+ lastTag = thisTag;
169
+ });
170
+ if (!show) return;
171
+ html = '<div id="toc"><p class="title"><a class="hide_toc" href="#"><strong>Table of Contents</strong></a> <small>(<a href="#" class="float_toc">left</a>)</small></p></div>';
172
+ $('#content').prepend(html);
173
+ $('#toc').append(_toc);
174
+ $('#toc .hide_toc').toggle(function() {
175
+ $('#toc .top').slideUp('fast');
176
+ $('#toc').toggleClass('hidden');
177
+ $('#toc .title small').toggle();
178
+ }, function() {
179
+ $('#toc .top').slideDown('fast');
180
+ $('#toc').toggleClass('hidden');
181
+ $('#toc .title small').toggle();
182
+ });
183
+ $('#toc .float_toc').toggle(function() {
184
+ $(this).text('float');
185
+ $('#toc').toggleClass('nofloat');
186
+ }, function() {
187
+ $(this).text('left')
188
+ $('#toc').toggleClass('nofloat');
189
+ });
190
+ }
191
+
192
+ $(framesInit);
193
+ $(createSourceLinks);
194
+ $(createDefineLinks);
195
+ $(createFullTreeLinks);
196
+ $(fixBoxInfoHeights);
197
+ $(searchFrameLinks);
198
+ $(linkSummaries);
199
+ $(keyboardShortcuts);
200
+ $(summaryToggle);
201
+ $(fixOutsideWorldLinks);
202
+ $(generateTOC);