Class: Skr::GlAccount

Inherits:
Model
  • Object
show all
Defined in:
lib/skr/models/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/models/gl_account.rb', line 25


Class Method Details

.default_for(lookup) ⇒ GlAccount

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

Raises:

  • (RuntimeError)


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

def self.default_for( lookup )
    number = Skr.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



55
56
57
# File 'lib/skr/models/gl_account.rb', line 55

def 
    number + '%'
end

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



60
61
62
# File 'lib/skr/models/gl_account.rb', line 60

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

#default_numberString



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

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

#number_for_location(location) ⇒ String



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

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

#trial_balanceBigDecimal



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

def trial_balance
    balance_for( GlPeriod.current )
end