Class: LiabilityInsurance
Overview
== Schema Information
Table name: liability_insurances
Database name: primary
id :bigint not null, primary key
attachment_name :string
attachment_uid :string
expiration_date :datetime
expiration_reminder_sent :boolean default(FALSE)
expiration_reminder_sent_on :datetime
expired_alert_sent :boolean default(FALSE)
expired_alert_sent_on :datetime
state :string
valid_from_date :datetime
created_at :datetime not null
updated_at :datetime not null
customer_id :integer
Constant Summary
Models::Auditable::ALWAYS_IGNORED
Constants included
from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
config
#after_commit
#publish_event
Instance Attribute Details
#attachment ⇒ Object
34
|
# File 'app/models/liability_insurance.rb', line 34
validates :expiration_date, :valid_from_date, :attachment, presence: true
|
#expiration_date ⇒ Object
34
|
# File 'app/models/liability_insurance.rb', line 34
validates :expiration_date, :valid_from_date, :attachment, presence: true
|
#valid_from_date ⇒ Object
34
|
# File 'app/models/liability_insurance.rb', line 34
validates :expiration_date, :valid_from_date, :attachment, presence: true
|
Class Method Details
A relation of LiabilityInsurances that are active. Active Record Scope
43
|
# File 'app/models/liability_insurance.rb', line 43
scope :active, -> { where(state: 'active') }
|
.effective_now ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective now. Active Record Scope
41
|
# File 'app/models/liability_insurance.rb', line 41
scope :effective_now, -> { active.effective_on(Time.current) }
|
.effective_on ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective on. Active Record Scope
40
|
# File 'app/models/liability_insurance.rb', line 40
scope :effective_on, ->(date) { where("valid_from_date <= ? and expiration_date >= ?", date || Time.current, date || Time.current) }
|
.requested ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are requested. Active Record Scope
42
|
# File 'app/models/liability_insurance.rb', line 42
scope :requested, -> { where(state: 'processing') }
|
Instance Method Details
28
|
# File 'app/models/liability_insurance.rb', line 28
belongs_to :customer, optional: true
|
#has_valid_date_range ⇒ Object
86
87
88
89
90
91
|
# File 'app/models/liability_insurance.rb', line 86
def has_valid_date_range
return unless valid_from_date && expiration_date
errors.add(:base, "date range is invalid") if valid_from_date > expiration_date
end
|
#is_valid? ⇒ Boolean
78
79
80
|
# File 'app/models/liability_insurance.rb', line 78
def is_valid?
Date.current.between?(valid_from_date, expiration_date)
end
|
#liability_insurance_link ⇒ Object
138
139
140
|
# File 'app/models/liability_insurance.rb', line 138
def liability_insurance_link
"#{WEB_URL}/my_account/liability_insurances"
end
|
#notify_new_upload ⇒ Object
#only_one_active ⇒ Object
93
94
95
|
# File 'app/models/liability_insurance.rb', line 93
def only_one_active
errors.add(:base, "there is currently another insurance card active and valid") if state == 'active' && is_valid?
end
|
27
|
# File 'app/models/liability_insurance.rb', line 27
belongs_to :party, foreign_key: 'customer_id', optional: true
|
#period ⇒ Object
82
83
84
|
# File 'app/models/liability_insurance.rb', line 82
def period
valid_from_date..expiration_date
end
|
#possible_events ⇒ Object
97
98
99
|
# File 'app/models/liability_insurance.rb', line 97
def possible_events
state_transitions.map(&:event).sort
end
|
#possible_events_for_select ⇒ Object
101
102
103
|
# File 'app/models/liability_insurance.rb', line 101
def possible_events_for_select
possible_events.map { |evt| [evt.to_s.titleize, evt] }
end
|
#process_expired_certification ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/models/liability_insurance.rb', line 105
def process_expired_certification
return if customer.liability_insurances.active.present?
send_expired_notice
TrainingMailer.expired_liability_insurance_card(self).deliver_later
end
|
#send_expiration_coming_alert ⇒ Object
126
127
128
129
130
131
132
|
# File 'app/models/liability_insurance.rb', line 126
def send_expiration_coming_alert
CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'LIAB_INSUR_EXPIRES10').create
update(expiration_reminder_sent: true, expiration_reminder_sent_on: Time.current)
end
|
#send_expired_notice ⇒ Object
118
119
120
121
122
123
124
|
# File 'app/models/liability_insurance.rb', line 118
def send_expired_notice
CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'LIAB_INSUR_EXPIRED').create
update(expired_alert_sent: true, expired_alert_sent_on: Time.current)
end
|