debitcredit 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +152 -0
  3. data/lib/debitcredit/version.rb +1 -1
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cdda8ead625a293df8638761fa79a311cc68b02
4
- data.tar.gz: 2f8d0b663c862ce70ef74bd8b8257be63f8ae006
3
+ metadata.gz: 2ddfbe9149c881d0409f7b3fa09807124b95f792
4
+ data.tar.gz: c56cf08f5ff9df370f6f7823bea30fa5ff1cebdc
5
5
  SHA512:
6
- metadata.gz: 5a26e809d2ea8b7792b1ce45e332fde267440a4e63a833da1ae527932642760ba1d4dbb746076bebd14f389e97b9fbe51a5c443e457fdc93a6e5747e6dc7a34d
7
- data.tar.gz: 5873e917d758255e97bbbe52e86e8dbea7c7154e1a0b4806dd25dfc8e6781889e694d8ab00eaf2930e8bf639716dad2036e37de19afee5ffe2a8e049f20116d0
6
+ metadata.gz: 0e546eb72ee89de8ffb0af9fedb64af323d083b856bcf0c96ae86202bfd41fa0763a3459df7d88c2206aaf41098a508ef1a19867f77a57f42634330a0458494d
7
+ data.tar.gz: 0e254ee5fd412b4173abdd0a2604bd60fb39e0b3a66c3ee8e6650a17e56be1962eb5b2f4f0703fdb3e400418c0580221b5e48b482a8d24200954f3ac130c8b7a
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # Debitcredit
2
+
3
+ [![Build Status](https://travis-ci.org/vitaly/debitcredit.png)](https://travis-ci.org/vitaly/debitcredit)
4
+ [![Code Climate](https://codeclimate.com/github/vitaly/debitcredit.png)](https://codeclimate.com/github/vitaly/debitcredit)
5
+
6
+ Double Entry Accounting for Rails Applications
7
+
8
+ ## Account Types, Debits and Credits
9
+
10
+ <http://en.wikipedia.org/wiki/Debits_and_credits>
11
+
12
+ In Double Entry Accounting there are 5 account types: Asset, Liability, Income,
13
+ Expense and Equity defined as follows:
14
+
15
+ **Asset** is a resource controlled by the entity as a result of past events and
16
+ from which future economic benefits are expected to flow to the entity
17
+
18
+ **Liability** is defined as an obligation of an entity arising from past
19
+ transactions or events, the settlement of which may result in the transfer or
20
+ use of assets, provision of services or other yielding of economic benefits in
21
+ the future.
22
+
23
+ **Income** is increases in economic benefits during the accounting period in
24
+ the form of inflows or enhancements of assets or decreases of liabilities that
25
+ result in increases in equity, other than those relating to contributions from
26
+ equity participants.
27
+
28
+ **Expense** is a decrease in economic benefits during the accounting period in
29
+ the form of outflows or depletions of assets or incurrences of liabilities that
30
+ result in decreases in equity, other than those relating to distributions to
31
+ equity participants.
32
+
33
+ **Equity** consists of the net assets of an entity. Net assets is the
34
+ difference between the total assets of the entity and all its liabilities.
35
+
36
+
37
+ In each transaction, sources are credited and destinations are debited.
38
+
39
+ I repeat: credit is the **source** and debit is the **destination**.
40
+
41
+ debit and credit affect balance of an account differently depending on the
42
+ account type.
43
+
44
+ For Asset and Expense accounts, Debit increases the balance, and credit
45
+ decreases it. For the rest of the accounts it is the opposite. i.e. debit
46
+ decreases and credit increases the balance.
47
+
48
+ ## Accounting Equation
49
+
50
+ At any given point accounts should satisfy the following equation:
51
+
52
+ Assets + Expenses = Liabilities + Equity + Income
53
+
54
+ You can verify it with `Account.balanced?`.
55
+
56
+ Debitcredit takes care to keep the system balanced at all times, if you get an
57
+ unbalanced state, its a bug, please report immediately!
58
+
59
+ ## Accounts
60
+
61
+ The 5 types of accounts are represented by `Debitcredit::AssetAccount`,
62
+ `Debitcredit::LiabilityAccount`, `Debitcredit::IncomeAccount`, `Debitcredit::ExpenseAccount` and `Debitcredit::EquityAccount`
63
+
64
+ You can create standalone accounts:
65
+
66
+ Debitcredit::AssetAccount.create name: 'asset'
67
+ puts Debitcredit::Account[:asset].name
68
+
69
+ Or you can have a reference for the account:
70
+
71
+ Debitcredit::AssetAccount.create name: 'asset', reference: User.first
72
+
73
+ Or
74
+
75
+ class User
76
+ has_many :accounts, as: :reference, class_name: 'Debitcredit::Account'
77
+ ...
78
+ end
79
+
80
+ User.first.accounts.asset.create name: 'bank'
81
+ puts User.first.accounts[:bank].name
82
+
83
+ Or better yet:
84
+
85
+ class User
86
+ include Debitcredit::Extension
87
+
88
+ has_accounts
89
+ has_transactions
90
+ end
91
+
92
+ By default accounts are prevented from having a negative balance, but you can
93
+ pass `overdraft_enabled: false` to allow it:
94
+
95
+ Debitcredit::AssetAccount.create ..., overdraft_enabled: true
96
+
97
+ You can pass a block to `has_accounts` and to define referenced accounts:
98
+
99
+ class User
100
+ include Debitcredit::Extension
101
+
102
+ has_accounts do
103
+ income :salary
104
+ expense :rent
105
+ asset :checking, true # allow negative balance
106
+ end
107
+ end
108
+
109
+ User.first.accounts.salary # will be created on first use
110
+
111
+ ## Transactions
112
+
113
+ You can prepare transactions using DSL:
114
+
115
+ t = Transaction.prepare(description: 'rent payment') do
116
+ debit expense_account, 100, "you can also provide a comment"
117
+ credit bank_account, 50
118
+ credit creditcard, 50
119
+ end
120
+ t.save!
121
+
122
+ Sum of the debits must be equal to the sum of the credits. Amounts can not be
123
+ negative.
124
+
125
+ You can create transactions with a reference. For this case, and in case that
126
+ reference has 'accounts' association, you can use account names instead of objects:
127
+
128
+ t = user1.transactions.prepare(description: 'sale') do
129
+ debit :checking, 100 # will use user1.accounts[:checking]
130
+ credit user2.accounts[:checking], 100
131
+ end
132
+
133
+ You can prepare an inverse transaction. For example if you want to rollback an
134
+ existing transaction:
135
+
136
+ rollback = existing.inverse(kind: 'refund', description: 'item is out of stock')
137
+ rollback.save!
138
+
139
+ > Note: by inverse transactions are allowed to take accounts into overdraft. if
140
+ > this is undesirable, pass `enable_overdraft` to the `inverse` call.
141
+
142
+ ## Contributing
143
+
144
+ 1. Fork it
145
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
146
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
147
+ 4. Push to the branch (`git push origin my-new-feature`)
148
+ 5. Create new Pull Request
149
+
150
+ # License
151
+
152
+ This project rocks and uses MIT-LICENSE.
@@ -1,3 +1,3 @@
1
1
  module Debitcredit
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debitcredit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Kushner
@@ -211,6 +211,7 @@ files:
211
211
  - lib/tasks/debitcredit_tasks.rake
212
212
  - MIT-LICENSE
213
213
  - Rakefile
214
+ - README.md
214
215
  homepage: http://github.com/astrails/debitcredit
215
216
  licenses: []
216
217
  metadata: {}