Sha256: e8c1135848e59b1da3c9a3f5bf5dbb5f412541b72d713b2a910a3a2d2cb316ff

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

module Plutus
  # 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 http://en.wikipedia.org/wiki/Expense Expenses
  #
  # @author Michael Bulat
  class Expense < Account

    # 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
    #
    # @example
    #   >> expense.balance
    #   => #<BigDecimal:103259bb8,'0.2E4',4(12)>
    #
    # @return [BigDecimal] The decimal value balance
    def balance
      unless contra
        debits_balance - credits_balance
      else
        credits_balance - debits_balance
      end
    end

    # This class method is used to return
    # the balance of all Expense accounts.
    #
    # Contra accounts are automatically subtracted from the balance.
    #
    # @example
    #   >> Plutus::Expense.balance
    #   => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
    #
    # @return [BigDecimal] The decimal value balance
    def self.balance
      accounts_balance = BigDecimal.new('0')
      accounts = self.all
      accounts.each do |expense|
        unless expense.contra
          accounts_balance += expense.balance
        else
          accounts_balance -= expense.balance
        end
      end
      accounts_balance
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
plutus-0.11.0 app/models/plutus/expense.rb
plutus-0.10.1 app/models/plutus/expense.rb
plutus-0.10.0 app/models/plutus/expense.rb
plutus-0.9.0 app/models/plutus/expense.rb
plutus-0.8.1 app/models/plutus/expense.rb
plutus-0.8.0 app/models/plutus/expense.rb