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

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::EventPublishable

#publish_event

Class Method Details

.availableActiveRecord::Relation<LedgerAccount>

A relation of LedgerAccounts that are available. Active Record Scope

Returns:

See Also:



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

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

.company_account_arrayObject



63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/ledger_account.rb', line 63

def self.
  accounts = []
  LedgerAccount.all.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_accountObject



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

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

.select_bank_balance_accountObject



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

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

.select_optionsObject



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

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

.types_for_selectObject



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

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

Instance Method Details

#budgetsActiveRecord::Relation<Budget>

Returns:

  • (ActiveRecord::Relation<Budget>)

See Also:



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

has_many :budgets

#ledger_company_accountsActiveRecord::Relation<LedgerCompanyAccount>

Returns:

See Also:



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

has_many :ledger_company_accounts

#ledger_entriesActiveRecord::Relation<LedgerEntry>

Returns:

See Also:



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

has_many :ledger_entries, :through => :ledger_company_accounts

#requires_business_unit?Boolean

Returns:

  • (Boolean)


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

def requires_business_unit?
  number >= 5000
end

#summary_nameObject



55
56
57
# File 'app/models/ledger_account.rb', line 55

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