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
#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
#publish_event
Class Method Details
A relation of LiabilityInsurances that are active. Active Record Scope
42
|
# File 'app/models/liability_insurance.rb', line 42
scope :active, -> { where(state: 'active') }
|
.effective_now ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective now. Active Record Scope
40
|
# File 'app/models/liability_insurance.rb', line 40
scope :effective_now, -> { active.effective_on(Time.current) }
|
.effective_on ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective on. Active Record Scope
39
|
# File 'app/models/liability_insurance.rb', line 39
scope :effective_on, ->(date) { where("valid_from_date <= ? and expiration_date >= ?", (date or Time.current), (date or Time.current)) }
|
.requested ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are requested. Active Record Scope
41
|
# File 'app/models/liability_insurance.rb', line 41
scope :requested, -> { where(state: 'processing') }
|
Instance Method Details
27
|
# File 'app/models/liability_insurance.rb', line 27
belongs_to :customer, optional: true
|
#has_valid_date_range ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'app/models/liability_insurance.rb', line 85
def has_valid_date_range
if self.valid_from_date && self.expiration_date
if self.valid_from_date > self.expiration_date
errors.add(:base, "date range is invalid")
end
end
end
|
#is_valid? ⇒ Boolean
77
78
79
|
# File 'app/models/liability_insurance.rb', line 77
def is_valid?
valid_from_date <= Date.current && expiration_date >= Date.current
end
|
#liability_insurance_link ⇒ Object
141
142
143
|
# File 'app/models/liability_insurance.rb', line 141
def liability_insurance_link
url = "#{WEB_URL}/my_account/liability_insurances"
end
|
#notify_new_upload ⇒ Object
#only_one_active ⇒ Object
94
95
96
97
98
|
# File 'app/models/liability_insurance.rb', line 94
def only_one_active
if self.state == 'active' && self.is_valid?
errors.add(:base, "there is currently another insurance card active and valid")
end
end
|
26
|
# File 'app/models/liability_insurance.rb', line 26
belongs_to :party, foreign_key: 'customer_id', optional: true
|
#period ⇒ Object
81
82
83
|
# File 'app/models/liability_insurance.rb', line 81
def period
valid_from_date..expiration_date
end
|
#possible_events ⇒ Object
100
101
102
|
# File 'app/models/liability_insurance.rb', line 100
def possible_events
state_transitions.map(&:event).sort
end
|
#possible_events_for_select ⇒ Object
104
105
106
|
# File 'app/models/liability_insurance.rb', line 104
def possible_events_for_select
possible_events.map { |evt| [evt.to_s.titleize, evt] }
end
|
#process_expired_certification ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/models/liability_insurance.rb', line 108
def process_expired_certification
unless customer.liability_insurances.active.present?
self.send_expired_notice
InternalMailer.expired_liability_insurance_card(self).deliver_later
end
end
|
#send_expiration_coming_alert ⇒ Object
129
130
131
132
133
134
135
|
# File 'app/models/liability_insurance.rb', line 129
def send_expiration_coming_alert
com = CommunicationBuilder.new(resource: self,
recipient_party: self.customer,
use_best_email: true,
template_system_code: 'LIAB_INSUR_EXPIRES10').create
self.update(expiration_reminder_sent: true, expiration_reminder_sent_on: Time.current)
end
|
#send_expired_notice ⇒ Object
121
122
123
124
125
126
127
|
# File 'app/models/liability_insurance.rb', line 121
def send_expired_notice
com = CommunicationBuilder.new(resource: self,
recipient_party: self.customer,
use_best_email: true,
template_system_code: 'LIAB_INSUR_EXPIRED').create
self.update(expired_alert_sent: true, expired_alert_sent_on: Time.current)
end
|