-
Notifications
You must be signed in to change notification settings - Fork 4
Basic Scenario
Mike Herrera edited this page May 31, 2015
·
5 revisions
The purpose of this first scenario is to learn how to:
- Create accounts
- Add entries to those accounts
- 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: 13Grandpa 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"