Class: Skr::GlAccount

Inherits:
Model
  • Object
show all
Defined in:
lib/skr/gl_account.rb

Overview

A GlAccount *(short for General Ledger Account)* is used to define each class of items for which money or the equivalent is spent or received.

Constant Summary collapse

DEFAULT_ACCOUNTS =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

A short description of the GL Account



# File 'lib/skr/gl_account.rb', line 15


Class Method Details

.default_for(lookup) ⇒ GlAccount

Returns the default account for the key from Core::Configuration.default_gl_accounts.

Returns:

  • (GlAccount)

    the default account for the key from Core::Configuration.default_gl_accounts

Raises:

  • (RuntimeError)


23
24
25
26
27
# File 'lib/skr/gl_account.rb', line 23

def self.default_for( lookup )
    number = Core.config.default_gl_accounts[ lookup ]
    raise RuntimeError.new("Unkown GL default account lookup code: {lookup}") unless number
    DEFAULT_ACCOUNTS[ lookup ] ||= GlAccount.find_by_number( number )
end

Instance Method Details

#account_maskString

Returns the account number suitable for querying all branches.

Returns:

  • (String)

    the account number suitable for querying all branches



45
46
47
# File 'lib/skr/gl_account.rb', line 45

def 
    number + '%'
end

#balance_for(period, mask = self.account_mask) ⇒ BigDecimal

Returns the balance for a given period.

Returns:

  • (BigDecimal)

    the balance for a given period



50
51
52
# File 'lib/skr/gl_account.rb', line 50

def balance_for( period, mask = self. )
    GlPosting.matching( period,  ).sum(:amount)
end

#default_numberString

Returns the account number combined with the default branch code.

Returns:

  • (String)

    the account number combined with the default branch code



35
36
37
# File 'lib/skr/gl_account.rb', line 35

def default_number
    self.number + Skr::Core.config.default_branch_code
end

#number_for_location(location) ⇒ String

Returns the account number combined with location branch code.

Returns:

  • (String)

    the account number combined with location branch code



30
31
32
# File 'lib/skr/gl_account.rb', line 30

def number_for_location( location )
    self.number + location.gl_branch_code
end

#trial_balanceBigDecimal

Returns The balance for the current period.

Returns:

  • (BigDecimal)

    The balance for the current period



40
41
42
# File 'lib/skr/gl_account.rb', line 40

def trial_balance
    balance_for( GlPeriod.current )
end