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

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

#publish_event

Instance Attribute Details

#company_idObject (readonly)



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

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

#ledger_detail_account_idObject (readonly)



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

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

#nameObject (readonly)



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

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

Class Method Details

.for_company_and_account(company_id, account_number) ⇒ Object



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

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

.get_by_identifier(identifier) ⇒ Object



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

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) ⇒ Object



58
59
60
61
62
# File 'app/models/ledger_company_account.rb', line 58

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) ⇒ Object



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

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

.select_options_for_company(company_id) ⇒ Object



68
69
70
71
72
# File 'app/models/ledger_company_account.rb', line 68

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



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

has_one :bank_account

#companyCompany

Returns:

See Also:



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

belongs_to :company, optional: true

#company_and_accountObject



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

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

#identifierObject



35
36
37
# File 'app/models/ledger_company_account.rb', line 35

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

#identifier_and_nameObject



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

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

#invoicesActiveRecord::Relation<Invoice>

Returns:

  • (ActiveRecord::Relation<Invoice>)

See Also:



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

has_many :invoices

#ledger_detail_accountLedgerDetailAccount



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

belongs_to :ledger_detail_account, optional: true

#ledger_entriesActiveRecord::Relation<LedgerEntry>

Returns:

See Also:



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

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:



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

delegate :requires_business_unit?, to: :ledger_detail_account