Class: RewardAllocation
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RewardAllocation
- 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
- #charities_for_select ⇒ Object
- #charity_combo ⇒ Object
- #charity_combo=(val) ⇒ Object
-
#company_match ⇒ Object
Future proofing so that if in the future we want to increase match to certain charities we can do so.
- #total_donation ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Method Details
#charities_for_select ⇒ Object
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 |
#charity ⇒ Charity
29 |
# File 'app/models/reward_allocation.rb', line 29 belongs_to :charity, optional: true |
#charity_combo ⇒ Object
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_match ⇒ Object
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_review ⇒ EmployeeReview
28 |
# File 'app/models/reward_allocation.rb', line 28 belongs_to :employee_review, inverse_of: :reward_allocations, optional: true |
#total_donation ⇒ Object
53 54 55 |
# File 'app/models/reward_allocation.rb', line 53 def total_donation company_match + (amount || 0.0) end |