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 Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
-
#company_id ⇒ Object
readonly
Validates presence of the detail account, company, and name.
-
#ledger_detail_account_id ⇒ Object
readonly
Validates presence of the detail account, company, and name.
-
#name ⇒ Object
readonly
Validates presence of the detail account, company, and name.
Belongs to collapse
-
#company ⇒ Company
Company this GL account belongs to.
-
#ledger_detail_account ⇒ LedgerDetailAccount
Detail (chart-of-accounts) account this company account rolls up to.
Methods included from Models::Auditable
Has one collapse
-
#bank_account ⇒ BankAccount
Bank account linked to this GL account.
Has many collapse
-
#invoices ⇒ ActiveRecord::Relation<Invoice>
Invoices using this account as their GL offset account.
-
#ledger_entries ⇒ ActiveRecord::Relation<LedgerEntry>
Ledger entries posted to this account.
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 Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#company_id ⇒ Object (readonly)
Validates presence of the detail account, company, and name.
Validations:
37 |
# File 'app/models/ledger_company_account.rb', line 37 validates :ledger_detail_account_id, :company_id, :name, presence: true |
#ledger_detail_account_id ⇒ Object (readonly)
Validates presence of the detail account, company, and name.
Validations:
- Presence
- Uniqueness ({ scope: :company_id, message: 'has already been created for that company' })
37 |
# File 'app/models/ledger_company_account.rb', line 37 validates :ledger_detail_account_id, :company_id, :name, presence: true |
#name ⇒ Object (readonly)
Validates presence of the detail account, company, and name.
Validations:
37 |
# File 'app/models/ledger_company_account.rb', line 37 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.
69 70 71 |
# File 'app/models/ledger_company_account.rb', line 69 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.
78 79 80 81 82 83 |
# File 'app/models/ledger_company_account.rb', line 78 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.
91 92 93 94 95 |
# File 'app/models/ledger_company_account.rb', line 91 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.
100 101 102 |
# File 'app/models/ledger_company_account.rb', line 100 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.
110 111 112 113 114 |
# File 'app/models/ledger_company_account.rb', line 110 def self.(company_id) return [] if company_id.nil? (company_id: company_id) end |
Instance Method Details
#bank_account ⇒ BankAccount
Bank account linked to this GL account.
30 |
# File 'app/models/ledger_company_account.rb', line 30 has_one :bank_account |
#company ⇒ Company
Company this GL account belongs to.
28 |
# File 'app/models/ledger_company_account.rb', line 28 belongs_to :company, optional: true |
#company_and_account ⇒ String
"<company short name> <account name>" for display rows.
52 53 54 |
# File 'app/models/ledger_company_account.rb', line 52 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").
46 47 48 |
# File 'app/models/ledger_company_account.rb', line 46 def identifier "#{company.number}.#{ledger_detail_account.number}" end |
#identifier_and_name ⇒ String
{identifier} joined with #company_and_account.
58 59 60 |
# File 'app/models/ledger_company_account.rb', line 58 def identifier_and_name "#{identifier} #{company_and_account}" end |
#invoices ⇒ ActiveRecord::Relation<Invoice>
Invoices using this account as their GL offset account.
34 |
# File 'app/models/ledger_company_account.rb', line 34 has_many :invoices |
#ledger_detail_account ⇒ LedgerDetailAccount
Detail (chart-of-accounts) account this company account rolls up to.
26 |
# File 'app/models/ledger_company_account.rb', line 26 belongs_to :ledger_detail_account, optional: true |
#ledger_entries ⇒ ActiveRecord::Relation<LedgerEntry>
Ledger entries posted to this account.
32 |
# File 'app/models/ledger_company_account.rb', line 32 has_many :ledger_entries, inverse_of: :ledger_company_account |
#requires_business_unit? ⇒ Object
Alias for Ledger_detail_account#requires_business_unit?
40 |
# File 'app/models/ledger_company_account.rb', line 40 delegate :requires_business_unit?, to: :ledger_detail_account |