Sha256: 46a8cdae3a006366ded90cfe34cb59b5f5cd94973cfd613d3371f652e1701f61

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

module Plutus
  # The Liability class is an account type used to represents debts owed to outsiders.
  #
  # === Normal Balance
  # The normal balance on Liability accounts is a *Credit*.
  #
  # @see http://en.wikipedia.org/wiki/Liability_(financial_accounting) Liability
  #
  # @author Michael Bulat
  class Liability < Account

    # The balance of the account.
    #
    # Liability accounts have normal credit balances, so the debits are subtracted from the credits
    # unless this is a contra account, in which credits are subtracted from debits
    #
    # @example
    #   >> liability.balance
    #   => #<BigDecimal:103259bb8,'0.2E4',4(12)>
    #
    # @return [BigDecimal] The decimal value balance
    def balance
      unless contra
        credits_balance - debits_balance
      else
        debits_balance - credits_balance
      end
    end

    # Balance of all Liability accounts
    #
    # @example
    #   >> Plutus::Liability.balance
    #   => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
    def self.balance
      accounts_balance = BigDecimal.new('0')
      accounts = self.all
      accounts.each do |liability|
        unless liability.contra
          accounts_balance += liability.balance
        else
          accounts_balance -= liability.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/liability.rb
plutus-0.10.1 app/models/plutus/liability.rb
plutus-0.10.0 app/models/plutus/liability.rb
plutus-0.9.0 app/models/plutus/liability.rb
plutus-0.8.1 app/models/plutus/liability.rb
plutus-0.8.0 app/models/plutus/liability.rb