Class: BankAccount
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- BankAccount
- Includes:
- Models::Auditable
- Defined in:
- app/models/bank_account.rb
Overview
== Schema Information
Table name: bank_accounts
Database name: primary
id :integer not null, primary key
account_number :string(255)
check_enabled :boolean
name :string(255)
created_at :datetime
updated_at :datetime
bank_id :integer
cc_company_id :integer
ledger_company_account_id :integer
paypal_company_id :integer
Indexes
bank_accounts_bank_id_idx (bank_id)
bank_accounts_ledger_company_account_id_idx (ledger_company_account_id)
idx_cc_company_id (cc_company_id)
idx_paypal_company_id (paypal_company_id)
Foreign Keys
bank_accounts_bank_id_fkey (bank_id => banks.id)
bank_accounts_ledger_company_account_id_fkey (ledger_company_account_id => ledger_company_accounts.id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
- #bank ⇒ Bank
- #cc_company ⇒ Company
- #ledger_company_account ⇒ LedgerCompanyAccount
- #paypal_company ⇒ Company
Methods included from Models::Auditable
Has many collapse
- #outgoing_payments ⇒ ActiveRecord::Relation<OutgoingPayment>
- #receipts ⇒ ActiveRecord::Relation<Receipt>
Class Method Summary collapse
-
.options_for_data_autocomplete ⇒ Array<Array>
Tuple shape used by Stimulus / autocompletes that need to filter by company or check-enabled flag client-side.
-
.options_for_select ⇒ Array<Array(String, Integer)>
[label, id]rows for the AP / outgoing-payment dropdown.
Instance Method Summary collapse
-
#get_next_check_number ⇒ String
Pull the next cheque number from the per-account Postgres sequence (
bank_account_<id>_check_numbers). -
#name_with_bank ⇒ String
"<bank name> - <account name>"label. - #to_s ⇒ String
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
Class Method Details
.options_for_data_autocomplete ⇒ Array<Array>
Tuple shape used by Stimulus / autocompletes that need to
filter by company or check-enabled flag client-side.
52 53 54 |
# File 'app/models/bank_account.rb', line 52 def self. all.joins(:bank).pluck('bank_accounts.id,banks.company_id,bank_accounts.check_enabled,banks.name,bank_accounts.name') end |
.options_for_select ⇒ Array<Array(String, Integer)>
[label, id] rows for the AP / outgoing-payment dropdown.
45 46 47 |
# File 'app/models/bank_account.rb', line 45 def self. all.joins(:bank).pluck("CONCAT(banks.name, ' - ', bank_accounts.name), bank_accounts.id".sql_safe).sort end |
Instance Method Details
#cc_company ⇒ Company
35 |
# File 'app/models/bank_account.rb', line 35 belongs_to :cc_company, :class_name => 'Company', optional: true |
#get_next_check_number ⇒ String
Pull the next cheque number from the per-account Postgres
sequence (bank_account_<id>_check_numbers). Each BankAccount
has its own monotonic numbering — this is the only safe way
to allocate a number under concurrent printing.
73 74 75 76 |
# File 'app/models/bank_account.rb', line 73 def get_next_check_number seq = BankAccount.find_by_sql("SELECT nextval('bank_account_#{self.id}_check_numbers') AS check_number") return seq[0].check_number.to_s end |
#ledger_company_account ⇒ LedgerCompanyAccount
37 |
# File 'app/models/bank_account.rb', line 37 belongs_to :ledger_company_account, optional: true |
#name_with_bank ⇒ String
"<bank name> - <account name>" label.
63 64 65 |
# File 'app/models/bank_account.rb', line 63 def name_with_bank "#{bank.name} - #{name}" end |
#outgoing_payments ⇒ ActiveRecord::Relation<OutgoingPayment>
38 |
# File 'app/models/bank_account.rb', line 38 has_many :outgoing_payments |
#paypal_company ⇒ Company
36 |
# File 'app/models/bank_account.rb', line 36 belongs_to :paypal_company, :class_name => 'Company', optional: true |
#receipts ⇒ ActiveRecord::Relation<Receipt>
39 |
# File 'app/models/bank_account.rb', line 39 has_many :receipts |
#to_s ⇒ String
57 58 59 |
# File 'app/models/bank_account.rb', line 57 def to_s "#{name_with_bank}" end |