Class: LedgerAccount

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable, Models::Lineage
Defined in:
app/models/ledger_account.rb

Overview

== Schema Information

Table name: ledger_accounts
Database name: primary

id :integer not null, primary key
classification :string(255)
closed :boolean default(FALSE), not null
description :text
name :string(50) not null
number :integer not null
type :string(255) not null
visible :boolean default(TRUE), not null
created_at :datetime
updated_at :datetime
parent_id :integer

Indexes

idx_id_type (id,type)
idx_la_parent_id (parent_id)
index_ledger_accounts_on_number (number)

Direct Known Subclasses

LedgerDetailAccount, LedgerSummaryAccount

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater

Methods included from Models::Lineage

#ancestors, #ancestors_ids, #children_and_roots, #descendants, #descendants_ids, #ensure_non_recursive_lineage, #family_members, #generate_full_name, #generate_full_name_array, #lineage, #lineage_array, #lineage_simple, #root, #root_id, #self_ancestors_and_descendants, #self_ancestors_and_descendants_ids, #self_and_ancestors, #self_and_ancestors_ids, #self_and_children, #self_and_descendants, #self_and_descendants_ids, #self_and_siblings, #self_and_siblings_ids, #siblings, #siblings_ids

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#nameString

Returns Account name.

Returns:

  • (String)

    Account name.



37
# File 'app/models/ledger_account.rb', line 37

validates :number, :name, :type, presence: true

#numberInteger

Returns Account number.

Returns:

  • (Integer)

    Account number.

Validations:



37
# File 'app/models/ledger_account.rb', line 37

validates :number, :name, :type, presence: true

#typeString

Returns STI subclass name.

Returns:

  • (String)

    STI subclass name.



37
# File 'app/models/ledger_account.rb', line 37

validates :number, :name, :type, presence: true

Class Method Details

.availableActiveRecord::Relation<LedgerAccount>

A relation of LedgerAccounts that are available. Active Record Scope

Returns:

See Also:



47
# File 'app/models/ledger_account.rb', line 47

scope :available, -> { where(visible: true, closed: false) }

.company_account_arrayHash{Integer=>Hash}

Pre-computed lookup of LedgerCompanyAccount ids per top-level
account, indexed by account id then by Company number (and a
convenience [USA, CAN] combo entry). Backs report dropdowns
that need to filter entries to the right company subset
without round-tripping the DB per row.

Returns:

  • (Hash{Integer=>Hash})


99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/ledger_account.rb', line 99

def self.
  accounts = []
  LedgerAccount.find_each do ||
    accounts[.id] = {}
    accounts[.id][Company::USA] = .(Company::USA)
    accounts[.id][Company::CAN] = .(Company::CAN)
    accounts[.id][Company::NLD] = .(Company::NLD)
    accounts[.id][[Company::USA, Company::CAN]] = accounts[.id][Company::USA] + accounts[.id][Company::CAN]
  end
  accounts
end

.select_accountArray<Array(String, Integer)>

[label, account_number] pairs — same as select_options but
keyed by account number, used when reports filter on the
human-known account number rather than the surrogate id.

Returns:

  • (Array<Array(String, Integer)>)


66
67
68
# File 'app/models/ledger_account.rb', line 66

def self.
  LedgerAccount.order(:number).pluck(Arel.sql("concat(number, ' ', name)"), :number)
end

.select_bank_balance_accountArray<Array(String, Integer)>

[label, account_number] pairs limited to the bank-related
accounts (cash, AR, money-market) used by the
BankBalanceStatement workflow.

Returns:

  • (Array<Array(String, Integer)>)


74
75
76
# File 'app/models/ledger_account.rb', line 74

def self.
  LedgerAccount.where(number: [1122, 1123, 1130, 1135, 1140, 1141]).order(:number).pluck(Arel.sql("concat(number, ' ', name)"), :number)
end

.select_optionsArray<Array(String, Integer)>

[label, id] pairs for any place that needs to pick an account
by record id (mostly admin form fields).

Returns:

  • (Array<Array(String, Integer)>)


58
59
60
# File 'app/models/ledger_account.rb', line 58

def self.select_options
  LedgerAccount.order(:number).pluck(Arel.sql("concat(number, ' ', name)"), :id)
end

.types_for_selectArray<Array(String, String)>

Detail vs. summary STI-class options for the new-account form.

Returns:

  • (Array<Array(String, String)>)


51
52
53
# File 'app/models/ledger_account.rb', line 51

def self.types_for_select
  [%w[Detail LedgerDetailAccount], %w[Summary LedgerSummaryAccount]]
end

Instance Method Details

#budgetsActiveRecord::Relation<LedgerBudget>

Returns:

  • (ActiveRecord::Relation<LedgerBudget>)


45
# File 'app/models/ledger_account.rb', line 45

has_many :budgets

#ledger_company_accountsActiveRecord::Relation<LedgerCompanyAccount>

Returns:



41
# File 'app/models/ledger_account.rb', line 41

has_many :ledger_company_accounts

#ledger_entriesActiveRecord::Relation<LedgerEntry>

Returns:



43
# File 'app/models/ledger_account.rb', line 43

has_many :ledger_entries, through: :ledger_company_accounts

#requires_business_unit?Boolean

Whether entries on this account require a BusinessUnit tag.
All P&L accounts (number ≥ 5000) carry one.

Returns:

  • (Boolean)


88
89
90
# File 'app/models/ledger_account.rb', line 88

def requires_business_unit?
  number >= 5000
end

#summary_nameString

"<number> <name>" label used in dropdowns and breadcrumb
strings.

Returns:

  • (String)


81
82
83
# File 'app/models/ledger_account.rb', line 81

def summary_name
  "#{number} #{name}"
end