Skip to content
Mike Herrera edited this page May 31, 2015 · 5 revisions

Track loan payments back to Grandpa.

The purpose of this first scenario is to learn how to:

  1. Create accounts
  2. Add entries to those accounts
  3. Get an account's balance

We've decided to keep things very simple and only create a few accounts:

  • 'Cash' an asset account.
  • 'Grandpa Loan' a liability account.
  • 'Spending' an expense account
DoubleDouble::Asset.create!     name:'Cash',         number: 11
DoubleDouble::Liability.create! name:'Grandpa Loan', number: 12
DoubleDouble::Expense.create!   name:'Spending',     number: 13

Grandpa was kind enough to loan us $800 USD in cash for college textbooks. To enter this we will require a entry which will affect both 'Cash' and 'Grandpa Loan'

DoubleDouble::Entry.create!(
  description: 
    'We received a loan from Grandpa',
  debits:[
    {account: 'Cash', amount: '$800'}],
  credits:[
    {account: 'Grandpa Loan', amount: '$800'}])

We buy our college textbooks.

DoubleDouble::Entry.create!(
  description: 
    'Purchase textbooks from bookstore',
  debits:[
    {account: 'Spending', amount: '$480'}],
  credits:[
    {account: 'Cash', amount: '$480'}])

What's our cash balance, now?

DoubleDouble::Account.named('Cash').balance.to_s           # => "320.00"

We decided that we wanted to return $320 of the loan.

DoubleDouble::Entry.create!(
  description: 
    'Paid back $320 to Grandpa',
  debits:[
    {account: 'Grandpa Loan', amount: '$320'}],
  credits:[
    {account: 'Cash', amount: '$320'}])

How much do we still owe Grandpa, now?

DoubleDouble::Account.named('Grandpa Loan').balance.to_s   # => "480.00"

How much did we spend?

DoubleDouble::Account.named('Spending').balance.to_s       # => "480.00"

How much cash is remaining?

DoubleDouble::Account.named('Cash').balance.to_s           # => "0.00"

Clone this wiki locally