Class: RewardAllocation

Inherits:
ApplicationRecord show all
Defined in:
app/models/reward_allocation.rb

Overview

== Schema Information

Table name: reward_allocations
Database name: primary

id :integer not null, primary key
amount :decimal(8, 2) not null
charity_name :string not null
notes :text
created_at :datetime not null
updated_at :datetime not null
charity_id :integer
creator_id :integer
employee_review_id :integer not null
updater_id :integer

Indexes

index_reward_allocations_on_charity_id (charity_id)
index_reward_allocations_on_employee_review_id (employee_review_id)

Foreign Keys

fk_rails_... (charity_id => charities.id)
fk_rails_... (employee_review_id => employee_reviews.id) ON DELETE => cascade

Belongs to collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#charities_for_selectObject



32
33
34
# File 'app/models/reward_allocation.rb', line 32

def charities_for_select
  Charity.active.map{|c| [c.to_s, "#{c.to_s}|#{c.id}"]}
end

#charityCharity

Returns:

See Also:



29
# File 'app/models/reward_allocation.rb', line 29

belongs_to :charity, optional: true

#charity_comboObject



43
44
45
46
# File 'app/models/reward_allocation.rb', line 43

def charity_combo
  return "#{charity.to_s}|#{charity_id}" if charity
  return charity_name
end

#charity_combo=(val) ⇒ Object



36
37
38
39
40
41
# File 'app/models/reward_allocation.rb', line 36

def charity_combo=(val)
  self.charity_name,self.charity_id = val.split('|')
  if charity_id.blank? && charity_name.present?
    self.charity = Charity.create(name: self.charity_name, status: 'review')
  end
end

#company_matchObject

Future proofing so that if in the future we want to increase match to certain charities we can do so



49
50
51
# File 'app/models/reward_allocation.rb', line 49

def company_match
  amount || 0.0
end

#employee_reviewEmployeeReview



28
# File 'app/models/reward_allocation.rb', line 28

belongs_to :employee_review, inverse_of: :reward_allocations, optional: true

#total_donationObject



53
54
55
# File 'app/models/reward_allocation.rb', line 53

def total_donation
  company_match + (amount || 0.0)
end