0.0
No commit activity in last 3 years
No release in over 3 years
Double-entry accounting issues credits and debits, calculates balances, allows for summary accounts and more.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.0.0
 Project Readme

DoubleBooked

Flexible double-entry accounting engine for Rails apps using ActiveRecord

Overview

The core of double_booked are Accounts and Transactions. The concept of an account is probably familiar to most developers-- think of your checking or savings accounts. A transaction links two accounts together, posting a debit to one, and a credit to another. The credits and debits must be equal in amount. That's it!

The system also includes invoices, payments, and the ability to mark any eligible transaction as payment for an invoice, as long as the buyer's account is involved in the transaction.

Installation

In your Gemfile, put:

source :rubygems
gem 'double_booked'

Then on the command line:

bundle install
rails g double_booked:migrations
rake db:migrate

Usage

To use double_booked, you'll need to create a model that is a subclass of DetailAccount. A DetailAccount represents an account that is directly debited from or credited to, for example a bank account.

Let's say your users have a TokenAccount record, and are able to award each other tokens from their accounts. You'd set up the models as such:

class User < ActiveRecord::Base
  has_one :token_account, :as => :owner
end

class TokenAccount < DetailAccount
  owned_by :user
end

You may want to set up a special user to issue tokens:

# Setup the token issuer and account (the "bank")
token_issuer = User.create :email => 'token_issuer@myapp.com', ...
token_bank = token_issuer.create_token_account

token_bank.current_balance
# => 0

# Issue 10 tokens to the user Jack
jack = User.find_by_name "Jack"
token_bank.transfer(10).to jack.token_account

jack.token_account.current_balance
# => 10

token_bank.current_balance
# => -10

# Now have Jack give 2 tokens to Bob
bob = User.find_by_name("Bob")

bob.token_account.current_balance
# => 0

jack.token_account.transfer(10).to bob.token_account

jack.token_account.current_balance
# => 8

bob.token_account.current_balance
# => 2

At any time, the total tokens in all accounts should sum up to zero.