Class: BudgetGroup

Inherits:
ApplicationRecord show all
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

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

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::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#descriptionString (readonly)

Returns:

  • (String)


45
# File 'app/models/budget_group.rb', line 45

validates :description, presence: true

#skip_populateObject

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) ⇒ Array<LedgerAccount>

Parameters:

Returns:



105
106
107
108
109
110
111
112
113
# File 'app/models/budget_group.rb', line 105

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
  company_accounts
end

#default_subtotal_descriptionString

Returns:

  • (String)


99
100
101
# File 'app/models/budget_group.rb', line 99

def default_subtotal_description
  "Total #{description}"
end

#dimensions_for_company(company_id, business_unit_id, ledger_project_id) ⇒ ActiveRecord::Relation<Analytic::BudgetDimension>

Parameters:

  • company_id (Integer, nil)
  • business_unit_id (Integer, nil)
  • ledger_project_id (Integer, nil)

Returns:



74
75
76
77
78
79
80
# File 'app/models/budget_group.rb', line 74

def dimensions_for_company(company_id, business_unit_id, ledger_project_id)
  return [] if .nil? || ( == [])

  res = Analytic::BudgetDimension.where(company_id: company_id, 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)
  ledger_project_id.blank? ? res.where(ledger_project_id: nil) : res.where(ledger_project_id: ledger_project_id.to_i)
end

#ledger_accountsActiveRecord::Relation<LedgerAccount>

Returns:



94
95
96
# File 'app/models/budget_group.rb', line 94

def ledger_accounts
  .nil? ? [] : LedgerAccount.where(id: )
end

#own_dimension_for_company(company_id, business_unit_id, ledger_project_id) ⇒ Analytic::BudgetDimension?

Parameters:

  • company_id (Integer, nil)
  • business_unit_id (Integer, nil)
  • ledger_project_id (Integer, nil)

Returns:



86
87
88
89
90
91
# File 'app/models/budget_group.rb', line 86

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: 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_fieldsvoid

This method returns an undefined value.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/budget_group.rb', line 55

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.instance_of?(LedgerSummaryAccount) ? ids.concat(la.child_ids) : ids << la.id }
  self. = ids
  # self.ancestors_count = ancestors.count.to_i
  self. = company_accounts_for(Company.find(Company::USA)).map(&:id)
  self. = company_accounts_for(Company.find(Company::CAN)).map(&:id)
  self. = company_accounts_for(Company.find(Company::NLD)).map(&:id)
  self.skip_populate = true
  save
  parent.presence&.populate_all_cache_fields
end

#to_sString

Returns:

  • (String)


50
51
52
# File 'app/models/budget_group.rb', line 50

def to_s
  "Budget Group #{description}"
end