Class: LedgerCompanyAccount
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LedgerCompanyAccount
- 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
- #company_id ⇒ Object readonly
- #ledger_detail_account_id ⇒ Object readonly
- #name ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Has one collapse
Has many collapse
Delegated Instance Attributes collapse
-
#requires_business_unit? ⇒ Object
Alias for Ledger_detail_account#requires_business_unit?.
Class Method Summary collapse
-
.for_company_and_account(company_id, account_number) ⇒ LedgerCompanyAccount?
Look up a LedgerCompanyAccount by
(company_id, ledger-account-number). -
.get_by_identifier(identifier) ⇒ LedgerCompanyAccount?
Inverse of #identifier — parse a
"<co>.<acct>"string back into the record. -
.quick_list(conditions = nil) ⇒ ActiveRecord::Relation
Lightweight relation that selects only the columns needed to build a dropdown — a synthetic
acc_identifierstring plus ids — sorted by company then account number. -
.select_options(conditions = nil) ⇒ Array<Array(String, Integer)>
[label, id]pairs from LedgerCompanyAccount.quick_list forselect_taghelpers. -
.select_options_for_company(company_id) ⇒ Array<Array(String, Integer)>
LedgerCompanyAccount.select_options scoped to a single Company.
Instance Method Summary collapse
-
#company_and_account ⇒ String
"<company short name> <account name>"for display rows. -
#identifier ⇒ String
"<company-number>.<account-number>"composite key — what accountants type into spreadsheets to refer to a specific company-account pair (e.g."01.1100"). -
#identifier_and_name ⇒ String
{identifier}joined with #company_and_account.
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
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#company_id ⇒ Object (readonly)
31 |
# File 'app/models/ledger_company_account.rb', line 31 validates :ledger_detail_account_id, :company_id, :name, presence: true |
#ledger_detail_account_id ⇒ Object (readonly)
31 |
# File 'app/models/ledger_company_account.rb', line 31 validates :ledger_detail_account_id, :company_id, :name, presence: true |
#name ⇒ Object (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.
63 64 65 |
# File 'app/models/ledger_company_account.rb', line 63 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) ⇒ LedgerCompanyAccount?
Inverse of #identifier — parse a "<co>.<acct>" string back
into the record.
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.
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.
94 95 96 |
# File 'app/models/ledger_company_account.rb', line 94 def self.(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.
104 105 106 107 108 |
# File 'app/models/ledger_company_account.rb', line 104 def self.(company_id) return [] if company_id.nil? (company_id: company_id) end |
Instance Method Details
#bank_account ⇒ BankAccount
27 |
# File 'app/models/ledger_company_account.rb', line 27 has_one :bank_account |
#company ⇒ Company
26 |
# File 'app/models/ledger_company_account.rb', line 26 belongs_to :company, optional: true |
#company_and_account ⇒ String
"<company short name> <account name>" for display rows.
46 47 48 |
# File 'app/models/ledger_company_account.rb', line 46 def company_and_account "#{company.short_name} #{name}" end |
#identifier ⇒ String
"<company-number>.<account-number>" composite key — what
accountants type into spreadsheets to refer to a specific
company-account pair (e.g. "01.1100").
40 41 42 |
# File 'app/models/ledger_company_account.rb', line 40 def identifier "#{company.number}.#{ledger_detail_account.number}" end |
#identifier_and_name ⇒ String
{identifier} joined with #company_and_account.
52 53 54 |
# File 'app/models/ledger_company_account.rb', line 52 def identifier_and_name "#{identifier} #{company_and_account}" end |
#invoices ⇒ ActiveRecord::Relation<Invoice>
29 |
# File 'app/models/ledger_company_account.rb', line 29 has_many :invoices |
#ledger_detail_account ⇒ LedgerDetailAccount
25 |
# File 'app/models/ledger_company_account.rb', line 25 belongs_to :ledger_detail_account, optional: true |
#ledger_entries ⇒ ActiveRecord::Relation<LedgerEntry>
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?
34 |
# File 'app/models/ledger_company_account.rb', line 34 delegate :requires_business_unit?, to: :ledger_detail_account |