Class: BudgetGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- BudgetGroup
- Includes:
- Models::Auditable
- Defined in:
- app/models/budget_group.rb
Overview
== Schema Information
Table name: budget_groups
Database name: primary
id :integer not null, primary key
all_ledger_account_ids :text default([]), is an Array
all_ledger_company_account_ids_1 :text default([]), is an Array
all_ledger_company_account_ids_2 :text default([]), is an Array
all_ledger_company_account_ids_4 :text default([]), is an Array
description :string
is_revenue :boolean
ledger_account_ids :text default([]), is an Array
position :integer
show_header :boolean
show_subtotal :boolean
subtotal_description :string
created_at :datetime not null
updated_at :datetime not null
creator_id :integer
parent_id :integer
updater_id :integer
Indexes
index_budget_groups_on_parent_id (parent_id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
- #description ⇒ Object readonly
-
#skip_populate ⇒ Object
Returns the value of attribute skip_populate.
Instance Method Summary collapse
- #company_accounts_for(company) ⇒ Object
- #default_subtotal_description ⇒ Object
- #dimensions_for_company(company_id, business_unit_id, ledger_project_id) ⇒ Object
- #ledger_accounts ⇒ Object
- #own_dimension_for_company(company_id, business_unit_id, ledger_project_id) ⇒ Object
- #populate_all_cache_fields ⇒ Object
- #to_s ⇒ Object
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#description ⇒ Object (readonly)
44 |
# File 'app/models/budget_group.rb', line 44 validates :description, presence: true |
#skip_populate ⇒ Object
Returns the value of attribute skip_populate.
32 33 34 |
# File 'app/models/budget_group.rb', line 32 def skip_populate @skip_populate end |
Instance Method Details
#company_accounts_for(company) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'app/models/budget_group.rb', line 90 def company_accounts_for(company) company_accounts = [] self_and_descendants.each do |bg| bg.ledger_accounts.each do |la| company_accounts.concat(la.company_accounts_for(company)) end end return company_accounts end |
#default_subtotal_description ⇒ Object
86 87 88 |
# File 'app/models/budget_group.rb', line 86 def default_subtotal_description "Total #{description}" end |
#dimensions_for_company(company_id, business_unit_id, ledger_project_id) ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/models/budget_group.rb', line 67 def dimensions_for_company(company_id, business_unit_id, ledger_project_id) return [] if all_ledger_account_ids.nil? or all_ledger_account_ids == [] res = Analytic::BudgetDimension.where(company_id: company_id, ledger_account_ids: all_ledger_account_ids, supplier_id: nil, budget_group_id: nil) res = business_unit_id.blank? ? res.where(business_unit_id: nil) : res.where(business_unit_id: business_unit_id.to_i) res = ledger_project_id.blank? ? res.where(ledger_project_id: nil) : res.where(ledger_project_id: ledger_project_id.to_i) res end |
#ledger_accounts ⇒ Object
82 83 84 |
# File 'app/models/budget_group.rb', line 82 def ledger_accounts ledger_account_ids.nil? ? [] : LedgerAccount.where(:id => ledger_account_ids) end |
#own_dimension_for_company(company_id, business_unit_id, ledger_project_id) ⇒ Object
75 76 77 78 79 80 |
# File 'app/models/budget_group.rb', line 75 def own_dimension_for_company(company_id, business_unit_id, ledger_project_id) res = Analytic::BudgetDimension.where(company_id: company_id, supplier_id: nil, budget_group_id: self.id) res = business_unit_id.blank? ? res.where(business_unit_id: nil) : res.where(business_unit_id: business_unit_id.to_i) res = ledger_project_id.blank? ? res.where(ledger_project_id: nil) : res.where(ledger_project_id: ledger_project_id.to_i) res.first end |
#populate_all_cache_fields ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/budget_group.rb', line 52 def populate_all_cache_fields accounts = [] self_and_descendants.each {|bg| accounts.concat(bg.ledger_accounts) if bg.ledger_accounts.present?} ids = [] accounts.each {|la| la.class == LedgerSummaryAccount ? ids.concat(la.child_ids) : ids << la.id} self.all_ledger_account_ids = ids # self.ancestors_count = ancestors.count.to_i self.all_ledger_company_account_ids_1 = company_accounts_for(Company.find(Company::USA)).collect(&:id) self.all_ledger_company_account_ids_2 = company_accounts_for(Company.find(Company::CAN)).collect(&:id) self.all_ledger_company_account_ids_4 = company_accounts_for(Company.find(Company::NLD)).collect(&:id) self.skip_populate = true self.save self.parent.populate_all_cache_fields if self.parent.present? end |
#to_s ⇒ Object
48 49 50 |
# File 'app/models/budget_group.rb', line 48 def to_s "Budget Group #{description}" end |