Class: Expense

Inherits:
Account
  • Object
show all
Defined in:
app/models/expense.rb

Overview

The Expense class is an account type used to represents assets or services consumed in the generation of revenue.

Normal Balance

The normal balance on Expense accounts is a Debit.

See Also:

Author:

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Account

trial_balance

Class Method Details

+ (BigDecimal) balance

This class method is used to return the balance of all Expense accounts.

Contra accounts are automatically subtracted from the balance.

Examples:

>> Expense.balance
=> #<BigDecimal:1030fcc98,'0.82875E5',8(20)>

Returns:

  • (BigDecimal)

    The decimal value balance



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/expense.rb', line 69

def self.balance
  accounts_balance = BigDecimal.new('0') 
  accounts = self.find(:all)
  accounts.each do |expense|
    unless expense.contra
      accounts_balance += expense.balance
    else
      accounts_balance -= expense.balance
    end
  end
  accounts_balance
end

Instance Method Details

- (BigDecimal) balance

The balance of the account.

Expenses have normal debit balances, so the credits are subtracted from the debits unless this is a contra account, in which debits are subtracted from credits

Examples:

>> expense.balance
=> #<BigDecimal:103259bb8,'0.2E4',4(12)> 

Returns:

  • (BigDecimal)

    The decimal value balance



51
52
53
54
55
56
57
# File 'app/models/expense.rb', line 51

def balance
  unless contra
    debits_balance - credits_balance
  else
    credits_balance - debits_balance
  end
end

- (BigDecimal) credits_balance

The credit balance for the account.

Examples:

>> expense.credits_balance
=> #<BigDecimal:103259bb8,'0.1E4',4(12)> 

Returns:

  • (BigDecimal)

    The decimal value credit balance



18
19
20
21
22
23
24
# File 'app/models/expense.rb', line 18

def credits_balance
  credits_balance = BigDecimal.new('0')
  credit_transactions.each do |credit_transaction|
    credits_balance = credits_balance + credit_transaction.amount
  end
  return credits_balance
end

- (BigDecimal) debits_balance

The debit balance for the account.

Examples:

>> expense.debits_balance
=> #<BigDecimal:103259bb8,'0.3E4',4(12)> 

Returns:

  • (BigDecimal)

    The decimal value credit balance



33
34
35
36
37
38
39
# File 'app/models/expense.rb', line 33

def debits_balance
  debits_balance = BigDecimal.new('0')
  debit_transactions.each do |debit_transaction|
    debits_balance = debits_balance + debit_transaction.amount
  end
  return debits_balance
end