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
Constant Summary
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #amount ⇒ Object readonly
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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#amount ⇒ Object (readonly)
31 |
# File 'app/models/reward_allocation.rb', line 31 validates :amount, :charity, presence: true |
Instance Method Details
#charities_for_select ⇒ Object
33 34 35 |
# File 'app/models/reward_allocation.rb', line 33 def charities_for_select Charity.active.map { |c| [c.to_s, "#{c}|#{c.id}"] } end |
#charity ⇒ Charity
Validations:
30 |
# File 'app/models/reward_allocation.rb', line 30 belongs_to :charity, optional: true |
#charity_combo ⇒ Object
42 43 44 45 46 |
# File 'app/models/reward_allocation.rb', line 42 def charity_combo return "#{charity}|#{charity_id}" if charity charity_name end |
#charity_combo=(val) ⇒ Object
37 38 39 40 |
# File 'app/models/reward_allocation.rb', line 37 def charity_combo=(val) self.charity_name, self.charity_id = val.split('|') self.charity = Charity.create(name: charity_name, status: 'review') if charity_id.blank? && charity_name.present? 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
29 |
# File 'app/models/reward_allocation.rb', line 29 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 |