Class: LedgerCompanyAccount

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/ledger_company_account.rb

Overview

== Schema Information

Table name: ledger_company_accounts
Database name: primary

id :integer not null, primary key
name :string(255)
number :string
tax_status :boolean default(TRUE), not null
created_at :datetime
updated_at :datetime
company_id :integer not null
ledger_detail_account_id :integer not null

Indexes

company_id_lda_id (company_id,ledger_detail_account_id)
index_ledger_company_accounts_on_ledger_detail_account_id (ledger_detail_account_id)
name_company_id (name,company_id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has one collapse

Has many collapse

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#company_idObject (readonly)



31
# File 'app/models/ledger_company_account.rb', line 31

validates :ledger_detail_account_id, :company_id, :name, presence: true

#ledger_detail_account_idObject (readonly)



31
# File 'app/models/ledger_company_account.rb', line 31

validates :ledger_detail_account_id, :company_id, :name, presence: true

#nameObject (readonly)



31
# File 'app/models/ledger_company_account.rb', line 31

validates :ledger_detail_account_id, :company_id, :name, presence: true

Class Method Details

.for_company_and_account(company_id, account_number) ⇒ LedgerCompanyAccount?

Look up a LedgerCompanyAccount by (company_id, ledger-account-number). Used everywhere the GL-posting code
needs the per-company instance of a chart-of-accounts row.

Parameters:

  • company_id (Integer)
  • account_number (Integer, String)

Returns:



63
64
65
# File 'app/models/ledger_company_account.rb', line 63

def self.(company_id, )
  joins(:ledger_detail_account).where(['company_id = ? and ledger_accounts.number = ?', company_id, ]).first
end

.get_by_identifier(identifier) ⇒ LedgerCompanyAccount?

Inverse of #identifier — parse a "<co>.<acct>" string back
into the record.

Parameters:

  • identifier (String)

Returns:



72
73
74
75
76
77
# File 'app/models/ledger_company_account.rb', line 72

def self.get_by_identifier(identifier)
  attrs = identifier.split('.')
  return nil if attrs.length != 2

  LedgerCompanyAccount.joins(:company, :ledger_detail_account).where(['companies.number = ? and ledger_accounts.number = ?', attrs[0], attrs[1]]).first
end

.quick_list(conditions = nil) ⇒ ActiveRecord::Relation

Lightweight relation that selects only the columns needed to
build a dropdown — a synthetic acc_identifier string plus
ids — sorted by company then account number.

Parameters:

  • conditions (Hash, String, Array, nil) (defaults to: nil)

    optional where clause

Returns:

  • (ActiveRecord::Relation)


85
86
87
88
89
# File 'app/models/ledger_company_account.rb', line 85

def self.quick_list(conditions = nil)
  res = LedgerCompanyAccount.joins(:company, :ledger_detail_account).order('companies.number asc, ledger_accounts.number asc')
  res = res.where(conditions) unless conditions.nil?
  res.select("ledger_company_accounts.id, ledger_company_accounts.company_id, companies.number||'.'||ledger_accounts.number||' '||ledger_accounts.name as acc_identifier")
end

.select_options(conditions = nil) ⇒ Array<Array(String, Integer)>

[label, id] pairs from quick_list for select_tag helpers.

Parameters:

  • conditions (Hash, String, Array, nil) (defaults to: nil)

Returns:

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


94
95
96
# File 'app/models/ledger_company_account.rb', line 94

def self.select_options(conditions = nil)
  quick_list(conditions).map { |lca| [lca.acc_identifier, lca.id] }
end

.select_options_for_company(company_id) ⇒ Array<Array(String, Integer)>

select_options scoped to a single Company. Returns an empty
array when company_id is nil so the JE form can swap rows
cleanly when the user hasn't picked a company yet.

Parameters:

  • company_id (Integer, nil)

Returns:

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


104
105
106
107
108
# File 'app/models/ledger_company_account.rb', line 104

def self.select_options_for_company(company_id)
  return [] if company_id.nil?

  select_options(company_id: company_id)
end

Instance Method Details

#bank_accountBankAccount



27
# File 'app/models/ledger_company_account.rb', line 27

has_one :bank_account

#companyCompany

Returns:

See Also:



26
# File 'app/models/ledger_company_account.rb', line 26

belongs_to :company, optional: true

#company_and_accountString

"<company short name> <account name>" for display rows.

Returns:

  • (String)


46
47
48
# File 'app/models/ledger_company_account.rb', line 46

def 
  "#{company.short_name} #{name}"
end

#identifierString

"<company-number>.<account-number>" composite key — what
accountants type into spreadsheets to refer to a specific
company-account pair (e.g. "01.1100").

Returns:

  • (String)


40
41
42
# File 'app/models/ledger_company_account.rb', line 40

def identifier
  "#{company.number}.#{.number}"
end

#identifier_and_nameString

{identifier} joined with #company_and_account.

Returns:

  • (String)


52
53
54
# File 'app/models/ledger_company_account.rb', line 52

def identifier_and_name
  "#{identifier} #{}"
end

#invoicesActiveRecord::Relation<Invoice>

Returns:

  • (ActiveRecord::Relation<Invoice>)

See Also:



29
# File 'app/models/ledger_company_account.rb', line 29

has_many :invoices

#ledger_detail_accountLedgerDetailAccount



25
# File 'app/models/ledger_company_account.rb', line 25

belongs_to :ledger_detail_account, optional: true

#ledger_entriesActiveRecord::Relation<LedgerEntry>

Returns:

See Also:



28
# File 'app/models/ledger_company_account.rb', line 28

has_many :ledger_entries, inverse_of: :ledger_company_account

#requires_business_unit?Object

Alias for Ledger_detail_account#requires_business_unit?

Returns:

  • (Object)

    Ledger_detail_account#requires_business_unit?

See Also:



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

delegate :requires_business_unit?, to: :ledger_detail_account