Class: LedgerAccount
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LedgerAccount
- 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
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #name ⇒ Object readonly
- #number ⇒ Object readonly
- #type ⇒ Object readonly
Has many collapse
- #budgets ⇒ ActiveRecord::Relation<Budget>
- #ledger_company_accounts ⇒ ActiveRecord::Relation<LedgerCompanyAccount>
- #ledger_entries ⇒ ActiveRecord::Relation<LedgerEntry>
Class Method Summary collapse
-
.available ⇒ ActiveRecord::Relation<LedgerAccount>
A relation of LedgerAccounts that are available.
-
.company_account_array ⇒ Hash{Integer=>Hash}
Pre-computed lookup of
LedgerCompanyAccountids per top-level account, indexed by account id then by Company number (and a convenience[USA, CAN]combo entry). -
.select_account ⇒ Array<Array(String, Integer)>
[label, account_number]pairs — same as LedgerAccount.select_options but keyed by account number, used when reports filter on the human-known account number rather than the surrogate id. -
.select_bank_balance_account ⇒ Array<Array(String, Integer)>
[label, account_number]pairs limited to the bank-related accounts (cash, AR, money-market) used by the BankBalanceStatement workflow. -
.select_options ⇒ Array<Array(String, Integer)>
[label, id]pairs for any place that needs to pick an account by record id (mostly admin form fields). -
.types_for_select ⇒ Array<Array(String, String)>
Detail vs.
Instance Method Summary collapse
-
#requires_business_unit? ⇒ Boolean
Whether entries on this account require a BusinessUnit tag.
-
#summary_name ⇒ String
"<number> <name>"label used in dropdowns and breadcrumb strings.
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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#name ⇒ Object (readonly)
31 |
# File 'app/models/ledger_account.rb', line 31 validates :number, :name, :type, presence: true |
#number ⇒ Object (readonly)
31 |
# File 'app/models/ledger_account.rb', line 31 validates :number, :name, :type, presence: true |
#type ⇒ Object (readonly)
31 |
# File 'app/models/ledger_account.rb', line 31 validates :number, :name, :type, presence: true |
Class Method Details
.available ⇒ ActiveRecord::Relation<LedgerAccount>
A relation of LedgerAccounts that are available. Active Record Scope
38 |
# File 'app/models/ledger_account.rb', line 38 scope :available, -> { where(visible: true, closed: false) } |
.company_account_array ⇒ Hash{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.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/ledger_account.rb', line 90 def self.company_account_array accounts = [] LedgerAccount.find_each do |ledger_account| accounts[ledger_account.id] = {} accounts[ledger_account.id][Company::USA] = ledger_account.company_account_ids_for(Company::USA) accounts[ledger_account.id][Company::CAN] = ledger_account.company_account_ids_for(Company::CAN) accounts[ledger_account.id][Company::NLD] = ledger_account.company_account_ids_for(Company::NLD) accounts[ledger_account.id][[Company::USA, Company::CAN]] = accounts[ledger_account.id][Company::USA] + accounts[ledger_account.id][Company::CAN] end accounts end |
.select_account ⇒ Array<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.
57 58 59 |
# File 'app/models/ledger_account.rb', line 57 def self.select_account LedgerAccount.order(:number).pluck(Arel.sql("concat(number, ' ', name)"), :number) end |
.select_bank_balance_account ⇒ Array<Array(String, Integer)>
[label, account_number] pairs limited to the bank-related
accounts (cash, AR, money-market) used by the
BankBalanceStatement workflow.
65 66 67 |
# File 'app/models/ledger_account.rb', line 65 def self.select_bank_balance_account LedgerAccount.where(number: [1122, 1123, 1130, 1135, 1140, 1141]).order(:number).pluck(Arel.sql("concat(number, ' ', name)"), :number) end |
.select_options ⇒ Array<Array(String, Integer)>
[label, id] pairs for any place that needs to pick an account
by record id (mostly admin form fields).
49 50 51 |
# File 'app/models/ledger_account.rb', line 49 def self. LedgerAccount.order(:number).pluck(Arel.sql("concat(number, ' ', name)"), :id) end |
.types_for_select ⇒ Array<Array(String, String)>
Detail vs. summary STI-class options for the new-account form.
42 43 44 |
# File 'app/models/ledger_account.rb', line 42 def self.types_for_select [%w[Detail LedgerDetailAccount], %w[Summary LedgerSummaryAccount]] end |
Instance Method Details
#budgets ⇒ ActiveRecord::Relation<Budget>
36 |
# File 'app/models/ledger_account.rb', line 36 has_many :budgets |
#ledger_company_accounts ⇒ ActiveRecord::Relation<LedgerCompanyAccount>
34 |
# File 'app/models/ledger_account.rb', line 34 has_many :ledger_company_accounts |
#ledger_entries ⇒ ActiveRecord::Relation<LedgerEntry>
35 |
# File 'app/models/ledger_account.rb', line 35 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.
79 80 81 |
# File 'app/models/ledger_account.rb', line 79 def requires_business_unit? number >= 5000 end |
#summary_name ⇒ String
"<number> <name>" label used in dropdowns and breadcrumb
strings.
72 73 74 |
# File 'app/models/ledger_account.rb', line 72 def summary_name "#{number} #{name}" end |