Class: LedgerCompanyAccount
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
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
#creator, #updater
Delegated Instance Attributes
collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#company_id ⇒ Object
30
|
# File 'app/models/ledger_company_account.rb', line 30
validates :ledger_detail_account_id, :company_id, :name, presence: true
|
#ledger_detail_account_id ⇒ Object
30
|
# File 'app/models/ledger_company_account.rb', line 30
validates :ledger_detail_account_id, :company_id, :name, presence: true
|
#name ⇒ Object
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.for_company_and_account(company_id, account_number)
joins(:ledger_detail_account).where(['company_id = ? and ledger_accounts.number = ?', company_id, account_number]).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
26
|
# File 'app/models/ledger_company_account.rb', line 26
has_one :bank_account
|
25
|
# File 'app/models/ledger_company_account.rb', line 25
belongs_to :company, optional: true
|
#company_and_account ⇒ Object
39
40
41
|
# File 'app/models/ledger_company_account.rb', line 39
def company_and_account
"#{company.short_name} #{name}"
end
|
#identifier ⇒ Object
35
36
37
|
# File 'app/models/ledger_company_account.rb', line 35
def identifier
"#{company.number}.#{ledger_detail_account.number}"
end
|
#identifier_and_name ⇒ Object
43
44
45
|
# File 'app/models/ledger_company_account.rb', line 43
def identifier_and_name
"#{identifier} #{company_and_account}"
end
|
#invoices ⇒ ActiveRecord::Relation<Invoice>
28
|
# File 'app/models/ledger_company_account.rb', line 28
has_many :invoices
|
24
|
# File 'app/models/ledger_company_account.rb', line 24
belongs_to :ledger_detail_account, optional: true
|
#ledger_entries ⇒ ActiveRecord::Relation<LedgerEntry>
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?
33
|
# File 'app/models/ledger_company_account.rb', line 33
delegate :requires_business_unit?, to: :ledger_detail_account
|